Android检查手机网络状态及网络类型的方法
本文实例讲述了Android检查手机网络状态及网络类型的方法。分享给大家供大家参考。具体分析如下:
//judgenetworkstatusisconnectingornot publicstaticbooleancheckNetworkConnected(Contextcontext){ if(null!=context){ ConnectivityManagerconnectivityManager=(ConnectivityManager)context .getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfonetworkInfo=connectivityManager.getActiveNetworkInfo(); if(null!=networkInfo){ returnnetworkInfo.isAvailable(); } } returnfalse; } //judgeWifistatusisconnectingornot publicstaticbooleancheckWifiStatus(Contextcontext){ ConnectivityManagerconnectivityManager=(ConnectivityManager)context .getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfonetworkInfo=connectivityManager.getActiveNetworkInfo(); if(null!=networkInfo &&networkInfo.getType()==ConnectivityManager.TYPE_WIFI){ returntrue; } returnfalse; } //judge3Gstatusisconnectingornot publicstaticbooleancheck3GStatus(Contextcontext){ ConnectivityManagerconnectivityManager=(ConnectivityManager)context .getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfonetworkInfo=connectivityManager.getActiveNetworkInfo(); if(null!=networkInfo &&networkInfo.getType()==ConnectivityManager.TYPE_MOBILE){ returntrue; } returnfalse; }
希望本文所述对大家的Android程序设计有所帮助。