Code example for NetworkInfo.State

Methods: equals

0
    public static boolean isAvailable(Context context) {
        // Check any network information such as 3G, 2G, Wifi, Nonetwork 
        NetworkInfo netInfo = (NetworkInfo) ((ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE)).getActiveNetworkInfo();
 
        Log.d(TAG, "State : "+ ((netInfo!=null)?netInfo.getState():""));
        if ((netInfo == null) || (!State.CONNECTED.equals(netInfo.getState()) ))
            return false; 
        else 
            return true; 
    } 
} 
Experience pair programming with AI  Get Codota for Java