附上代碼說(shuō)明如何在Android中判斷網(wǎng)絡(luò )功能是否可用:
* 判斷網(wǎng)絡(luò )功能是否可用
* 需要權限< uses-permission android:name="android.permission.ACCESS_NETWORK_STATE">
* @param ctx
* @return
*/
public static boolean isNetworkAvailable(Context ctx){
ConnectivityManager cm = (ConnectivityManager)ctx.getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo info = cm.getActiveNetworkInfo();
return (info != null && info.isConnected());
}