Code example for NetworkInfo.State

Methods: equals

0
        ConnectivityManager manager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
        NetworkInfo info = manager.getActiveNetworkInfo();
        if (info == null) {
            Log.d(TAG, "no network found");
            return false; 
        } else if (info.getState().equals(State.CONNECTED)) {
            Log.d(TAG, "network state = CONNECTED");
            return true; 
        } else { 
            Log.d(TAG, "network state != CONNECTED, " + info.getState().toString());
            return false; 
        } 
    } 
}