[Android]獲取網路連線狀態

大搜車-自娛發表於2012-11-26
ConnectivityManager cm = (ConnectivityManager) mContext.getApplicationContext().getSystemService(mContext.CONNECTIVITY_SERVICE);
NetworkInfo[] nis=cm.getAllNetworkInfo();
for(int i=0;i<nis.length;i++){
//Log.d("UpdateManagerTest", nis[i].getTypeName()+"---"+nis[i].getType());
Log.d("UpdateManagerTest", nis[i].getExtraInfo());
//cm.stopUsingNetworkFeature(nis[i].getType(), nis[i].getTypeName());
}

boolean abc=ConnectivityManager.isNetworkTypeValid(ConnectivityManager.TYPE_WIFI);
assertTrue(abc);
boolean bcd=ConnectivityManager.isNetworkTypeValid(ConnectivityManager.TYPE_MOBILE);
assertTrue(bcd);

相關文章