我想测试Android中的wifi连接。我的程序总是返回CONNECTED,无论我使用什么密码或者是什么类型的网络。 下面的代码有什么问题。
String checkConnection(ScanResult sr,String password)
{
String sreturn="NOT CONNECTED";
WifiConfiguration wifiConfig = new WifiConfiguration();
wifiConfig.SSID = String.format("\"%s\"", sr.SSID);
wifiConfig.preSharedKey = String.format("\"%s\"", password);
WifiManager wifiManager = (WifiManager)getSystemService(WIFI_SERVICE);
if (wifiManager.addNetwork(wifiConfig) != -1)
{
if (wifiManager.enableNetwork(netId, true)) {
sreturn = "CONNECTED";
wifiManager.disableNetwork(netId);
}
wifiManager.removeNetwork(netId);
}
return sreturn;
}
*
答案 0 :(得分:0)
String checkConnection(ScanResult sr,String password) { String sreturn =" NOT CONNECTED";
{{1}}