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();
}
On Android phones: Go to Settings. Tap Connections. Then, tap Data Usage.
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.
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.
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();
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With