自 2025 年 3 月 27 日起,我们建议您使用 android-latest-release
而非 aosp-main
构建 AOSP 并为其做出贡献。如需了解详情,请参阅 AOSP 的变更。
Wi-Fi 基础架构功能
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
Android WLAN 框架可帮助用户连接到优质 WLAN 网络(在有可用 WLAN 网络且需要连接到这类网络的情况下)。Android 通过两种方式来实现这一功能:
- 自动开启 Wi-Fi:当用户靠近之前保存的网络时重新开启 Wi-Fi
- 附近有公共网络时发出通知:当有可用优质开放 Wi-Fi 网络时向用户发出通知
上述功能均通过 AOSP 代码实现,您无需明确启用或配置这些功能。
自动开启 WLAN
用户可能会出于各种原因停用 Wi-Fi(例如,所连接的网络不稳定),但在回家后可能忘记重新启用 Wi-Fi,从而导致体验不佳(例如,无法控制家居自动化设备)。在 Android 9 中引入的“自动开启 Wi-Fi”功能解决了这一问题:只要设备靠近已保存(即用户过去明确连接过)且 RSSI 足够高的 Wi-Fi 网络,便会自动重新启用 Wi-Fi。
用户可在“设置”应用中通过以下路径启用或停用该功能:
设置 > 网络和互联网 > Wi-Fi > Wi-Fi 偏好设置 > 自动开启 Wi-Fi
图 1. “自动开启 Wi-Fi”功能
必须启用“WLAN 扫描”(针对位置信息)才能使该功能正常运行。如果未启用“WLAN 扫描”,则系统会提示用户允许启用此功能。之所以需要启用“Wi-Fi 扫描”,是因为系统要根据扫描结果判断设备是否位于一个符合重启 Wi-Fi 连接条件的 Wi-Fi 网络附近。
该功能可避免在用户停用 Wi-Fi 后立即重新启用,此时即使设备检测到质量符合条件的已保存 Wi-Fi 网络也不会重新连接。例如,如果用户在办公室内并已连接到办公室的 Wi-Fi(已保存的网络),然后停用 Wi-Fi,则该功能将不会重新启用 Wi-Fi,直到用户来到另一个环境,有其他符合重新启用条件的已保存网络时再重新启用。
附近有公共网络时发出通知
只要出现以下情况,“开放网络通知”功能便会向用户发出通知:
- WLAN 已启用
- 设备未连接到 Wi-Fi 网络
- 有开放且 RSSI 足够高的 Wi-Fi 网络(与内部 Wi-Fi 选择算法使用相同 RSSI 阈值)
用户可在“设置”应用中通过以下路径启用或停用该功能:
设置 > 网络和互联网 > 互联网 > 网络偏好设置 > 附近有公共网络时发出通知
图 2. “附近有公共网络时发出通知”功能
本页面上的内容和代码示例受内容许可部分所述许可的限制。Java 和 OpenJDK 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2025-03-27。
[null,null,["最后更新时间 (UTC):2025-03-27。"],[],[],null,["# Wi-Fi infrastructure features\n\nThe Android Wi-Fi framework helps users connect to a good Wi-Fi network when\nnetworks are available and needed. Android does that in two ways:\n\n- **Turn on Wi-Fi automatically**: Re-enabling Wi-Fi when the user is near a previously saved network\n- **Notify for public networks** : Informing users about available *good* open Wi-Fi networks\n\nThe features described are implemented by AOSP code and you don't have to\nexplicitly enable or configure them.\n\nTurn on Wi-Fi automatically\n---------------------------\n\nUsers may disable Wi-Fi for a variety of reasons (e.g. a connection to a bad\nnetwork) and can then forget to re-enable it when arriving back home, resulting\nin a bad experience (e.g. not being able to control home automation devices).\nThe *Turn on Wi-Fi automatically* feature, introduced in\nAndroid 9,\nsolves this issue by automatically\nre-enabling Wi-Fi whenever the device is near a Wi-Fi network that is both a\n**saved** network (i.e. one which the user explicitly connected to in the past)\nand has a *sufficiently* **high RSSI.**\n\nThe feature can be enabled or disabled by the user using the Settings app at:\n\n**Settings** \\\u003e **Network \\& internet** \\\u003e **Wi-Fi** \\\u003e **Wi-Fi preferences** \\\u003e\n**Turn on Wi-Fi automatically**\n\n**Figure 1.** Turn on Wi-Fi automatically feature.\n\nWi-Fi Scanning (for Location) must be enabled for this feature to function. If\nWi-Fi Scanning is not enabled the user is prompted for permission to enable it.\nWi-Fi Scanning is required because scan results are used to determine whether\nthe device is in the vicinity of a Wi-Fi network that meets the criteria to\nre-enable Wi-Fi connectivity.\n\nThe feature avoids re-enabling Wi-Fi immediately after a user disables it, even\nif the device observes a saved Wi-Fi network of sufficient quality. For\nexample, if the user is in the office and is connected to the office Wi-Fi (a\n*saved* network) and then disables Wi-Fi, the feature won't re-enable Wi-Fi\nuntil the user arrives at a different environment with a different saved\nnetwork that meets the re-enabling criteria.\n\nNotify for public networks\n--------------------------\n\nThe *Open network notification* feature raises a notification to the user\nwhenever:\n\n- Wi-Fi is enabled\n- The device is not connected to a Wi-Fi network\n- A Wi-Fi network that is both **open** and has a *sufficiently* **high RSSI** (the same RSSI threshold as used by the internal Wi-Fi selection algorithm) is available\n\nThe feature can be enabled or disabled by the user using the Settings app at:\n\n**Settings** \\\u003e **Network \\& internet** \\\u003e **Internet** \\\u003e **Network preferences** \\\u003e\n**Notify for public networks**\n\n**Figure 2.** Notify for public networks feature."]]