connection - Problem: Android's isConnected() used to get current state of WiFi often returns false even when the device is connected -
my android app can function wifi connected internet. thus, use following code check if device connected:
connectivitymanager conmgr = (connectivitymanager)getsystemservice(activity.connectivity_service); boolean wifi = conmgr.getnetworkinfo(connectivitymanager.type_wifi).isconnected();
however, when application launched , wifi connected internet, notification shown when wifi = false
. have missed something, or check not accurate?
i use code this:
public static string getcurrentssid(context context) { final wifiinfo wifiinfo = getcurrentwifiinfo(context); if (wifiinfo != null && !stringutil.isblank(wifiinfo.getssid())) { return wifiinfo.getssid(); } return null; } public static wifiinfo getcurrentwifiinfo(context context) { final connectivitymanager connmanager = (connectivitymanager) context.getsystemservice(context.connectivity_service); final networkinfo networkinfo = connmanager.getnetworkinfo(connectivitymanager.type_wifi); if (networkinfo != null && networkinfo.isconnected()) { final wifimanager wifimanager = (wifimanager) context.getsystemservice(context.wifi_service); return wifimanager.getconnectioninfo(); } return null; }
Comments
Post a Comment