Merge pull request #4365 from osmandapp/dead_system_exception

Fix #4332
This commit is contained in:
Alexey 2017-08-30 16:39:53 +03:00 committed by GitHub
commit 16a1599bf3

View file

@ -256,19 +256,27 @@ public class OsmandSettings {
} }
public boolean isWifiConnected() { public boolean isWifiConnected() {
ConnectivityManager mgr = (ConnectivityManager) ctx.getSystemService(Context.CONNECTIVITY_SERVICE); try {
NetworkInfo ni = mgr.getActiveNetworkInfo(); ConnectivityManager mgr = (ConnectivityManager) ctx.getSystemService(Context.CONNECTIVITY_SERVICE);
return ni != null && ni.getType() == ConnectivityManager.TYPE_WIFI; NetworkInfo ni = mgr.getActiveNetworkInfo();
return ni != null && ni.getType() == ConnectivityManager.TYPE_WIFI;
} catch (Exception e) {
return false;
}
} }
private boolean isInternetConnected() { private boolean isInternetConnected() {
ConnectivityManager mgr = (ConnectivityManager) ctx.getSystemService(Context.CONNECTIVITY_SERVICE); try {
NetworkInfo active = mgr.getActiveNetworkInfo(); ConnectivityManager mgr = (ConnectivityManager) ctx.getSystemService(Context.CONNECTIVITY_SERVICE);
if (active == null) { NetworkInfo active = mgr.getActiveNetworkInfo();
if (active == null) {
return false;
} else {
NetworkInfo.State state = active.getState();
return state != NetworkInfo.State.DISCONNECTED && state != NetworkInfo.State.DISCONNECTING;
}
} catch (Exception e) {
return false; return false;
} else {
NetworkInfo.State state = active.getState();
return state != NetworkInfo.State.DISCONNECTED && state != NetworkInfo.State.DISCONNECTING;
} }
} }