I made a simple application that shows the network type currently on the device. I have Nexus 7 inch tablet and the value shown is Unknown. I know that Nexus 7 is not a GSM device i.e it doesn't need a SIM card to operate. But I get internet from a wifi router which means there must be a network type.
Why it is giving me value of Unknown?
I checked my code well so it cannot be a bug as on emulated Nexus 7 gives UTMS type. I used this page as a reference.
TelephonyManager
is used to check cellular connectivity only. Your device is not using any (since it does not have SIM card), thus unknown return value.
If you want to check for WiFi connection:
ConnectivityManager connManager = (ConnectivityManager) getSystemService(CONNECTIVITY_SERVICE);
NetworkInfo info = connManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
if (info != null && info.isConnected()) {
// device is using WiFi connection
}
Or, just give up with TelephonyManager and use ConnectionManager exclusively:
NetworkInfo info = connManager.getActiveNetworkInfo();
if (info != null && info.isConnected()) {
// device is using some connection
}
above code will check for any type of connectivity, be it WiFi or cellular.