gpt4 book ai didi

android - Marshmallow FINE 和 COARSE 位置许可

转载 作者:IT老高 更新时间:2023-10-28 23:30:53 25 4
gpt4 key购买 nike

我正在尝试访问 ACCESS_FINE_LOCATION,如果找不到,请访问 ACCESS_COARSE_LOCATION。所以我请求这 2 个权限,但他们给了我同样的对话框,请求位置权限。我知道它们都在同一个组中,但 Google 说:

Note: Your app still needs to explicitly request every permission it needs, even if the user has already granted another permission in the same group. In addition, the grouping of permissions into groups may change in future Android releases. Your code should not rely on the assumption that particular permissions are or are not in the same group.

这意味着我在一秒钟内请求这 2 个权限,这会导致连续出现 2 个对话框。这对我来说似乎不是很用户友好。有没有更好的办法?

最佳答案

定义ACCESS_FINE_LOCATION权限时,不需要ACCESS_COARSE_LOCATION权限。

来自 Android 文档:

Requesting User Permissions

In order to receive location updates from NETWORK_PROVIDER or GPS_PROVIDER, you must request user permission by declaring either the ACCESS_COARSE_LOCATION or ACCESS_FINE_LOCATION permission, respectively, in your Android manifest file. For example:

<manifest>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
.......
</manifest>

Without these permissions, your application will fail at runtime when requesting location updates.

Note: If you are using both NETWORK_PROVIDER and GPS_PROVIDER, then you need to request only the ACCESS_FINE_LOCATION permission, because it includes permission for both providers. (Permission for ACCESS_COARSE_LOCATION includes permission only for NETWORK_PROVIDER.)

请看https://developer.android.com/guide/topics/location/strategies.html

关于android - Marshmallow FINE 和 COARSE 位置许可,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33780331/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com