1000字范文,内容丰富有趣,学习的好帮手!
1000字范文 > android 如何自动连接wifi密码错误 在android中连接到wifi网络 如果密码不正确则返回...

android 如何自动连接wifi密码错误 在android中连接到wifi网络 如果密码不正确则返回...

时间:2022-07-29 16:32:08

相关推荐

android 如何自动连接wifi密码错误 在android中连接到wifi网络 如果密码不正确则返回...

我想创建一个允许用户连接到wifi网络的应用程序,但是我无法连接到网络

我目前的代码是:

WifiManager wifi = (WifiManager) getSystemService(WIFI_SERVICE);

wifi.setWifiEnabled(true);

WifiConfiguration wc = new WifiConfiguration();

wifi.startScan();

List l=wifi.getScanResults();

wc.SSID = l.get(NUMBER).SSID;

post(wc.SSID);

/*This is the bit that I think is failing, my network does not have these properties.. but I can't see how to get them from the Scan Result*/

wc.preSharedKey = "\"passw0rd123\"";

wc.hiddenSSID = false;

wc.status = WifiConfiguration.Status.ENABLED;

wc.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.TKIP);

wc.allowedGroupCiphers.set(MP);

wc.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.WPA_PSK);

wc.allowedPairwiseCiphers.set(WifiConfiguration.PairwiseCipher.TKIP);

wc.allowedPairwiseCiphers.set(MP);

wc.allowedProtocols.set(WifiConfiguration.Protocol.RSN);

int res = wifi.addNetwork(wc);

post("add Network returned " + res);

boolean b = wifi.enableNetwork(res, true);

post("enableNetwork returned " + b);

我认为这与设置(在我的评论之后)有关,这与我的网络配置不同,但我不知道如何从ScanResult获取这些设置.

编辑:

我还想知道它是否已正确连接.

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。