gpt4 book ai didi

android - Ionic android 请求位置许可

转载 作者:太空宇宙 更新时间:2023-11-03 11:47:30 26 4
gpt4 key购买 nike

我想完成的事情:
如果用户的位置服务阻止我默认获取他/她的手机位置,我想请求 16-25 (Android 4.1.2-7.1.1) 之间的每个 API 的位置权限
由于在 iOS 上我还没有遇到这个问题我想专注于 android。

我已经尝试过的:

  • <uses-permission android:name="android.premission.ACCESS_COARSE_LOCATION" />
  • <uses-permission android:name="android.premission.ACCESS_FINE_LOCATION" />
  • cordova-plugin-android-premissions

上面提到的插件总是返回 hasPermission: true即使在设备上拒绝访问位置,所以它对我不起作用。

我还没有尝试过的:

诊断插件描述说我在 API 23 及更高版本或 API 22 及以下之间进行选择。 (<preference name="android-targetSdkVersion" value="22"/> 是最低目标版本。)但我不知道它是否仍然适用于较低的 API 版本。

我的设置:

  • Cordova CLI:6.2.0
  • Gulp CLI 和本地:3.9.1
  • ionic 框架:1.3.1
  • Ionic CLI:1.7.16
  • 节点:4.2.2
  • 设备安卓:5.0.1
  • 期望的构建目标:16
  • 当前构建目标:22

最佳答案

Diagnostic plugin description says that I have choose between API 23 and above or API 22 and below in my understanding. ( is the minimum target version.) Yet I don't know if it would still work on lower API versions.

cordova-diagnostic-plugin API 级别要求基于用于构建的 SDK 版本,而不是目标设备上运行的 API 版本。因此,使用适用于 API 23 (Android 6.0) 的 SDK 构建的应用仍可在运行旧版 Android 的设备上运行。

您需要将构建目标设置为 API 23(或更高版本)以使用插件的主要版本构建(cordova.plugins.diagnostic 而不是 cordova.plugins.diagnostic .api-22),因为它包含需要 API 23+ 构建环境的运行时权限代码。

If the user's location service is preventing me from getting his/her phone's location by default I'd like to ask for location permission on every API between 16-25 (Android 4.1.2-7.1.1)

这有两个不同的方面:

ask for location permission on every API between 16-25 (Android 4.1.2-7.1.1)

Android 运行时权限在 API 23 (Android 6.0) 中引入

您可以使用 isLocationAuthorized() 检查应用是否有位置授权.在运行 Android 5 (API 22) 或更低版本的设备上调用它将始终返回 TRUE,因为权限已在安装时授予。

您可以请求运行时权限以使用 requestLocationAuthorization() 的位置.在运行 Android 5 (API 22) 或更低版本的设备上调用它不会有任何效果,因为权限已在安装时授予。

location service is preventing me from getting his/her phone's location

您可以使用 isLocationEnabled() 检查用户是否关闭了定位功能.

如果位置关闭,您可以使用 switchToLocationSettings()打开设备位置设置页面以允许用户启用位置服务,或者您可以使用 cordova-plugin-request-location-accuracy请求所需的位置精度,而无需用户在位置设置页面上手动执行此操作。

免责声明:我是 cordova-diagnostic-plugin 的作者和 cordova-plugin-request-location-accuracy .

关于android - Ionic android 请求位置许可,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40149318/

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