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

2019-10-10  本文已影响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;

}

```

上一篇下一篇

猜你喜欢

热点阅读