Check connection using ConnectivityManager

suggest change

Declare ACCESS_NETWORK_STATE. This reports whether a network is connected or connecting. It does not prove that a remote host answered.

public static boolean isConnectedNetwork(Context context) {
    ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
    if (cm == null) {
        return false;
    }
    NetworkInfo info = cm.getActiveNetworkInfo();
    return info != null && info.isConnectedOrConnecting();
}

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents