From dbf069cf85a97e1bf2693b0b84b230b29e573254 Mon Sep 17 00:00:00 2001 From: Albert Vaca Date: Tue, 28 Feb 2017 21:21:31 +0100 Subject: [PATCH] Further refining the network detection --- src/org/kde/kdeconnect/Helpers/NetworkHelper.java | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/org/kde/kdeconnect/Helpers/NetworkHelper.java b/src/org/kde/kdeconnect/Helpers/NetworkHelper.java index 75f05b91..f6d37425 100644 --- a/src/org/kde/kdeconnect/Helpers/NetworkHelper.java +++ b/src/org/kde/kdeconnect/Helpers/NetworkHelper.java @@ -4,6 +4,7 @@ import android.content.Context; import android.net.ConnectivityManager; import android.net.Network; import android.net.NetworkInfo; +import android.util.Log; public class NetworkHelper { @@ -11,16 +12,19 @@ public class NetworkHelper { if (context == null || android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.LOLLIPOP) { return false; //No good way to know it } + boolean mobile = false; final ConnectivityManager connMgr = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); Network[] networks = connMgr.getAllNetworks(); for (Network network : networks) { NetworkInfo info = connMgr.getNetworkInfo(network); if (info.getType() == ConnectivityManager.TYPE_MOBILE) { + mobile = info.isConnected(); continue; } - if (info.isConnected()) return false; //We are connected to at least one non-mobile network + Log.e(info.getTypeName(),""+info.isAvailable()); + if (info.isAvailable()) return false; //We are connected to at least one non-mobile network } - return true; + return mobile; } }