【发布时间】:2015-04-23 00:28:23
【问题描述】:
我正在创建一个应用程序,它可以在 ListView 中列出所有可用的 wifi。如果我在列表中选择一个 wifi,它之前在 List<WifiConfiguration> list = wifiManager.getConfiguredNetworks(); 中缓存,那么它应该连接到它。如果WifiConfiguration 列表不包含选定的 wifi,则不会发生任何事情。我的问题是,有时我从列表中选择一个 wifi(我肯定知道它在 WifiConfiguration 列表中),但它没有连接到它。相反,它会连接回之前连接的 wifi。经过一些尝试(一次又一次地选择同一个 wifi)它最终连接到它。这并不总是发生,只是有时。可能是什么问题?这是我的代码 sn-p:
// Go through all the cached wifis and check if the selected GoPro was cached before
for (WifiConfiguration config : configurations) {
// If it was cached connect to it and that's all
if (config.SSID != null && config.SSID.equals("\"" + mDrawerListView.getAdapter().getItem(position) + "\"")) {
// Log
Log.i("onReceive", "Connecting to: " + config.SSID);
mWifiManager.disconnect();
mWifiManager.enableNetwork(config.networkId, true);
mWifiManager.reconnect();
break;
}
}
【问题讨论】:
标签: android android-wifi