问题
Question
Is it possible to grant Nearby API permissions from phone settings?
- If so, how?
- Does the answer vary by device API level?
Read on for more context if needed :)
General Background
When an app targeting API level 23 or higher is installed on a device running API level 23 or higher, access to actions that required dangerous permissions can be granted or revoked by the user in two different ways:
- while the application is running in the foreground, where calls to requestPermissions result in the user being shown a prompt;
- from the Settings -> Apps screen, where users can grant/revoke access to actions requiring dangerous permissions on a app-by-app or group-by-group basis.
In particular, a user who has denied a permission that has been requested (at least) twice via mechanism #1, and who has checked 'Never ask again' in the most recently-displayed prompt:
can still choose to grant that permission at a later time using mechanism #2.
Nearby API Background
When an app wishes to use the Nearby Messages API, a mechanism similar to (but distinct from) #1 can be used to request the necessary permissions at runtime. As far as I can tell, these permissions are not represented within any of the standard dangerous permissions groups.
Just like for typical dangerous permissions, it is possible for a user to instruct an application to 'Never ask again' for the Nearby API permission (example from Pocket Casts; device running API 23):
However, if a user selects this option it would appear to be totally permanent. Here are the listed permissions groups for Pocket Casts immediately after denying access to the Nearby APIs with 'Never ask again' checked:
The only dangerous permissions group present is Storage, and access is still granted. There's no sign of the Nearby API permissions, and I therefore don't see how it is possible to ever grant access to these permissions after reaching this state... (apart from uninstalling and reinstalling the application, which isn't ideal!)
Edit
In more recent testing I seem unable to permanently deny the Nearby permission. Even after the first denial, the "Never ask again" checkbox does not appear. I am guessing this was introduced by a change in the Google Play Services version running on my phone. Here's what the permissions dialog looks like now. Note that it includes specific instructions related to locating the Nearby permission setting!
回答1:
As pointed out by Morrison Chang in the comments, Nearby API permissions control is located under Settings -> Google. Here's an animated gif showing how to grant access to the Nearby APIs on an app-by-app basis, starting from the settings screen of a Nexus 6 running Marshmallow:
As a developer, this makes sense to me in hindsight - it's the only way Nearby permissions management could be backported to pre-Marshmallow devices. As a user, though, I definitely found this confusing!
来源:https://stackoverflow.com/questions/36511317/is-it-possible-to-grant-nearby-api-permissions-from-phone-settings