我做了研究,但我找不到解决问题的方法,实际上我不知道我做错了什么但是enableNetwork总是返回true,甚至reconnect()方法总是返回true,这很奇怪,甚至当错误的密码通过时..你能指点我正确的方向吗?我只是想检查wifi连接的特定密码。这是正确的方法吗?
WifiConfiguration conf = new WifiConfiguration();
conf.preSharedKey = "\""+ networkPass +"\"";
WifiManager wifiManager = (WifiManager)context.getSystemService(Context.WIFI_SERVICE);
int res = wifi.addNetwork(conf);
wifiManager.disconnect();
boolean b = wifiManager.enableNetwork(res, true);
String str = String.valueOf(b);
Toast.makeText(getApplicationContext(), str, Toast.LENGTH_LONG).show();
if (wifiManager.reconnect()) {
Toast.makeText(getApplicationContext(), "Connected", Toast.LENGTH_LONG).show();
} else {
Toast.makeText(getApplicationContext(), "Not Connected", Toast.LENGTH_LONG).show();
}