Loading app/src/main/java/foundation/e/drive/utils/CommonUtils.java +8 −8 Original line number Diff line number Diff line Loading @@ -17,6 +17,7 @@ import android.content.ContentResolver; import android.content.Context; import android.media.MediaScannerConnection; import android.net.ConnectivityManager; import android.net.Network; import android.net.NetworkInfo; import android.net.Uri; import android.util.Log; Loading Loading @@ -195,14 +196,13 @@ public abstract class CommonUtils { boolean haveConnectedMobile = false; ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo[] netInfo = cm.getAllNetworkInfo(); for (NetworkInfo ni : netInfo) { if (ni.getType()== ConnectivityManager.TYPE_WIFI) // Replaced the ni.getTypeName by ni.getType to make the test from ObserverServiceTest to work. But looks a better solution in all case if (ni.isConnected()) haveConnectedWifi = true; if (ni.getType()== ConnectivityManager.TYPE_MOBILE) if (ni.isConnected()) haveConnectedMobile = true; Network[] networks = cm.getAllNetworks(); for (Network network : networks) { NetworkInfo networkInfo = cm.getNetworkInfo(network); if (networkInfo.getType()== ConnectivityManager.TYPE_WIFI) haveConnectedWifi |= networkInfo.isConnected(); if (networkInfo.getType()== ConnectivityManager.TYPE_MOBILE) haveConnectedMobile |= networkInfo.isConnected(); } return haveConnectedWifi || haveConnectedMobile; } Loading Loading
app/src/main/java/foundation/e/drive/utils/CommonUtils.java +8 −8 Original line number Diff line number Diff line Loading @@ -17,6 +17,7 @@ import android.content.ContentResolver; import android.content.Context; import android.media.MediaScannerConnection; import android.net.ConnectivityManager; import android.net.Network; import android.net.NetworkInfo; import android.net.Uri; import android.util.Log; Loading Loading @@ -195,14 +196,13 @@ public abstract class CommonUtils { boolean haveConnectedMobile = false; ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo[] netInfo = cm.getAllNetworkInfo(); for (NetworkInfo ni : netInfo) { if (ni.getType()== ConnectivityManager.TYPE_WIFI) // Replaced the ni.getTypeName by ni.getType to make the test from ObserverServiceTest to work. But looks a better solution in all case if (ni.isConnected()) haveConnectedWifi = true; if (ni.getType()== ConnectivityManager.TYPE_MOBILE) if (ni.isConnected()) haveConnectedMobile = true; Network[] networks = cm.getAllNetworks(); for (Network network : networks) { NetworkInfo networkInfo = cm.getNetworkInfo(network); if (networkInfo.getType()== ConnectivityManager.TYPE_WIFI) haveConnectedWifi |= networkInfo.isConnected(); if (networkInfo.getType()== ConnectivityManager.TYPE_MOBILE) haveConnectedMobile |= networkInfo.isConnected(); } return haveConnectedWifi || haveConnectedMobile; } Loading