Example usage for android.net ConnectivityManager getAllNetworkInfo

List of usage examples for android.net ConnectivityManager getAllNetworkInfo

Introduction

In this page you can find the example usage for android.net ConnectivityManager getAllNetworkInfo.

Prototype

@Deprecated
@RequiresPermission(android.Manifest.permission.ACCESS_NETWORK_STATE)
@NonNull
public NetworkInfo[] getAllNetworkInfo() 

Source Link

Document

Returns connection status information about all network types supported by the device.

Usage

From source file:Main.java

public static boolean isNetworkAvailable(Context context) {
    ConnectivityManager connectivity = (ConnectivityManager) context
            .getSystemService(Context.CONNECTIVITY_SERVICE);
    if (connectivity == null) {
    } else {//from ww  w  . j a  v a  2s.  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 isNetworkAvailable(Context context) {

    final 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 w  w w  .j av a2  s . com*/
            }
        }
    }

    return false;
}

From source file:Main.java

public static boolean hasNetwork(Context context) {
    ConnectivityManager connectivityManager = (ConnectivityManager) context
            .getSystemService(Context.CONNECTIVITY_SERVICE);
    if (connectivityManager == null)
        return false;
    NetworkInfo[] networkInfos = connectivityManager.getAllNetworkInfo();
    for (NetworkInfo networkInfo : networkInfos) {
        if (networkInfo != null && networkInfo.isConnected())
            return true;
    }//from ww  w  .ja v a 2 s. c o  m
    return false;
}

From source file:Main.java

public static boolean isConnToInternet(Context context) {
    ConnectivityManager connectivity = (ConnectivityManager) context
            .getSystemService(Context.CONNECTIVITY_SERVICE);
    if (connectivity != null) {
        NetworkInfo[] infoArr = connectivity.getAllNetworkInfo();
        if (isNotEmpty(infoArr)) {
            for (NetworkInfo networkInfo : infoArr) {
                if (networkInfo.getState() == NetworkInfo.State.CONNECTED) {
                    return true;
                }//  ww w  . ja va2 s . com
            }
        }
    }

    return false;
}

From source file:Main.java

public static boolean IsWiFiConnected(Context context) {
    ConnectivityManager connectivity = (ConnectivityManager) context.getApplicationContext()
            .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 ww w.  j  av  a2s. c  o  m*/
        }
    }

    return false;
}

From source file:Main.java

public static boolean isNetworkAvailable(Context context) {
    ConnectivityManager connectivity = (ConnectivityManager) context
            .getSystemService(Context.CONNECTIVITY_SERVICE);
    if (connectivity == null) {
        return false;
    } else {/*from  w w w.  java  2  s.c om*/
        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

private static boolean isAvailableByType(Context context, int type) {
    if (context != null) {
        ConnectivityManager manager = (ConnectivityManager) context.getApplicationContext()
                .getSystemService(Context.CONNECTIVITY_SERVICE);
        if (manager != null) {
            NetworkInfo[] networkInfos = manager.getAllNetworkInfo();
            for (int i = 0; i < networkInfos.length; i++) {
                if (networkInfos[i].getState() == NetworkInfo.State.CONNECTED) {
                    if (networkInfos[i].getType() == type) {
                        return true;
                    }//w w  w.  j av  a  2s  .com
                }
            }

        }
    }
    return false;
}

From source file:Main.java

public static boolean NetworkAvailable(Context context) {
    ConnectivityManager connectivity = (ConnectivityManager) context
            .getSystemService(Context.CONNECTIVITY_SERVICE);
    if (connectivity == null) {
        return false;
    } else {/*from w  w w  .  j  av  a2  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

/**
 * Get whether or not any network connection is present (eg. wifi, 3G, etc.).
 *//*from   w ww.  jav a  2  s.co  m*/
public static boolean isNetworkConnected(Context context) {
    ConnectivityManager connectivityManager = (ConnectivityManager) context
            .getSystemService(Context.CONNECTIVITY_SERVICE);
    if (connectivityManager == null)
        return false;
    NetworkInfo[] info = connectivityManager.getAllNetworkInfo();
    if (info == null)
        return false;
    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 isNetworkAvailable(Activity activity) {
    ConnectivityManager connectivity = (ConnectivityManager) activity
            .getSystemService(Context.CONNECTIVITY_SERVICE);
    if (connectivity == null) {
        return false;
    } else {/* w  ww  .  j  a  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;
}