ConnectivityManager cm = (ConnectivityManager)context.getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo activeNetwork = cm.getActiveNetworkInfo();
导致记录
android.net.conn.CONNECTIVITY_CHANGE
getConnectivityStatusString = TYPE_ETHERNET
activeNetwork.getTypeName()= ETHERNET
activeNetwork.isConnected()=真
activeNetwork.isConnectedOrConnecting()= true
activeNetwork.isAvailable()= true
activeNetwork.getState()= CONNECTED
我正在使用Android打印机,我正在检查以太网连接状态。 我总是获得相同的结果。当有线插件拔出时。 关于如何跟踪它的任何想法
答案 0 :(得分:1)
要检查以太网连接,请使用:
public Boolean isEthernetConnected(){
if(isNetworkAvailable()){
ConnectivityManager cm
= (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
return (cm.getActiveNetworkInfo().getType() == ConnectivityManager.TYPE_ETHERNET);
}
return false;
}
以下是isNetworkAvailable()
private Boolean isNetworkAvailable() {
ConnectivityManager connectivityManager
= (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo activeNetworkInfo = connectivityManager.getActiveNetworkInfo();
return activeNetworkInfo != null && activeNetworkInfo.isConnectedOrConnecting();
}