Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Check whether mobile is using WIFI or Data/3G

Tags:

android

Assuming that both WIFI and Data/3G are enabled on a device, how do I check if the user is currently using the internet over the wifi or the data plan assuming they are both enabled. So I don't need to check if they are enabled or disabled, I would like to detect which one is the user actually using.

I've been doing the following, is this the only solution?

WifiManager wifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
WifiInfo wifiInfo = wifiManager.getConnectionInfo();
if (WifiInfo.getDetailedStateOf(wifiInfo.getSupplicantState()) == NetworkInfo.DetailedState.CONNECTED) {
    String ssid = wifiInfo.getSSID();
}
like image 446
ARMAGEDDON Avatar asked Jun 17 '13 13:06

ARMAGEDDON


People also ask

How can I tell if my phone is using data or wi fi?

On Android phones: Go to Settings. Tap Connections. Then, tap Data Usage.

How do I know if my Android is using WIFI or data?

You can tell from the screen if the phone is using Wifi or LTE. On the top of your screen, if you see the fan symbol, that means that the phone is using Wifi. Similarly, when it's using LTE or 3G (in case you have that), that means that it's using the cellular network instead.

How do I know if my phone is 3G or 5G?

Another easier way to tell if your smartphone supports 5G or not is to check in the phone settings. Assuming it's an Android phone, tap on Settings >> Network & internet >> Mobile Network >> Preferred Network type. You should see all the Mobile Network technologies supported such as 2G, 3G, 4G and 5G.


1 Answers

void chkStatus() {
    final ConnectivityManager connMgr = (ConnectivityManager)
    this.getSystemService(Context.CONNECTIVITY_SERVICE);
    final android.net.NetworkInfo wifi = connMgr.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
    final android.net.NetworkInfo mobile = connMgr.getNetworkInfo(ConnectivityManager.TYPE_MOBILE);
    if (wifi.isConnectedOrConnecting ()) {
        Toast.makeText(this, "Wifi", Toast.LENGTH_LONG).show();
    } else if (mobile.isConnectedOrConnecting ()) {
        Toast.makeText(this, "Mobile 3G ", Toast.LENGTH_LONG).show();
    } else {
        Toast.makeText(this, "No Network ", Toast.LENGTH_LONG).show();
    }
}
like image 196
Aashish Bhatnagar Avatar answered Oct 21 '22 08:10

Aashish Bhatnagar