qq_20258523
2017-09-22 01:31android wifi连接记住密码并自动连接
想让链接过一次的WIFI再次点击之后不需要输入密码直接连接,需要用到哪些方法呢?
下面的是连接的代码,哪里需要改动?
public WifiConfiguration CreateWifiInfo(String SSID, String Password, int Type) {//
WifiConfiguration config = new WifiConfiguration();
config.allowedAuthAlgorithms.clear();
config.allowedGroupCiphers.clear();
config.allowedKeyManagement.clear();
config.allowedPairwiseCiphers.clear();
config.allowedProtocols.clear();
config.SSID = "\"" + SSID + "\"";
//config.SSID = SSID;
config.hiddenSSID = false;
WifiConfiguration tempConfig = isExsits(SSID);
if (tempConfig != null) {
Log.e("connectgid.", "exixtandClear : " + tempConfig.networkId);
wifiManager.removeNetwork(tempConfig.networkId);
}
Log.e("connectgid.", SSID + " " + Password);
if (Type == SECURITY_NONE) {
config.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.NONE);
}
if (Type == SECURITY_WEP) {
config.hiddenSSID = true;
config.wepKeys[0] = "\"" + Password + "\"";
config.allowedAuthAlgorithms
.set(WifiConfiguration.AuthAlgorithm.SHARED);
config.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.CCMP);
config.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.TKIP);
config.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.WEP40);
config.allowedGroupCiphers
.set(WifiConfiguration.GroupCipher.WEP104);
config.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.NONE);
config.wepTxKeyIndex = 0;
}
if (Type == SECURITY_PSK) {
config.preSharedKey = "\"" + Password + "\"";
config.hiddenSSID = true;
config.allowedAuthAlgorithms.set(WifiConfiguration.AuthAlgorithm.OPEN);
config.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.TKIP);
config.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.WPA_PSK);
config.allowedPairwiseCiphers.set(WifiConfiguration.PairwiseCipher.TKIP);
config.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.CCMP);
config.allowedPairwiseCiphers.set(WifiConfiguration.PairwiseCipher.CCMP);
config.status = WifiConfiguration.Status.ENABLED;
config.allowedKeyManagement.set(KeyMgmt.WPA_PSK);
if (Password.length() != 0) {
if (Password.matches("[0-9A-Fa-f]{8,}")) {
Log.e("CreateWifiInfo", "password:" + Password);
config.preSharedKey = Password;
} else {
config.preSharedKey = '"' + Password + '"';
}
}
}
if (Type == SECURITY_EAP) {
config.allowedKeyManagement.set(KeyMgmt.WPA_EAP);
config.allowedKeyManagement.set(KeyMgmt.IEEE8021X);
}
return config;
}
- 点赞
- 回答
- 收藏
- 复制链接分享
2条回答
为你推荐
- Android 9.0 开机自动连接指定WIFI
- android
- 4个回答
- Androidstudio连接postgresql数据库
- 特别紧急帮帮忙
- 3个回答
- android 自定义wifi设置
- wifi
- 1个回答
- Android 自动更新覆盖安装失败
- 自动更新
- android
- apk
- 7个回答
- Android开发,wifi连接如何知道连接失败是因为密码错误导致
- 3个回答