1
0
Fork 0
mirror of https://github.com/M66B/NetGuard.git synced 2024-12-22 07:43:15 +00:00

Workaround Android returning wrong is connected state

This commit is contained in:
M66B 2020-06-07 12:20:12 +02:00
parent 0525a14eda
commit d0f19242bb

View file

@ -165,8 +165,24 @@ public class Util {
public static boolean isConnected(Context context) {
ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo ni = (cm == null ? null : cm.getActiveNetworkInfo());
return (ni != null && ni.isConnected());
if (cm == null)
return false;
NetworkInfo ni = cm.getActiveNetworkInfo();
if (ni != null && ni.isConnected())
return true;
Network[] networks = cm.getAllNetworks();
if (networks == null)
return false;
for (Network network : networks) {
ni = cm.getNetworkInfo(network);
if (ni != null && ni.getType() != ConnectivityManager.TYPE_VPN && ni.isConnected())
return true;
}
return false;
}
public static boolean isWifiActive(Context context) {