How to check is the device connected to internet or not in Android



With this simple snippet, we can check is the device is connected to internet or not:

private boolean isConnected(){
        ConnectivityManager connectivityManager = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
        NetworkInfo activeNetworkInfo = connectivityManager.getActiveNetworkInfo();
        return activeNetworkInfo != null && activeNetworkInfo.isConnected();
    }

So this “isConnected()” returns true if it’s connected, otherwise it returns false.

loading...

Leave a Reply

Your email address will not be published. Required fields are marked *