GPS 提供商是否需要 ACCESS_FINE_LOCATION 权限?
这个 SO 线程似乎表明它确实如此,但链接同一线程中的 文档 说:
除非另有说明,所有位置 API 方法都需要 Manifest.permission.ACCESS_COARSE_LOCATION 或 Manifest.permission.ACCESS_FINE_LOCATION 权限。如果您的应用程序仅具有粗略权限,则提供商仍将返回位置结果,但确切位置将被混淆为粗略精度。
这让我觉得 Google 为 GPS 提供商添加了粗略位置支持。但是,我收到此错误:
Caused by: java.lang.SecurityException: "gps" location provider require ACCESS_FINE_LOCATION permission.
当然,最好的方法是使用 融合位置提供程序 API 但在那之前我认为文档应该对此更清楚?主要是寻找更新的答案。
This SO thread seems to indicate that it does but the links to documentation in the same thread says:
Unless otherwise noted, all Location API methods require the Manifest.permission.ACCESS_COARSE_LOCATION or Manifest.permission.ACCESS_FINE_LOCATION permissions. If your application only has the coarse permission then providers will still return location results, but the exact location will be obfuscated to a coarse level of accuracy.
Which makes me think that Google added coarse location support for the GPS provider. However, I am getting this error:
Caused by: java.lang.SecurityException: "gps" location provider requires ACCESS_FINE_LOCATION permission.
Of course the best way forward would be to use the fused location provider API but until then I think the documentation should be clearer about this? Mostly looking for an updated answer.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
ACCESS_COARSE_LOCATION 仅包含 NETWORK_PROVIDER 的权限,而不包含 GPS 的权限。
从这个 StackOverflow 线程 的评论中了解更多信息,
似乎有一个来自 MarshmallowVersion 的切换。 Pre Marshmallow 的 CoarseLocation 可让您使用 Gps,但为了隐私而混淆位置
ACCESS_COARSE_LOCATION includes permission only for NETWORK_PROVIDER Not GPS.
Got to know more on this from the comments on this StackOverflow Thread
There seems to be a switch from the MarshmallowVersion. Pre Marshmallow the CoarseLocation let you use the Gps but obfuscate the location for privacy
简短的回答是肯定的。
为了完整起见,从 API31 开始,使用 GPS 提供商需要
ACCESS_COARSE_LOCATION
和ACCESS_FINE_LOCATION
权限。在较低的 API 上,GPS 提供商仅需要
ACCESS_FINE_LOCATION
权限。The short answer is Yes.
To be complete, starting from API31 the use of the GPS provider requires both
ACCESS_COARSE_LOCATION
andACCESS_FINE_LOCATION
permissions.On lower APIs the GPS provider requires only the
ACCESS_FINE_LOCATION
permission.