[Android]获取网络连接状态

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);



你可能感兴趣的:(android,NetWork)