Code example for NetworkInfo

Methods: getState

0
     * @return boolean true if online 
     */ 
    public static boolean isDeviceOnline(Context context) {
        ConnectivityManager cMgr = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
        NetworkInfo netInfo = cMgr.getActiveNetworkInfo();
        if (netInfo == null || netInfo.getState() == null)
            return false; 
        return netInfo.getState().equals(State.CONNECTED);
    } 
     
} 
Contextual code suggestions in your IDE  Get Codota for Java