WifiManager.getConfiguredNetworks always returns empty list

故事扮演 提交于 2019-12-02 07:21:41
Youngpan

You can not continue the

CMD wifiManager.getConfiguredNetworks()

until the status of WiFi is enabled completely. For enabling the WiFi it need some time. So you need to delay some time.

Try to comment these lines in your code.. do you see any change in result set?

wifiManager.setWifiEnabled(true);   
wifiManager.addNetwork(conf);

You might want to check the return for wifiManager.addNetwork(conf);, is it returning -1.

For me this lines return 31 objects only.. no idea why..still hunting for it.

WifiManager wifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
List<WifiConfiguration> arraylist = wifiManager.getConfiguredNetworks();
Log.wtf("WifiPreference","No of Networks"+arraylist.size());

I also met this question unfortunely.

After searching for some time, I think it is a bug.

This is the android implement of getConfiguredNetworks

public List<WifiConfiguration> getConfiguredNetworks() {
    try {
        return mService.getConfiguredNetworks();
    } catch (RemoteException e) {
        return null;
    }
}

It is clearly shown that the function will return null if RemoteException happened when running. Up to now, I am also distressed with this and could not get some points to address this issue.

For more information: https://code.google.com/p/android/issues/detail?id=19078

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!