List of utility methods to do Network State Check
boolean | checkNetState(Context context) check Net State 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) { ... |
int | checkNetWorkStatus(Context context) check Net Work Status int status = 0;
ConnectivityManager connMgr = (ConnectivityManager) context
.getApplicationContext().getSystemService(
Context.CONNECTIVITY_SERVICE);
android.net.NetworkInfo wifi = connMgr
.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
android.net.NetworkInfo mobile = connMgr
.getNetworkInfo(ConnectivityManager.TYPE_MOBILE);
...
|
boolean | checkNetworkState(Context context) check Network State 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) { ... |
boolean | getMobileState(Context context) get Mobile State ConnectivityManager cm = (ConnectivityManager) context .getSystemService(Context.CONNECTIVITY_SERVICE); State wifistate = cm.getNetworkInfo(ConnectivityManager.TYPE_WIFI) .getState(); if (wifistate != State.CONNECTED) { return false; State mobileState = cm.getNetworkInfo( ... |
boolean | hasConnectivity(Application application) has Connectivity ConnectivityManager cm = (ConnectivityManager) application .getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo wifiNetwork = cm .getNetworkInfo(ConnectivityManager.TYPE_WIFI); if (wifiNetwork != null && wifiNetwork.isConnected()) { return true; NetworkInfo mobileNetwork = cm ... |
boolean | hasConnectivity(final Context context, final int... networkTypes) has Connectivity final ConnectivityManager connectivity = (ConnectivityManager) context .getSystemService(Context.CONNECTIVITY_SERVICE); if (networkTypes.length > 0) for (final int networkType : networkTypes) if (ConnectivityManager.isNetworkTypeValid(networkType)) return hasConnectivity(connectivity .getNetworkInfo(networkType)); return hasConnectivity(connectivity.getActiveNetworkInfo()); ... |
boolean | hasConnectivity(final NetworkInfo info) has Connectivity return null != info && info.isAvailable() && info.isConnected();
|
boolean | hasInternetAvailable(Context context) has Internet Available ConnectivityManager cm = (ConnectivityManager) context .getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo netInfo = cm.getActiveNetworkInfo(); if (netInfo != null && netInfo.isConnected()) { return true; return false; |
boolean | hasMobileConnectivity(Context context) has Mobile Connectivity ConnectivityManager cm = (ConnectivityManager) context .getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo mobileInfo = cm .getNetworkInfo(ConnectivityManager.TYPE_MOBILE); if (mobileInfo != null) { return true; } else { return false; ... |
boolean | hasNoConnectivity(Application application) has No Connectivity return !hasConnectivity(application);
|