Home android How to find out if mobile internet is turned on if wifi...

How to find out if mobile internet is turned on if wifi is on (with internet)?




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 .

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.

Programmers, Start Your Engines!

Why spend time searching for the correct question and then entering your answer when you can find it in a second? That's what CompuTicket is all about! Here you'll find thousands of questions and answers from hundreds of computer languages.

Recent questions