Is there a way to check if the user is using a device (this applies primarily to tablets) with Cellular conection?. That is, the smartphones comes with built-in Wi‑Fi and Cellular (generally), but some tablets only comes with Wi-Fi. How I can know what type of device is running my application?
I tried the following without results:
cell = ConnectivityManager.isNetworkTypeValid(ConnectivityManager.TYPE_MOBILE);
wifi = ConnectivityManager.isNetworkTypeValid(ConnectivityManager.TYPE_WIFI);
if (cell) tv_1.setText("The tablet has cellular");
else tv_1.setText("The tablet does not have cellular");
if (wifi) tv_2.setText("The tablet has wifi");
else tv_2.setText("The tablet does not have wifi");
The problem is that both comparisons always return true, even if it's a tablet that has no cellular.
I only need to know if the device has a SIM card slot (model with cellular) or it is a model that only has WiFi, is that possible?
Thanks in advance.
On Android phones: Go to Settings. Tap Connections. Then, tap Data Usage.
You can quickly tell if an iPad has cellular by looking at the top back of the iPad - if there's a thick black or white band like the one below you know it has cellular (that's where all the antennae go...)
Go to the Settings menu. Tap on 'Connections' or 'Network & Internet. ' Go to the 'Mobile Networks' section.
If the goal is to determine whether the connection is metered, you should call ConnectivityManager.isActiveNetworkMetered(), or if older device support is required, ConnectivityManagerCompat.isActiveNetworkMetered().
For background on reacting to varying connection types, see the Managing Network Usage (although be aware of that documentation's problem of not using isActiveNetworkMetered()).
Here is excerpt from my code (it works so far):
ConnectivityManager connManager = (ConnectivityManager) getSystemService(CONNECTIVITY_SERVICE);
NetworkInfo mWifi = connManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
NetworkInfo mEthernet = connManager.getNetworkInfo(ConnectivityManager.TYPE_ETHERNET);
NetworkInfo m3G = connManager.getNetworkInfo(ConnectivityManager.TYPE_MOBILE);
if (mWifi!=null) isOnWifi = mWifi.isConnected();
if (mEthernet!=null) isOnEthernet = mEthernet.isConnected();
if (m3G!=null) is3G = m3G.isConnected();
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