棉花糖FINE和COARSE位置许可 [英] Marshmallow FINE and COARSE location permission

查看:223
本文介绍了棉花糖FINE和COARSE位置许可的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试访问ACCESS_FINE_LOCATION,如果找不到它,则访问ACCESS_COARSE_LOCATION.因此,我请求这2个权限,但是它们给了我相同的对话框,要求位置权限.我知道这两个都属于同一组,但是Google说:

I'm trying to access ACCESS_FINE_LOCATION and if it cannot be found access ACCESS_COARSE_LOCATION. So I request for those 2 permission, but they give me the same dialog asking for location permission. I know those are both in the same group but Google says:

注意:即使用户已经在同一组中授予了其他权限,您的应用仍然需要明确请求所需的每个权限.此外,权限的分组可能会在未来的Android版本中发生变化.您的代码不应依赖于特定权限在同一组中或不在同一组中的假设.

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个对话框.这对我来说似乎不是很用户友好.有更好的方法吗?

This means I ask for those 2 permissions within a second, which results in 2 dialog in a row. THis does not seem very user friendly to me. Is there a better way?

推荐答案

定义ACCESS_FINE_LOCATION权限时不需要ACCESS_COARSE_LOCATION权限.

You do not need ACCESS_COARSE_LOCATION permission when you define ACCESS_FINE_LOCATION permission.

来自Android文档:

请求用户权限

为了接收来自NETWORK_PROVIDER的位置更新,或者 GPS_PROVIDER,您必须通过声明以下任意一项来请求用户许可: ACCESS_COARSE_LOCATIONACCESS_FINE_LOCATION权限, 分别在您的Android清单文件中.例如:

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.

注意:如果同时使用NETWORK_PROVIDERGPS_PROVIDER,则 您只需要请求ACCESS_FINE_LOCATION权限,因为 它包括两个提供商的许可. (允许 ACCESS_COARSE_LOCATION仅包含对NETWORK_PROVIDER的许可.)

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

这篇关于棉花糖FINE和COARSE位置许可的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆