Android自動連接WiFi優先順序規則,以及查看已串連WiFi的密碼

來源:互聯網
上載者:User

標籤:android   wifi   串連優先順序   查看密碼   

目前Android的WiFi自動連接的優先順序規則如下:

1、priority值的範圍設定為[0,1000000),如果超出此範圍則會reset;

2、最近串連過的AP擁有最高priority,在自動連接中會首先嘗試串連它;
3、未串連過但是掃描到的AP,按其訊號值強弱排序,越強的顯示靠前,但是,還得綜合
AP的安全因素,基本情況是:WPA/WPA2 > WEP > signal level high > signal level low > noise low > noise
high

4、如果是預置的AP,可能會人為設定其最高的priority;

看一下源碼,代碼路徑:frameworks/base/wifi/java/android/net/wifi/


WifiConfigStore.java

 boolean selectNetwork(int netId) {        if (VDBG) localLog("selectNetwork", netId);        if (netId == INVALID_NETWORK_ID) return false;        // Reset the priority of each network at start or if it goes too high.        if (mLastPriority == -1 || mLastPriority > 1000000) {            Xlog.d(TAG, "Need to reset the priority, mLastPriority:" + mLastPriority);            for(WifiConfiguration config : mConfiguredNetworks.values()) {                if (config.networkId != INVALID_NETWORK_ID) {                    config.priority = 0;                    addOrUpdateNetworkNative(config);                }            }            mLastPriority = 0;        }        // Set to the highest priority and save the configuration.        WifiConfiguration config = new WifiConfiguration();        config.networkId = netId;        config.priority = ++mLastPriority;        addOrUpdateNetworkNative(config);        mWifiNative.saveConfig();        /* Enable the given network while disabling all other networks */        enableNetworkWithoutBroadcast(netId, true);       /* Avoid saving the config & sending a broadcast to prevent settings        * from displaying a disabled list of networks */        return true;    }

有時候,我們會忘記已串連WiFi的密碼,應用市場也有相關的應用可以幫我們讀取。其實如有有Root許可權,用RE檔案管理工具(Root Explorer)就可以查看了。檔案路徑:

/data/misc/wifi/sockets/wpa_supplicant.conf

每一個network包裹起來的就是一個串連過的WiFi熱點,其中ssid是名字,psk就是密碼了,也可以看到其他資訊,包括加密類型key_mgmt和優先順序priority,是否自動連接autojoin等,如:



轉載請註明出處:周木水的CSDN部落格 http://blog.csdn.net/zhoumushui

我的GitHub:周木水的GitHub https://github.com/zhoumushui


Android自動連接WiFi優先順序規則,以及查看已串連WiFi的密碼

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.