[null,null,["最后更新时间 (UTC):2025-08-21。"],[],[],null,["# Request permission to access nearby Wi-Fi devices\n\nApps that target Android 13 (API level 33) or higher and manage Wi-Fi connections\nshould request the\n[`NEARBY_WIFI_DEVICES`](/reference/android/Manifest.permission#NEARBY_WIFI_DEVICES)\n[runtime permission](/guide/topics/permissions/overview#runtime). This\npermission makes it easier to justify an app's access of nearby Wi-Fi devices;\non previous versions of Android, these apps needed to declare the\n[`ACCESS_FINE_LOCATION`](/reference/android/Manifest.permission#ACCESS_FINE_LOCATION)\npermission instead.\n| **Caution:** If your app tries to call a Wi-Fi API without the proper permission, a [`SecurityException`](/reference/java/lang/SecurityException) occurs.\n\nPermission is part of the nearby devices group\n----------------------------------------------\n\nThe `NEARBY_WIFI_DEVICES` permission is part of the **Nearby devices**\npermission group. This group, added in Android 12 (API level 31), also includes\npermissions related to Bluetooth and Ultra-wideband. When you request any\ncombination of permissions from this permission group, the system shows a single\nruntime dialog and asks the user to approve your app's access to nearby devices.\nIn system settings, the user must enable and disable the **Nearby devices**\npermissions as a group; for example, users can't disable Wi-Fi access but keep\nBluetooth access enabled for a given app.\n\nStrongly assert that your app doesn't derive physical location\n--------------------------------------------------------------\n\nWhen you target Android 13 or higher, consider whether your app\never derives location information from Wi-Fi APIs; if not, you should strongly\nassert that. To make this assertion, set the `usesPermissionFlags` attribute to\n`neverForLocation` in your app's manifest file, as shown in the following code\nsnippet. This process is similar to the one you do when you\n[assert that Bluetooth device information is never used for location](/guide/topics/connectivity/bluetooth/permissions#assert-never-for-location): \n\n```xml\n\u003cmanifest ...\u003e\n \u003cuses-permission android:name=\"android.permission.NEARBY_WIFI_DEVICES\"\n android:usesPermissionFlags=\"neverForLocation\" /\u003e\n \u003capplication ...\u003e\n ...\n \u003c/application\u003e\n\u003c/manifest\u003e\n```\n\nPrevious versions and some APIs require location permission\n-----------------------------------------------------------\n\nSeveral Wi-Fi APIs require the `ACCESS_FINE_LOCATION` permission, even when your\napp targets Android 13 or higher. Examples include the following\nmethods from the `WifiManager` class:\n\n- [`getScanResults()`](/reference/android/net/wifi/WifiManager#getScanResults())\n- [`startScan()`](/reference/android/net/wifi/WifiManager#startScan())\n\nAlso, because the `NEARBY_WIFI_DEVICES` permission is available only on\nAndroid 13 and higher, you should keep any declarations for\n[`ACCESS_FINE_LOCATION`](/reference/android/Manifest.permission#ACCESS_FINE_LOCATION)\nto provide backward compatibility in your app. However, as long as your app\ndoesn't otherwise rely on\n[precise location information](/training/location/permissions#accuracy), you can\nset the maximum SDK version of this permission to `32`, as shown in the\nfollowing code snippet: \n\n```xml\n\u003cmanifest ...\u003e\n \u003cuses-permission android:name=\"android.permission.ACCESS_FINE_LOCATION\"\n android:maxSdkVersion=\"32\" /\u003e\n \u003capplication ...\u003e\n ...\n \u003c/application\u003e\n\u003c/manifest\u003e\n```\n\nCheck for APIs that require the permission\n------------------------------------------\n\nIf your app targets Android 13 or higher, you must declare the\n`NEARBY_WIFI_DEVICES` permission to call any of the following Wi-Fi APIs:\n\n- `WifiManager`\n - [`startLocalOnlyHotspot()`](/reference/android/net/wifi/WifiManager#startLocalOnlyHotspot(android.net.wifi.WifiManager.LocalOnlyHotspotCallback,%20android.os.Handler))\n- `WifiAwareManager`\n - [`attach(AttachCallback attachCallback,\n IdentityChangedListener identityChangedListener,\n Handler handler)`](/reference/android/net/wifi/aware/WifiAwareManager#attach(android.net.wifi.aware.AttachCallback,%20android.net.wifi.aware.IdentityChangedListener,%20android.os.Handler))\n- `WifiAwareSession`\n - [`publish()`](/reference/android/net/wifi/aware/WifiAwareSession#publish(android.net.wifi.aware.PublishConfig,%20android.net.wifi.aware.DiscoverySessionCallback,%20android.os.Handler))\n - [`subscribe()`](/reference/android/net/wifi/aware/WifiAwareSession#subscribe(android.net.wifi.aware.SubscribeConfig,%20android.net.wifi.aware.DiscoverySessionCallback,%20android.os.Handler))\n- `WifiP2pManager`\n - [`addLocalService()`](/reference/android/net/wifi/p2p/WifiP2pManager#addLocalService(android.net.wifi.p2p.WifiP2pManager.Channel,%20android.net.wifi.p2p.nsd.WifiP2pServiceInfo,%20android.net.wifi.p2p.WifiP2pManager.ActionListener))\n - [`connect()`](/reference/android/net/wifi/p2p/WifiP2pManager#connect(android.net.wifi.p2p.WifiP2pManager.Channel,%20android.net.wifi.p2p.WifiP2pConfig,%20android.net.wifi.p2p.WifiP2pManager.ActionListener))\n - [`createGroup()`](/reference/android/net/wifi/p2p/WifiP2pManager#createGroup(android.net.wifi.p2p.WifiP2pManager.Channel,%20android.net.wifi.p2p.WifiP2pConfig,%20android.net.wifi.p2p.WifiP2pManager.ActionListener))\n - [`discoverPeers()`](/reference/android/net/wifi/p2p/WifiP2pManager#discoverPeers(android.net.wifi.p2p.WifiP2pManager.Channel,%20android.net.wifi.p2p.WifiP2pManager.ActionListener))\n - [`discoverServices()`](/reference/android/net/wifi/p2p/WifiP2pManager#discoverServices(android.net.wifi.p2p.WifiP2pManager.Channel,%20android.net.wifi.p2p.WifiP2pManager.ActionListener))\n - [`requestDeviceInfo()`](/reference/android/net/wifi/p2p/WifiP2pManager#requestDeviceInfo(android.net.wifi.p2p.WifiP2pManager.Channel,%20android.net.wifi.p2p.WifiP2pManager.DeviceInfoListener))\n - [`requestGroupInfo()`](/reference/android/net/wifi/p2p/WifiP2pManager#requestGroupInfo(android.net.wifi.p2p.WifiP2pManager.Channel,%20android.net.wifi.p2p.WifiP2pManager.GroupInfoListener))\n - [`requestPeers()`](/reference/android/net/wifi/p2p/WifiP2pManager#requestPeers(android.net.wifi.p2p.WifiP2pManager.Channel,%20android.net.wifi.p2p.WifiP2pManager.PeerListListener))\n- `WifiRttManager`\n - [`startRanging()`](/reference/android/net/wifi/rtt/WifiRttManager#startRanging(android.net.wifi.rtt.RangingRequest,%20java.util.concurrent.Executor,%20android.net.wifi.rtt.RangingResultCallback))\n\nWi-Fi access workflows\n----------------------\n\nFigure 1 shows the Wi-Fi access workflow on devices that run\nAndroid 13 or higher, for apps that target\nAndroid 13 or higher. Note that, as long as you assert that your\napp doesn't derive physical location from Wi-Fi device information, you don't\nneed to declare the `ACCESS_FINE_LOCATION` permission anymore:\n**Figure 1.** Flow chart to determine whether an app that targets Android 13 (API level 33) or higher can access Wi-Fi information.\n\nFigure 2 shows the Wi-Fi access workflow on devices that run\n12L or lower. Note the reliance on the\n`ACCESS_FINE_LOCATION` permission.\n**Figure 2.** Flow chart to determine whether an app that targets 12L (API level 32) or lower can access Wi-Fi information."]]