美文网首页
Android connect wifi 连接热点 稳稳稳,像快

Android connect wifi 连接热点 稳稳稳,像快

作者: 龙镇 | 来源:发表于2019-10-10 16:00 被阅读0次

```

if (config ==null) {

addNetWork =true;

config =new WifiConfiguration();

config.allowedAuthAlgorithms.clear();

config.allowedGroupCiphers.clear();

config.allowedKeyManagement.clear();

config.allowedPairwiseCiphers.clear();

config.allowedProtocols.clear();

config.SSID ="\"" + wifiName +"\"";

config.preSharedKey ="\"" + password +"\"";

config.hiddenSSID =false;

config.status = WifiConfiguration.Status.ENABLED;

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

config.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.CCMP);

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

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

config.allowedPairwiseCiphers.set(WifiConfiguration.PairwiseCipher.CCMP);

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

config.allowedProtocols.set(WifiConfiguration.Protocol.WPA);

config.allowedAuthAlgorithms.set(WifiConfiguration.AuthAlgorithm.OPEN);

config.priority =1000000;

}

int networkId;

if (addNetWork) {

//不在wifi列表中,添加到wifi列表,得到网络id

    networkId =wifiManager.addNetwork(config);

}else {

//直接从配置中取出id

    networkId =config.networkId;

}

```

相关文章

网友评论

      本文标题:Android connect wifi 连接热点 稳稳稳,像快

      本文链接:https://www.haomeiwen.com/subject/eubnectx.html