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;
import android.util.Log;

public class Main {
    public static boolean isNetworkAvailable(Context context) {
        ConnectivityManager connectivity = (ConnectivityManager) context
                .getSystemService(Context.CONNECTIVITY_SERVICE);
        if (connectivity == null) {
            Log.i("NetWorkState", "Unavailabel");
            return false;
        } else {/*  w w  w. ja  v  a 2  s.co  m*/
            NetworkInfo[] info = connectivity.getAllNetworkInfo();
            if (info != null) {
                for (int i = 0; i < info.length; i++) {
                    if (info[i].getState() == NetworkInfo.State.CONNECTED) {
                        Log.i("NetWorkState", "Availabel");
                        return true;
                    }
                }
            }
        }
        return false;
    }
}

Related

  1. isMobileConnected(Context context)
  2. isNetworkAvailable(Context context)
  3. isNetworkConnected(Context context)
  4. isMobileConnected(Context context)
  5. isNetworkConnected(Context context)
  6. isNetworkConnected(Context context)
  7. onNetwork(Context context)
  8. haveNetworkConnection(Context context)
  9. isNetworkConnected(Context context)