VladMorzhanov
9/23/2017 - 3:00 PM

Android check is device connected to network.

Android check is device connected to network.

public static boolean checkNetworkAvailability(Context context) {
        ConnectivityManager connMgr = (ConnectivityManager)
                context.getSystemService(Context.CONNECTIVITY_SERVICE);
        NetworkInfo networkInfo = null;
        if (connMgr != null) {
            networkInfo = connMgr.getActiveNetworkInfo();
        }

        return networkInfo != null && networkInfo.isConnected();
    }