how to check internet connection in android

Solutions on MaxInterview for how to check internet connection in android by the best coders in the world

showing results for - "how to check internet connection in android"
Angela
02 Jan 2020
1public static boolean isNetworkConnected(Context context) {
2        ConnectivityManager cm = (ConnectivityManager) context
3                .getSystemService(Context.CONNECTIVITY_SERVICE);
4        NetworkInfo ni = cm.getActiveNetworkInfo();
5        if (ni == null) {
6            // There are no active networks.
7            return false;
8        } else {
9            return true;
10        }
11
12    }