From 3e86975ecfe8f03c538dc1ab63f726b268c2b27c Mon Sep 17 00:00:00 2001 From: PavelRatushny Date: Wed, 30 Aug 2017 14:51:28 +0300 Subject: [PATCH] Fix #4332 --- .../src/net/osmand/plus/OsmandSettings.java | 26 ++++++++++++------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/OsmandSettings.java b/OsmAnd/src/net/osmand/plus/OsmandSettings.java index e79fc369e2..8dcec70c60 100644 --- a/OsmAnd/src/net/osmand/plus/OsmandSettings.java +++ b/OsmAnd/src/net/osmand/plus/OsmandSettings.java @@ -256,19 +256,27 @@ public class OsmandSettings { } public boolean isWifiConnected() { - ConnectivityManager mgr = (ConnectivityManager) ctx.getSystemService(Context.CONNECTIVITY_SERVICE); - NetworkInfo ni = mgr.getActiveNetworkInfo(); - return ni != null && ni.getType() == ConnectivityManager.TYPE_WIFI; + try { + ConnectivityManager mgr = (ConnectivityManager) ctx.getSystemService(Context.CONNECTIVITY_SERVICE); + NetworkInfo ni = mgr.getActiveNetworkInfo(); + return ni != null && ni.getType() == ConnectivityManager.TYPE_WIFI; + } catch (Exception e) { + return false; + } } private boolean isInternetConnected() { - ConnectivityManager mgr = (ConnectivityManager) ctx.getSystemService(Context.CONNECTIVITY_SERVICE); - NetworkInfo active = mgr.getActiveNetworkInfo(); - if (active == null) { + try { + ConnectivityManager mgr = (ConnectivityManager) ctx.getSystemService(Context.CONNECTIVITY_SERVICE); + 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; - } else { - NetworkInfo.State state = active.getState(); - return state != NetworkInfo.State.DISCONNECTED && state != NetworkInfo.State.DISCONNECTING; } }