Voidcode Voidcode - 20 days ago 8
Android Question

ConnectivityManager do not work on Motorola xoom (honeycomb 3.2)

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):



https://github.com/voidcode/Diaspora-Webclient/blob/master/src/com/voidcode/diasporawebclient/MainActivity.java

Answer

mobileInfo or wifiInfo could be null. On a wifi-only device I wouldn't be surprised if mobileInfo (ConnectivityManager.TYPE_MOBILE) is null.

Comments