這是殺了我,任何幫助將不勝感激。Android的wifimanager總是返回true
我想連接到使用wifi管理器的開放網絡。我遇到的問題是代碼聲稱連接到任何網絡 - 甚至不存在的網絡。下面是整個代碼被執行並被網絡的SSID調用。即使沒有任何形狀或形式的網絡存在,您傳遞給網絡的SSID也不重要,enableNetwork聲明返回true,我相信這意味着它連接到網絡。
我需要做的是確保我有連接。所以如果我傳遞一個不存在的網絡SSID(例如,它超出範圍),API嘗試連接時應該返回失敗。
任何想法/提示/建議將不勝感激。
public boolean conto (String network){
WifiConfiguration wifiConfiguration = new WifiConfiguration();
wifi = (WifiManager) getSystemService(Context.WIFI_SERVICE);
List<WifiConfiguration> configs = null;
int inetId = -1;
// make sure there are no funny stuff in the config
configs = wifi.getConfiguredNetworks();
for (WifiConfiguration config : configs) {
wifi.removeNetwork(config.networkId);
Log.d("********", "Removed Network: SSID=[" + config.SSID + "] and ID=[" + config.networkId + "]");
}
// Now add the network
wifiConfiguration.SSID = "\"" + network + "\"";
wifiConfiguration.hiddenSSID = false;
//wifiConfiguration.priority = 1;
//wifiConfiguration.networkId = 999;
inetId = wifi.addNetwork(wifiConfiguration);
if(inetId < 0) {
Log.d("********", "Could Not Add Network......... [" + wifiConfiguration.SSID + "]");
}
else {
Log.d("********", "Added Network......... [" + wifiConfiguration.SSID + "]");
// Lets be paranoid and double check the config file
Log.d("********", " +++++++++++++++++++++++++ This is what I have in Config File");
configs = wifi.getConfiguredNetworks();
for (WifiConfiguration config : configs) {
Log.d("********", "In the Config file after add, SSID=[" + config.SSID + "], ID=[" + config.networkId + "]");
}
// Now Enable the network
boolean successConnected = wifi.enableNetwork(inetId, true);
//boolean successAssociated = wifi.reassociate(); This did not change the results
if(successConnected) {
Log.d("********", "Connected to......... [" + inetId + "]");
}
else {
Log.d("********", "Could Not Connect to......... [" + inetId + "]");
}
}
return false;
}
你有沒有解決這個問題?我有[同樣的問題](http://stackoverflow.com/questions/11378452/android-wifimanager-making-a-phantom-connection)。 – gcl1 2012-07-08 00:03:43