1
I have the following problem, I have a method that checks whether the device is connected to the internet or not
public static boolean isNetworkAvailable(Context context) {
ConnectivityManager cm = (ConnectivityManager)context.getSystemService(Context.CONNECTIVITY_SERVICE);
assert cm != null;
NetworkInfo activeNetwork = cm.getActiveNetworkInfo();
boolean isConnected = activeNetwork != null && activeNetwork.isConnectedOrConnecting() && activeNetwork.getState() == NetworkInfo.State.CONNECTED;
return isConnected;
}
Only, when I am connected to a wifi, where it has no internet, it returns true. That is, the method returns true if there is a connection and not specifically with the internet. Someone has already been there?
I had seen this solution, only it does not work for older devices, but even for my reality works very well.
– lucas_marciano