I am struggling with this question: How do I know that the mobile Internet is turned on if wifi is also turned on and has the Internet? And is it possible at all to do this without turning off wifi or without a situation when wifi will not have the Internet?
Answer 1
To check the status of the connection, use NetworkInfo
.
Example:
private static final String DEBUG_TAG = "NetworkStatusExample";
...
ConnectivityManager connMgr = (ConnectivityManager)
getSystemService (Context.CONNECTIVITY_SERVICE);
NetworkInfo networkInfo = connMgr.getNetworkInfo (ConnectivityManager.TYPE_WIFI);
boolean isWifiConn = networkInfo.isConnected ();
networkInfo = connMgr.getNetworkInfo (ConnectivityManager.TYPE_MOBILE);
boolean isMobileConn = networkInfo.isConnected ();
Log.d (DEBUG_TAG, "Wifi connected:" + isWifiConn);
Log.d (DEBUG_TAG, "Mobile connected:" + isMobileConn);
Just write your boolean condition =)
See also documentation for help.
Answer 2
Apparently the answer is no way. Since it is possible only to check which Internet you are connected to (or are connecting) to mobile or wifi.