androidandroid-5.1.1-lollipop

How to check if both Mobile Data and WIFI are connected?


I have this code:

ConnectivityManager connMgr = (ConnectivityManager)
  context.getSystemService(Context.CONNECTIVITY_SERVICE);

NetworkInfo networkInfoWifi =
  connMgr.getNetworkInfo(ConnectivityManager.TYPE_WIFI);

NetworkInfo networkInfoMobileData =
  connMgr.getNetworkInfo(ConnectivityManager.TYPE_MOBILE);

And then in my Android network settings, both Mobile Data and WiFi are enabled. The following checks are

networkInfoWifi.isConnected();       // results to TRUE
networkInfoMobileData.isConnected(); // results to FALSE

My app runs on Android Lollipop. I expect that both checks above should return TRUE. Why is this happening? I need them to be both TRUE. What should I do?


Solution

  • I never found a way to make the networkInfoWifi.isConnected() and networkInfoMobileData.isConnected() to return both TRUE. This is probably because Android can only be connected to only one interface at a time.

    This interface selection is also done by Android automatically starting Lollipop devices. Android Lollipop defaults to Mobile Data when Wi-Fi has not Internet access?