自 2025 年 3 月 27 日起,我們建議您使用 android-latest-release
而非 aosp-main
建構及貢獻 AOSP。詳情請參閱「Android 開放原始碼計畫變更」。
Wi-Fi 首選網路卸載掃描
透過集合功能整理內容
你可以依據偏好儲存及分類內容。
Wi-Fi 偏好網路卸載 (PNO) 掃描是低耗電量的 Wi-Fi 掃描,會在裝置與 Wi-Fi 連線中斷且螢幕關閉時,以規律的間隔執行。PNO 掃描可用於尋找並連線至已儲存的網路。這些掃描作業會由架構使用 NL80211_CMD_START_SCHED_SCAN
指令排程。詳情請參閱 nl80211.h。
在搭載 Android 9 以下版本的裝置上,如果裝置已與 Wi-Fi 斷線且螢幕關閉,PNO 掃描會以 20 秒的間隔執行前三次掃描,然後放慢至每 60 秒執行一次掃描,直到所有後續掃描作業結束為止。找到已儲存的網路或螢幕開啟時,PNO 掃描作業就會停止。
Android 10 在 WifiManager
中推出了名為 setDeviceMobilityState()
的可選 API 方法,可根據裝置的移動狀態增加 PNO 掃描間隔,以減少耗電量。
可能的移動狀態如下:
DEVICE_MOBILITY_STATE_UNKNOWN
:不明的移動性
DEVICE_MOBILITY_STATE_HIGH_MVMT
:在腳踏車或機動車輛上
DEVICE_MOBILITY_STATE_LOW_MVMT
:步行或跑步
DEVICE_MOBILITY_STATE_STATIONARY
:未移動
如果裝置處於靜止狀態,Android 架構會將 PNO 掃描間隔從 60 秒增加到 180 秒,以減少耗電量。這項最佳化作業假設裝置在靜止時,不太可能在 PNO 掃描中找到任何新的網路。
如果裝置處於任何其他行動狀態,或未呼叫方法,則裝置會使用預設的 PNO 掃描行為。
實作
如要在搭載 Android 10 以上版本的裝置上實作這項省電功能,請擷取裝置行動性資訊,並從自訂系統應用程式呼叫 setDeviceMobilityState()
方法。
這個頁面中的內容和程式碼範例均受《內容授權》中的授權所規範。Java 與 OpenJDK 是 Oracle 和/或其關係企業的商標或註冊商標。
上次更新時間:2025-07-27 (世界標準時間)。
[[["容易理解","easyToUnderstand","thumb-up"],["確實解決了我的問題","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["缺少我需要的資訊","missingTheInformationINeed","thumb-down"],["過於複雜/步驟過多","tooComplicatedTooManySteps","thumb-down"],["過時","outOfDate","thumb-down"],["翻譯問題","translationIssue","thumb-down"],["示例/程式碼問題","samplesCodeIssue","thumb-down"],["其他","otherDown","thumb-down"]],["上次更新時間:2025-07-27 (世界標準時間)。"],[],[],null,["# Wi-Fi preferred network offload scanning\n\nWi-Fi preferred network offload (PNO) scans are low-powered Wi-Fi scans that\noccur at regular intervals when a device is disconnected from Wi-Fi and the\nscreen is off. PNO scans are used to find and\nconnect to saved networks. These scans are scheduled by the framework using the\n`NL80211_CMD_START_SCHED_SCAN` command. For more information, see\n[nl80211.h](https://git.kernel.org/pub/scm/linux/kernel/git/linville/wireless.git/tree/include/uapi/linux/nl80211.h).\n\nOptimize power usage with device mobility information\n-----------------------------------------------------\n\nOn devices running Android 9 or lower, when the device\nis disconnected from Wi-Fi and the screen is off, PNO scans occur at 20 second\nintervals for the first three scans, then slow down to one scan every 60 seconds\nfor all subsequent scans. PNO scanning stops when a saved network is found or\nthe screen is turned on.\n\nAndroid 10 introduces an optional API method named\n[`setDeviceMobilityState()`](https://cs.android.com/android/platform/superproject/+/android-latest-release:packages/modules/Wifi/framework/java/android/net/wifi/WifiManager.java?q=func:setDeviceMobilityState)\nin `WifiManager` that increases the interval between\nPNO scans based on the device's mobility state to reduce power consumption.\n\nThe possible mobility states are:\n\n- `DEVICE_MOBILITY_STATE_UNKNOWN`: Unknown mobility\n- `DEVICE_MOBILITY_STATE_HIGH_MVMT`: On a bike or in a motor vehicle\n- `DEVICE_MOBILITY_STATE_LOW_MVMT`: Walking or running\n- `DEVICE_MOBILITY_STATE_STATIONARY`: Not moving\n\nIf the device is stationary, the Android framework increases the\ninterval between PNO scans from 60 seconds to 180 seconds to reduce power\nconsumption. This optimization is made on the assumption that the device is\nunlikely to find any new networks in PNO scans when the device is not moving.\n\nIf the device is in any other mobility state or if the method isn't called, the\ndevice uses the default PNO scan behavior.\n\n### Implementation\n\nTo implement this power-optimizing feature on a device running Android\n10 or higher, derive the device mobility information\nand call the `setDeviceMobilityState()` method from a custom system app."]]