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.