在Android中,如何判斷網絡是否連接或WIFI已連接呢,很簡單,可以用如下的方法判斷
- public static boolean checkNetworkConnection(Context context)
- {
- final ConnectivityManager connMgr = (ConnectivityManager)context.getSystemService(Context.CONNECTIVITY_SERVICE);
-
- final android.net.NetworkInfo wifi =connMgr.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
- final android.net.NetworkInfo mobile =connMgr.getNetworkInfo(ConnectivityManager.TYPE_MOBILE);
-
- if(wifi.isAvailable()||mobile.isAvailable())
- return true;
- else
- return false;
- }