Android Utililty Methods Network State Check

List of utility methods to do Network State Check

Description

The list of methods to do Network State Check are organized into topic(s).

Method

booleanisConnectingToInternet(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;
...
booleanisConnectionFast(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; 
...
booleanisNetworkAvailable()
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;
booleanisNetworkConnected(Context context)
is Network Connected
ConnectivityManager cm = (ConnectivityManager) context
        .getSystemService(Context.CONNECTIVITY_SERVICE);
return (cm.getActiveNetworkInfo() != null)
        && cm.getActiveNetworkInfo().isConnectedOrConnecting();
booleanisOnline(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())
...
booleanisOnline(Context context)
is Online
ConnectivityManager cm = (ConnectivityManager) context
        .getSystemService(Context.CONNECTIVITY_SERVICE);
return ((cm.getActiveNetworkInfo() != null) && cm
        .getActiveNetworkInfo().isConnectedOrConnecting());
booleanisNetworkReady(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;
...
booleanisConMeNetwork(String ssid)
is Con Me Network
if (ssid.startsWith(NETWORK_BRANDING) && ssid.length() == 15)
    return true;
return false;
booleanisConnectNetWork(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);
...
booleanisOnline(Context context)
is Online
try {
    ConnectivityManager cm = (ConnectivityManager) context
            .getSystemService(Context.CONNECTIVITY_SERVICE);
    return cm.getActiveNetworkInfo().isConnected();
} catch (Exception e) {
    return false;