Flutter permission_handler问题

huangapple go评论307阅读模式
英文:

Flutter permission_handler issue

问题

我是flutter的新手,正在按照这个指南学习permission_handler。

我在Android 13上测试我的应用程序,当我请求权限时,我可以选择只授予大致位置,而不是精确位置。

当我授予精确位置权限时,没有问题。

问题出在我授予大致位置权限时。当我尝试检查Permission.location.statusPermission.locationWhenInUse.statusPermission.locationAlways.status的状态时,它们都是 'denied'。

我如何区分用户是不授予权限还是只授予了大致位置?

我如何检查用户授予了我什么样的精度?

我尝试在控制台中打印所有权限和所有状态,但我找不到关于大致位置的任何信息。

英文:

I am new to flutter and was following this guide on permission_handler.

I am running tests of my app on android 13 and when I request permissions I can also choose to grant only the approximate location and not the exact location.

When I grant the precise location permissions I have no problem.

The problem is when I grant the approximate location. When I go to check the status of Permission.location.status, Permission.locationWhenInUse.status and Permission.locationAlways.status all 3 are 'denied'.

How do I differentiate when the user is not granting permissions and when they are only granting the approximate location?

How can I check what kind of precision the user has granted me?

I tried to print out in console all permissions and all statuses but I can't find anything about the approximate location

答案1

得分: 0

permission_handler 目前不支持检查用户是否授予粗略位置权限。

如果您想确定用户授予您的应用的位置精度,其中一种选择是通过使用诸如 Flutter Geolocator Plugin 这样的地理位置包来请求设备的当前位置。

import 'package:geolocator/geolocator.dart';

final geo = Geolocator();
final location = await geo.getCurrentPosition(); 

// 使用 .accuracy 来识别位置的估计水平精度(以米为单位)。

print(location.accuracy);

请注意,如果 location.accuracy 返回 0.0,则表示设备上不可用或没有 GPS 信号。

除此之外,还有原生 Android 代码中的 LocationManager 类,您需要在 Flutter 中编写自己的方法来访问它。

英文:

Currently permission_handler does not support checking for the case when a user grants approximate location permissions.

If you want to determine the location precision the user granted your app then one option is to identify the accuracy by requesting the devices current location via a geolocation package such as the Flutter Geolocator Plugin.

import 'package:geolocator/geolocator.dart';

final geo = Geolocator();
final location = await geo.getCurrentPosition(); 

// use the .accuracy to identify the estimated horizontal accuracy of the position in meters.

print(location.accuracy);

Note that if location.accuracy returns 0.0 - then it is not available on the device or there is no GPS signal.

Aside from this, there is the LocationManager class in native Android code, you would need to write your own method in Flutter to access this.

huangapple
  • 本文由 发表于 2023年8月10日 22:50:36
  • 转载请务必保留本文链接:https://go.coder-hub.com/76876885.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定