導航:首頁 > 操作系統 > 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相關的資料

熱點內容
怎麼添加網名文件夾 瀏覽:767
啊哈演算法語言 瀏覽:675
馬來西亞加密貨幣政策 瀏覽:231
交通銀行app鎖定怎麼解鎖 瀏覽:44
php登錄驗證session 瀏覽:728
粵政易文件放在手機哪個文件夾 瀏覽:105
列印機和傳真命令 瀏覽:548
php添加購物車 瀏覽:5
安卓怎麼下載植物大戰僵屍1無盡版 瀏覽:267
程序員上班下班難嗎 瀏覽:299
夢的pdf微盤 瀏覽:186
材料結構分析pdf 瀏覽:795
程序員預研的項目 瀏覽:346
新華保險伺服器登錄不上怎麼回事 瀏覽:397
氣溫高時汽車空調壓縮機振動 瀏覽:563
分配器python 瀏覽:228
outlook伺服器怎麼查詢 瀏覽:400
python預測疫情代碼 瀏覽:982
普通化學原理pdf 瀏覽:908
java的聖經 瀏覽:41