Commit dbf069cf authored by Albert Vaca Cintora's avatar Albert Vaca Cintora

Further refining the network detection

parent bf230509
...@@ -4,6 +4,7 @@ import android.content.Context; ...@@ -4,6 +4,7 @@ import android.content.Context;
import android.net.ConnectivityManager; import android.net.ConnectivityManager;
import android.net.Network; import android.net.Network;
import android.net.NetworkInfo; import android.net.NetworkInfo;
import android.util.Log;
public class NetworkHelper { public class NetworkHelper {
...@@ -11,16 +12,19 @@ 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) { if (context == null || android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.LOLLIPOP) {
return false; //No good way to know it return false; //No good way to know it
} }
boolean mobile = false;
final ConnectivityManager connMgr = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); final ConnectivityManager connMgr = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
Network[] networks = connMgr.getAllNetworks(); Network[] networks = connMgr.getAllNetworks();
for (Network network : networks) { for (Network network : networks) {
NetworkInfo info = connMgr.getNetworkInfo(network); NetworkInfo info = connMgr.getNetworkInfo(network);
if (info.getType() == ConnectivityManager.TYPE_MOBILE) { if (info.getType() == ConnectivityManager.TYPE_MOBILE) {
mobile = info.isConnected();
continue; 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;
} }
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment