List of utility methods to do Network State Check
boolean | isConnectingToInternet(Context context) is Connecting To Internet 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; ... |
boolean | isConnectionFast(int type, int subType) Check if the connection is fast if (type == ConnectivityManager.TYPE_WIFI) { return true; } else if (type == ConnectivityManager.TYPE_MOBILE) { switch (subType) { case TelephonyManager.NETWORK_TYPE_1xRTT: return false; case TelephonyManager.NETWORK_TYPE_CDMA: return false; ... |
boolean | isNetworkAvailable() Uses Android connectivity service to give information about the availability of the network on the phone. if (context != null) { ConnectivityManager connMgr = (ConnectivityManager) context .getSystemService(Context.CONNECTIVITY_SERVICE); return connMgr.getNetworkInfo(ConnectivityManager.TYPE_WIFI) .isConnected() || connMgr.getNetworkInfo( ConnectivityManager.TYPE_MOBILE).isConnected(); return false; |
boolean | isNetworkConnected(Context context) is Network Connected ConnectivityManager cm = (ConnectivityManager) context
.getSystemService(Context.CONNECTIVITY_SERVICE);
return (cm.getActiveNetworkInfo() != null)
&& cm.getActiveNetworkInfo().isConnectedOrConnecting();
|
boolean | isOnline(Context c) is Online boolean haveConnectedWifi = false; boolean haveConnectedMobile = false; ConnectivityManager cm = (ConnectivityManager) c .getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo[] netInfo = cm.getAllNetworkInfo(); for (NetworkInfo ni : netInfo) { if (ni.getTypeName().equalsIgnoreCase("WIFI")) if (ni.isConnected()) ... |
boolean | isOnline(Context context) is Online ConnectivityManager cm = (ConnectivityManager) context
.getSystemService(Context.CONNECTIVITY_SERVICE);
return ((cm.getActiveNetworkInfo() != null) && cm
.getActiveNetworkInfo().isConnectedOrConnecting());
|
boolean | isNetworkReady(Context context) Check the network interface (system-level) connectivity ATTENTION: permissions must be set in manifest.xml boolean status = false; try { ConnectivityManager cm = (ConnectivityManager) context .getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo netInfo = cm.getNetworkInfo(0); if (netInfo != null && netInfo.getState() == NetworkInfo.State.CONNECTED) { status = true; ... |
boolean | isConMeNetwork(String ssid) is Con Me Network if (ssid.startsWith(NETWORK_BRANDING) && ssid.length() == 15) return true; return false; |
boolean | isConnectNetWork(final Context context) Detect whether network is available or not boolean result = false; ConnectivityManager cm = (ConnectivityManager) context .getSystemService(Context.CONNECTIVITY_SERVICE); boolean isWifiConnected = cm.getNetworkInfo( ConnectivityManager.TYPE_WIFI).getState() == NetworkInfo.State.CONNECTED ? true : false; NetworkInfo mobileState = cm .getNetworkInfo(ConnectivityManager.TYPE_MOBILE); ... |
boolean | isOnline(Context context) is Online try { ConnectivityManager cm = (ConnectivityManager) context .getSystemService(Context.CONNECTIVITY_SERVICE); return cm.getActiveNetworkInfo().isConnected(); } catch (Exception e) { return false; |