Android Network State Check isNetworkAvailable(Context context)

Here you can find the source of isNetworkAvailable(Context context)

Description

is Network Available

Declaration

public static boolean isNetworkAvailable(Context context) 

Method Source Code

//package com.java2s;

import android.content.Context;

import android.net.ConnectivityManager;
import android.net.NetworkInfo;

public class Main {

    public static boolean isNetworkAvailable(Context context) {
        try {/*from  w w w  .  ja  v a2  s .co  m*/
            ConnectivityManager connectivity = (ConnectivityManager) context
                    .getSystemService(Context.CONNECTIVITY_SERVICE);
            if (connectivity != null) {
                NetworkInfo info = connectivity.getActiveNetworkInfo();
                if (info != null && info.isConnected()) {
                    if (info.getState() == NetworkInfo.State.CONNECTED) {
                        return true;
                    }
                }
            }
        } catch (Exception e) {
            return false;
        }
        return false;
    }
}

Related

  1. isHightBandwidthConnection(Context context)
  2. isConnectionFast(int type, int subType)
  3. isNetAvailable(Context context)
  4. isNetworkAvailable(Context context)
  5. isNetworkAvailable(Context context)
  6. isNetworkAvailable(Context paramContext)
  7. isNetworkAvailable(Context context)
  8. isNetworkRoaming(Context context)
  9. isMobileDataEnable(Context context)