To check if your device is internet connected or not use:
private boolean isNetworkAvailable() {
ConnectivityManager connectivityManager
= (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo activeNetworkInfo = connectivityManager.getActiveNetworkInfo();
return activeNetworkInfo != null && activeNetworkInfo.isConnectedOrConnecting();
}
Use a permission in your Manifest.xml:
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
And then use the method like:
if (!isNetworkAvailable) {
} else {
}