ConnectivityManager do not work on Motorola xoom (honeycomb 3.2)
-
20-04-2021 - |
Вопрос
I have a method call isNetworkAvailable()
to check if the user have enable wap/wifi/wimax this works for Android 2.1 to 2.3+.
But now a user of the app which uses honeycomb 3.2 on a Motorola xoom rapport to me that he can´t open the app.
In my android developer web-interface I can see this log-error: http://paste.ubuntu.com/811881/
private boolean isNetworkAvailable()
{
ConnectivityManager connec = (ConnectivityManager)getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo mobileInfo = connec.getNetworkInfo(0);
NetworkInfo wifiInfo = connec.getNetworkInfo(1);
NetworkInfo wimaxInfo = connec.getNetworkInfo(6);
if (wimaxInfo!=null) {
return mobileInfo.isConnected() || wifiInfo.isConnected()|| wimaxInfo.isConnected();
}
else {
return mobileInfo.isConnected() || wifiInfo.isConnected();
}
}
See the whole Class/Activity here(line 276):
Решение
mobileInfo or wifiInfo could be null. On a wifi-only device I wouldn't be surprised if mobileInfo (ConnectivityManager.TYPE_MOBILE) is null.
Другие советы
I have faced same problem with Motorola Xoom, because it does not have connectivity support for ConnectivityManager.TYPE_MOBILE
.
The following code is working fine for me:
ConnectivityManager connMngr = (ConnectivityManager)context.getSystemService(Context.CONNECTIVITY_SERVICE);
try {
return connMngr.getActiveNetworkInfo().isConnected();
} catch (NullPointerException npe) {
return false;
}
Не связан с StackOverflow