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) {
        ConnectivityManager conMgr = (ConnectivityManager) context
                .getSystemService(Context.CONNECTIVITY_SERVICE);

        boolean availability = false;
        try {//from  ww  w.j a va  2  s . c  om
            if (conMgr.getNetworkInfo(ConnectivityManager.TYPE_MOBILE)
                    .getState() == NetworkInfo.State.CONNECTED
                    || conMgr.getNetworkInfo(ConnectivityManager.TYPE_WIFI)
                            .getState() == NetworkInfo.State.CONNECTED) {
                availability = true;
            }
        } catch (Exception e) {
            return true;
        }
        return availability;
    }
}

Related

  1. isOnline(Context context)
  2. isNetworkReady(Context context)
  3. isConMeNetwork(String ssid)
  4. isConnectNetWork(final Context context)
  5. isOnline(Context context)
  6. isNetworkAvailable(Context context)
  7. isMobileOnline(Context context)
  8. isInternetReachable(Context context)
  9. isHightBandwidthConnection(Context context)