我正在尝试创建一个应用程序,一旦连接,就会在过去使用的每个可用网络上运行特定方法。在运行方法并连接到下一个可用网络之前,我尝试确保wifi已完全连接,但这部分代码似乎无法正常工作。
任何建议都将不胜感激!
List<WifiConfiguration> networkList = wifiManager.getConfiguredNetworks();
List<ScanResult> scannedList = wifiManager.getScanResults();
for (ScanResult i: scannedList){
for (WifiConfiguration z: networkList){
if(z.SSID.substring(1, (z.SSID.length() - 1)).equals(i.SSID)){
//System.out.println("NETWORK: " + i.SSID);
System.out.println("NETWORK: " + i.SSID + "STATE " + wifiManager.getConnectionInfo().getSupplicantState().toString());
wifiManager.disconnect();
wifiManager.enableNetwork(z.networkId, true);
wifiManager.reconnect();
while(wifiManager.getConnectionInfo().getSupplicantState().toString() != "COMPLETED"){
}
runMethod(wifiManager);
}
}
}
}