xamarin / Essentials

Xamarin.Essentials is no longer supported. Migrate your apps to .NET MAUI, which includes Maui.Essentials.
https://aka.ms/xamarin-upgrade
Other
1.52k stars 506 forks source link

[Bug] - Android 12 - Geolocation.GetLocationAsync(request) throws an exception while coarse location is granted #2011

Closed aleksandarpanov closed 2 years ago

aleksandarpanov commented 2 years ago

Description

According to Android 12 documentation a user can grant only approximate location (ACCESS_COARSE_LOCATION) even while your app requests ACCESS_FINE_LOCATION. When a geolocation request is made the app throws an exception stating that Permissions.LocationWhenInUse is not granted, although it doesn't have to be granted on Android 12 in order to get approximate location.

https://developer.android.com/training/location/permissions#approximate-request

Steps to Reproduce

  1. Request LocationWhenInUse permission.
  2. Select Approximate precision in a popup
  3. Make a new geolocation request (any accuracy, any frequency)
  4. The app throws an exception stating LocationWhenInUse is not granted.

Expected Behavior

Code should use provided approximate location (ACCESS_CORASE_LOCATION) in order to pull a user's current location (as it is provided by Android 12)

I believe that code in line 259 of https://github.com/xamarin/Essentials/blob/e054b7e19b7fb8f1787af41c95ce4447660422ed/Xamarin.Essentials/Permissions/Permissions.android.cs#L259 should return PermissionStatus.Granted.

The issue is related to another bug reported a few days ago https://github.com/xamarin/Essentials/issues/2009

Actual Behavior

Code throws an exception stating that LocationWhenInUse is not provided.

Basic Information

jfversluis commented 2 years ago

Duplicate of #2009