I want to check connection state in my android app. I call the next method in onResume
:
public boolean isThereInternetConnection() {
boolean isConnected = false;
ConnectivityManager connectivityManager =
(ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo networkInfo = (connectivityManager != null) ? connectivityManager.getActiveNetworkInfo() : null;
if (networkInfo != null) {
isConnected = networkInfo.isConnected();
}
return isConnected;
}
In normal mode it works well. But when my device is on battery saver mode and I open my activity from background, method isThereInternetConnection()
returns false sometimes (internet connection was well). For this I checked networkInfo.getDetailedState()
and in battery saver mode it returns DetailedState.BLOCKED
even I have good internet connection. So how to resolve this bug, how to check internet connection in battery saver mode and obtain real value true or false - connected to internet or not?