Thursday 15 March 2012

android - connMgr.getActiveNetworkInfo() return null while wifi is on -



android - connMgr.getActiveNetworkInfo() return null while wifi is on -

this code:

connectivitymanager connmgr = (connectivitymanager) getsystemservice(activity.connectivity_service); networkinfo networkinfo = connmgr.getactivenetworkinfo();

but networkinfo null..

what can cause odd thing?

docs getactivenetworkinfo can homecoming null if there no default network set. "this may homecoming null when there no default network." http://developer.android.com/reference/android/net/connectivitymanager.html#getactivenetworkinfo()

a improve alternative might check cell info or wifi connection.

check mobile connection.

connectivitymanager connectivitymanager = (connectivitymanager) context.getsystemservice(context.connectivity_service); networkinfo mobnetinfo = connectivitymanage.getnetworkinfo(connectivitymanager.type_mobile);

check wifi connection.

connectivitymanager connectivitymanager = (connectivitymanager) context.getsystemservice(context.connectivity_service); networkinfo wifinetinfo = connectivitymanager.getnetworkinfo(connectivitymanager.type_wifi);

android null android-wifi

No comments:

Post a Comment