使用仅限本地的 WLAN 热点
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
您可以使用仅限本地使用的热点,使连接到 Wi-Fi 热点的设备上的应用能够相互通信。通过此方法创建的网络将无法访问互联网。每个应用都可以发出单个热点请求,但多个应用可以同时请求热点。当多个应用成功并发注册时,它们会共享底层热点。
当热点准备就绪可供使用时,系统会调用 LocalOnlyHotspotCallback.onStarted(LocalOnlyHotspotReservation)
。
如果您的应用以 Android 13(API 级别 33)或更高版本为目标平台,您必须请求 NEARBY_WIFI_DEVICES
才能使用仅限本地的热点,如以下代码段中所示。以较低版本的 Android 为目标平台的应用必须改为请求 ACCESS_FINE_LOCATION
。
<manifest ...>
<<!-- If your app targets Android 13 (API level 33)
or higher, you must declare the NEARBY_WIFI_DEVICES permission. -->
<uses-permission android:name="android.permission.NEARBY_WIFI_DEVICES"
<!-- If your app derives location information from
Wi-Fi APIs, don't include the "usesPermissionFlags"
attribute. -->
android:usesPermissionFlags="neverForLocation" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"
<!-- If any feature in your app relies on
precise location information, don't include the
"maxSdkVersion" attribute. -->
android:maxSdkVersion="32" />
<application ...>
...
</application>
</manifest>
如需详细了解如何使用仅限本地使用的热点,请参阅 startLocalOnlyHotspot()
。
本页面上的内容和代码示例受内容许可部分所述许可的限制。Java 和 OpenJDK 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2025-08-27。
[null,null,["最后更新时间 (UTC):2025-08-27。"],[],[],null,["You can use a local-only hotspot to enable applications on devices connected to\nthe Wi-Fi hotspot to communicate with each other. The network created by this\nmethod will not have Internet access. Each application can make a single request\nfor the hotspot, but multiple applications can request the hotspot at the same\ntime. When multiple applications have successfully registered concurrently, they\nshare the underlying hotspot.\n[`LocalOnlyHotspotCallback.onStarted(LocalOnlyHotspotReservation)`](/reference/android/net/wifi/WifiManager.LocalOnlyHotspotCallback#onStarted(android.net.wifi.WifiManager.LocalOnlyHotspotReservation))\nis called when the hotspot is ready for use.\n\nIf your app targets Android 13 (API level 33) or higher, you must request the\n[`NEARBY_WIFI_DEVICES`](/reference/android/Manifest.permission#NEARBY_WIFI_DEVICES)\nto use a local-only hotspot, as shown in the following code snippet. Apps that\ntarget an earlier version of Android must request `ACCESS_FINE_LOCATION`\ninstead. \n\n```xml\n\u003cmanifest ...\u003e\n \u003c\u003c!-- If your app targets Android 13 (API level 33)\n or higher, you must declare the NEARBY_WIFI_DEVICES permission. --\u003e\n \u003cuses-permission android:name=\"android.permission.NEARBY_WIFI_DEVICES\"\n \u003c!-- If your app derives location information from\n Wi-Fi APIs, don't include the \"usesPermissionFlags\"\n attribute. --\u003e\n android:usesPermissionFlags=\"neverForLocation\" /\u003e\n \u003cuses-permission android:name=\"android.permission.ACCESS_FINE_LOCATION\"\n \u003c!-- If any feature in your app relies on\n precise location information, don't include the\n \"maxSdkVersion\" attribute. --\u003e\n android:maxSdkVersion=\"32\" /\u003e\n \u003capplication ...\u003e\n ...\n \u003c/application\u003e\n\u003c/manifest\u003e\n```\n\nFor more details on using local-only hotspots, see\n[`startLocalOnlyHotspot()`](/reference/android/net/wifi/WifiManager#startLocalOnlyHotspot(android.net.wifi.WifiManager.LocalOnlyHotspotCallback,%20android.os.Handler))."]]