List of usage examples for android.net ConnectivityManager getAllNetworkInfo
@Deprecated
@RequiresPermission(android.Manifest.permission.ACCESS_NETWORK_STATE)
@NonNull
public NetworkInfo[] getAllNetworkInfo()
From source file:Main.java
public static boolean isNetConnected(Context context) { ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); if (cm != null) { NetworkInfo[] infos = cm.getAllNetworkInfo(); if (infos != null) { for (NetworkInfo ni : infos) { if (ni.isConnected()) { return true; }/* w w w. j a v a 2s .com*/ } } } return false; }
From source file:Main.java
/** * @param context/* ww w . j a va2s . co m*/ * @return boolean * @throws * @Title: currentNetworkIsWifi * @Description: TODO */ public static boolean currentNetworkIsWifi(Context context) { if (checkPermission(context, "android.permission.ACCESS_WIFI_STATE")) ; Context contextApplication = context.getApplicationContext(); ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); if (cm != null) { NetworkInfo[] info = cm.getAllNetworkInfo(); if (info != null) { for (int i = 0; i < info.length; i++) { if (info[i].getTypeName().equals("WIFI") && info[i].isConnected()) return true; } } } return false; }
From source file:Main.java
public static boolean isConnectingToInternet(Context context) { ConnectivityManager connectivity = (ConnectivityManager) context .getSystemService(context.CONNECTIVITY_SERVICE); if (connectivity != null) { NetworkInfo[] info = connectivity.getAllNetworkInfo(); if (info != null) for (int i = 0; i < info.length; i++) if (info[i].getState() == NetworkInfo.State.CONNECTED) { return true; }//from www . jav a 2 s . com } return false; }
From source file:Main.java
public static boolean isConnectedToInternet(Context context) { ConnectivityManager connectivity = (ConnectivityManager) context .getSystemService(Context.CONNECTIVITY_SERVICE); if (connectivity != null) { NetworkInfo[] info = connectivity.getAllNetworkInfo(); if (info != null) for (int i = 0; i < info.length; i++) if (info[i].getState() == NetworkInfo.State.CONNECTED) { return true; }// ww w .j a v a 2 s . c om } return false; }
From source file:Main.java
public static boolean isNetWorkEnable(Context cxt) { ConnectivityManager connectivity = (ConnectivityManager) cxt.getSystemService(Context.CONNECTIVITY_SERVICE); if (connectivity == null) { } else {/*from w ww. ja v a 2 s. c o m*/ NetworkInfo[] info = connectivity.getAllNetworkInfo(); if (info != null) { for (int i = 0; i < info.length; i++) { if (info[i].getState() == NetworkInfo.State.CONNECTED) { return true; } } } } return false; }
From source file:Main.java
public static boolean isConnectingToInternet(Context _context) { ConnectivityManager connectivity = (ConnectivityManager) _context .getSystemService(Context.CONNECTIVITY_SERVICE); if (connectivity != null) { NetworkInfo[] info = connectivity.getAllNetworkInfo(); if (info != null) for (int i = 0; i < info.length; i++) if (info[i].getState() == NetworkInfo.State.CONNECTED) { return true; }/*w ww . j a v a 2 s.co m*/ } return false; }
From source file:Main.java
public static boolean isWiFiActive(Context context) { ConnectivityManager connectivity = (ConnectivityManager) context .getSystemService(Context.CONNECTIVITY_SERVICE); if (connectivity != null) { NetworkInfo[] info = connectivity.getAllNetworkInfo(); if (info != null) { for (int i = 0; i < info.length; i++) { if (info[i].getTypeName().equals("WIFI") && info[i].isConnected()) { return true; }/*from w w w . j a v a 2s . c o m*/ } } } return false; }
From source file:Main.java
/** * Checks if a internet connection is available. Note that the device can be connected * to a network but not have internet access * * Requires <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> * in the manifest/* ww w . j a v a 2 s. c o m*/ * * @param appContext * @return */ public static boolean isNetworkAvailable(Context appContext) { /** ConnectivityManager cm = (ConnectivityManager) appContext.getSystemService(Context.CONNECTIVITY_SERVICE); return cm.getActiveNetworkInfo() != null && cm.getActiveNetworkInfo().isConnectedOrConnecting(); */ boolean outcome = false; if (appContext != null) { ConnectivityManager cm = (ConnectivityManager) appContext .getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo[] networkInfos = cm.getAllNetworkInfo(); for (NetworkInfo tempNetworkInfo : networkInfos) { // Can also check if the user is in roaming if (tempNetworkInfo.isConnected()) { outcome = true; break; } } } return outcome; }
From source file:Main.java
public static boolean checkNetworkState(Context context) { boolean netstate = false; ConnectivityManager connectivity = (ConnectivityManager) context .getSystemService(Context.CONNECTIVITY_SERVICE); if (connectivity != null) { NetworkInfo[] info = connectivity.getAllNetworkInfo(); if (info != null) { for (int i = 0; i < info.length; i++) { if (info[i].getState() == NetworkInfo.State.CONNECTED) { netstate = true;//from w w w . ja va2 s . c om break; } } } } return netstate; }
From source file:Main.java
public static boolean isWifiAvailable(final Context context) { if (context != null) { final ConnectivityManager connManager = (ConnectivityManager) context .getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo[] connections = connManager.getAllNetworkInfo(); for (NetworkInfo netInfo : connections) { if (netInfo != null) { boolean connected = netInfo.isConnected(); int connectType = netInfo.getType(); if (connected) if (connectType == ConnectivityManager.TYPE_WIFI || connectType == ConnectivityManager.TYPE_ETHERNET) return true; }//from w w w .j av a 2 s.co m } } return false; }