导航:首页 > 操作系统 > android自动连接指定wifi

android自动连接指定wifi

发布时间:2024-05-21 00:00:51

❶ 安卓手机怎么一键连接到指定WIFI网络

三星手机的部分ROM非常奇葩,不能保存WIFI密码,每次连接WIFI都得重新输入密码。2.X的版本如此,5.X的版本也是如此。必须修改系统文件才能自动连接指定的WIFI。解决这个问题的方法如下:

一、root手机:虽然现在很多软件自称可以一键root手机,但有的无法root,有的root不完全,有的root后不稳定。最正规的root方法,是卡刷SuperSU_Pro_v2.46。

二、下载安装Root Explorer。

三、打开Root Explorer,进入data/misc/wifi/文件夹,找到wpa_supplicant.conf 文件。

.

android wifi 是怎么实现打开wifi后自动连接的

设置静态IP既可先连接好wifi然后点击它在hdcp那里点击静态确定既可

❸ Android WiFi开发,如何自动连接的代码

public class WifiAutoConnectManager {
private static final String TAG = WifiAutoConnectManager.class.getSimpleName();
WifiManager wifiManager;
// 定义几种加密方式,一种是WEP,一种是WPA,还有没有密码的情况 public enum WifiCipherType { WIFICIPHER_WEP, WIFICIPHER_WPA, WIFICIPHER_NOPASS, WIFICIPHER_INVALID }
// 构造函数 public WifiAutoConnectManager(WifiManager wifiManager) { this.wifiManager = wifiManager; }
// 提供一个外部接口,传入要连接的无线网 public void connect(String ssid, String password, WifiCipherType type) { Thread thread = new Thread(new ConnectRunnable(ssid, password, type)); thread.start(); }
// 查看以前是否也配置过这个网络 private WifiConfiguration isExsits(String SSID) { List<WifiConfiguration> existingConfigs = wifiManager.getConfiguredNetworks(); for (WifiConfiguration existingConfig : existingConfigs) { if (existingConfig.SSID.equals("\"" + SSID + "\"")) { return existingConfig; } } return null; }
private WifiConfiguration createWifiInfo(String SSID, String Password, WifiCipherType Type) { WifiConfiguration config = new WifiConfiguration(); config.allowedAuthAlgorithms.clear(); config.allowedGroupCiphers.clear(); config.allowedKeyManagement.clear(); config.allowedPairwiseCiphers.clear(); config.allowedProtocols.clear(); config.SSID = "\"" + SSID + "\""; // nopass if (Type == WifiCipherType.WIFICIPHER_NOPASS) { config.wepKeys[0] = ""; config.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.NONE); config.wepTxKeyIndex = 0; } // wep if (Type == WifiCipherType.WIFICIPHER_WEP) { if (!TextUtils.isEmpty(Password)) { if (isHexWepKey(Password)) { config.wepKeys[0] = Password; } else { config.wepKeys[0] = "\"" + Password + "\""; } } config.allowedAuthAlgorithms.set(AuthAlgorithm.OPEN); config.allowedAuthAlgorithms.set(AuthAlgorithm.SHARED); config.allowedKeyManagement.set(KeyMgmt.NONE); config.wepTxKeyIndex = 0; } // wpa if (Type == WifiCipherType.WIFICIPHER_WPA) { 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.allowedProtocols.set(WifiConfiguration.Protocol.WPA); config.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.CCMP); config.allowedPairwiseCiphers.set(WifiConfiguration.PairwiseCipher.CCMP); config.status = WifiConfiguration.Status.ENABLED; } return config; }
// 打开wifi功能 private boolean openWifi() { boolean bRet = true; if (!wifiManager.isWifiEnabled()) { bRet = wifiManager.setWifiEnabled(true); } return bRet; }
class ConnectRunnable implements Runnable { private String ssid;
private String password;
private WifiCipherType type;
public ConnectRunnable(String ssid, String password, WifiCipherType type) { this.ssid = ssid; this.password = password; this.type = type; }
@Override public void run() { // 打开wifi openWifi(); // 开启wifi功能需要一段时间(我在手机上测试一般需要1-3秒左右),所以要等到wifi // 状态变成WIFI_STATE_ENABLED的时候才能执行下面的语句 while (wifiManager.getWifiState() == WifiManager.WIFI_STATE_ENABLING) { try { // 为了避免程序一直while循环,让它睡个100毫秒检测…… Thread.sleep(100); } catch (InterruptedException ie) { } }
WifiConfiguration wifiConfig = createWifiInfo(ssid, password, type); // if (wifiConfig == null) { Log.d(TAG, "wifiConfig is null!"); return; }
WifiConfiguration tempConfig = isExsits(ssid);
if (tempConfig != null) { wifiManager.removeNetwork(tempConfig.networkId); }
int netID = wifiManager.addNetwork(wifiConfig); boolean enabled = wifiManager.enableNetwork(netID, true); Log.d(TAG, "enableNetwork status enable=" + enabled); boolean connected = wifiManager.reconnect(); Log.d(TAG, "enableNetwork connected=" + connected); } }
private static boolean isHexWepKey(String wepKey) { final int len = wepKey.length();
// WEP-40, WEP-104, and some vendors using 256-bit WEP (WEP-232?) if (len != 10 && len != 26 && len != 58) { return false; }
return isHex(wepKey); }
private static boolean isHex(String key) { for (int i = key.length() - 1; i >= 0; i--) { final char c = key.charAt(i); if (!(c >= '0' && c <= '9' || c >= 'A' && c <= 'F' || c >= 'a' && c <= 'f')) { return false; } }
return true; }}

阅读全文

与android自动连接指定wifi相关的资料

热点内容
苹果安卓换机用什么软件好 浏览:261
华为通话加密电话 浏览:58
什么服务器可以代替计算机 浏览:960
服务器当电脑用怎么安装显卡 浏览:519
回女友消息神器python 浏览:50
App分类框怎么添加 浏览:543
海尔帅王子冰箱压缩机启动跳闸 浏览:479
cadfill命令什么意思 浏览:334
中公专项题库pdf 浏览:931
拼多多缓存在哪个文件夹 浏览:640
安卓无卡汽车导航怎么升级 浏览:48
cs管理员命令是什么 浏览:126
华为v10模拟加密门禁卡 浏览:725
android修改app名称 浏览:640
辐射3伙伴命令 浏览:247
苹果电脑pdf转换成word 浏览:921
纯小数运算法则 浏览:385
php什么是事务 浏览:859
怎么添加网名文件夹 浏览:770
啊哈算法语言 浏览:677