android 发射器的 IPTV 盒子编程
android IPTV box programming for launcher
我正在 android 中编写一个 iptv setup box launcher,我正在尝试找出以太网连接信息(即用户是否通过以太网电缆连接),请帮助...
如果问题不清楚,我深表歉意。
请帮帮我,我非常需要它,最近三天卡住了。
您可以通过 ConnectivityManager
检查您是通过以太网还是 Wifi 连接:
ConnectivityManager connManager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo wifi = connManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
NetworkInfo ethernet = connManager.getNetworkInfo(ConnectivityManager.TYPE_ETHERNET);
// get the ethernet state with : ethernet.getState()
// get the Wifi state with : wifi.getState()
您需要在清单中添加:
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
您可以通过 BroadcastReceiver
注册连接事件,检查 this example
或者您可以使用适合您的 this library
private Boolean isNetworkAvailable() {
ConnectivityManager connectivityManager
= (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo activeNetworkInfo = connectivityManager.getActiveNetworkInfo();
return activeNetworkInfo != null && activeNetworkInfo.isConnectedOrConnecting();
}
public Boolean isWifiConnected(){
if(isNetworkAvailable()){
ConnectivityManager cm
= (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
return (cm.getActiveNetworkInfo().getType() == ConnectivityManager.TYPE_WIFI);
}
return false;
}
public Boolean isEthernetConnected(){
if(isNetworkAvailable()){
ConnectivityManager cm
= (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
return (cm.getActiveNetworkInfo().getType() == ConnectivityManager.TYPE_ETHERNET);
}
return false;
}
然后:
if(isEthernetConnected()){
// connected
}
else {
//not connected
}
我正在 android 中编写一个 iptv setup box launcher,我正在尝试找出以太网连接信息(即用户是否通过以太网电缆连接),请帮助... 如果问题不清楚,我深表歉意。 请帮帮我,我非常需要它,最近三天卡住了。
您可以通过 ConnectivityManager
检查您是通过以太网还是 Wifi 连接:
ConnectivityManager connManager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo wifi = connManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
NetworkInfo ethernet = connManager.getNetworkInfo(ConnectivityManager.TYPE_ETHERNET);
// get the ethernet state with : ethernet.getState()
// get the Wifi state with : wifi.getState()
您需要在清单中添加:
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
您可以通过 BroadcastReceiver
注册连接事件,检查 this example
或者您可以使用适合您的 this library
private Boolean isNetworkAvailable() {
ConnectivityManager connectivityManager
= (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo activeNetworkInfo = connectivityManager.getActiveNetworkInfo();
return activeNetworkInfo != null && activeNetworkInfo.isConnectedOrConnecting();
}
public Boolean isWifiConnected(){
if(isNetworkAvailable()){
ConnectivityManager cm
= (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
return (cm.getActiveNetworkInfo().getType() == ConnectivityManager.TYPE_WIFI);
}
return false;
}
public Boolean isEthernetConnected(){
if(isNetworkAvailable()){
ConnectivityManager cm
= (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
return (cm.getActiveNetworkInfo().getType() == ConnectivityManager.TYPE_ETHERNET);
}
return false;
}
然后:
if(isEthernetConnected()){
// connected
}
else {
//not connected
}