如何检查我的应用程序是否始终或使用Xamarin.forms在Android中使用时获得权限

发布于 2025-01-23 01:50:43 字数 415 浏览 2 评论 0原文

我正在使用Xamarin.Forms作为我的应用程序,并且正在使用Android设备。我想检查我的应用程序是否正在使用“始终”或“使用应用程序”在Android中的位置。

对于iOS,我可以使用 cllocationmanager.status 检查权限状态。

But in android I can't able to check the permission status of "Always" or "While Using the App"

CrossPermissions.Current.CheckPermissionStatusAsync(Permission.LocationWhenInUse);

通过使用上述条件,它始终返回“始终”或“使用应用程序时”。我想要确切的权限状态。 因此,任何人都请帮助我解决这个问题。

I am using xamarin.forms for my app and i am using Android device. I want to check whether my app is using "Always" or "While Using the App" for location in Android.

For iOS I can able to check the permission status using CLLocationManager.Status.

But in android I can't able to check the permission status of "Always" or "While Using the App"

CrossPermissions.Current.CheckPermissionStatusAsync(Permission.LocationWhenInUse);

By using the above condition it always return granted for both "Always" or "While Using the App". I want exact permission status.
So Anyone please help me to resolve this issue.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

蹲墙角沉默 2025-01-30 01:50:43

似乎没有API可以返回Android中位置许可的清晰状态。但是用户需要请求两个权限,android.permission.access_fine_locationandroid.permision.access_background_location在Android中。

此外,两个权限的不同结果意味着不同的位置权限状态:

  • 授予两个权限
  • 始终:使用应用程序时 :允许android.permission.access_fine_location

    deny android.permission.access_background_location

因此您可以执行运行时许可检查以获得清晰的位置许可状态。

It seems that there is no api which can return the clear status of the location permission in android. But the user need to request two permissions, android.permission.ACCESS_FINE_LOCATION and android.permission.ACCESS_BACKGROUND_LOCATION in the android.

Furthermore, the different result of the two permission means different location permission status:

  • Always: both the two permission are granted
  • While Using the App: allow android.permission.ACCESS_FINE_LOCATION
    deny android.permission.ACCESS_BACKGROUND_LOCATION

So you can do a runtime permission check to get a clear status of the location permission.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文