Android Context Check isNetAvailable(Context context)

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

Description

is Net Available

Declaration

public static Boolean isNetAvailable(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 isNetAvailable(Context context) {
        try {/*from   www  .j a v a 2 s . com*/
            ConnectivityManager connectivityManager = (ConnectivityManager) context
                    .getSystemService(Context.CONNECTIVITY_SERVICE);
            NetworkInfo wifiInfo = connectivityManager
                    .getNetworkInfo(ConnectivityManager.TYPE_WIFI);
            NetworkInfo mobileInfo = connectivityManager
                    .getNetworkInfo(ConnectivityManager.TYPE_MOBILE);
            if (wifiInfo.isConnected() || mobileInfo.isConnected()) {
                return true;
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return false;
    }
}

Related

  1. isLandscape(Context context)
  2. isLandscape(final Context context)
  3. isLocationEnabledGPS(Context c)
  4. isMobile(Context context)
  5. isMobilityInstalled(Context context)
  6. isOnline(Context c)
  7. isOnline(Context context)
  8. isOnline(Context context)
  9. isOnline(Context context)