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 505 forks source link

[Bug] Android 12 Coarse Location Permission is returning Denied Status #1999

Closed Cheesebaron closed 2 years ago

Cheesebaron commented 2 years ago

Description

If you request LocationWhenInUse permission targeting Android 12, it shows a nice pop-up, where you can select the precision of the permission you want to grant. Either Approximate (coarse) or Precise (fine).

If you only allow Approximate, the CheckAsync will always return "Denied" status, even though permission was granted.

There is no way of defining what you want.

Both fine and coarse is requested: https://github.com/xamarin/Essentials/blob/main/Xamarin.Essentials/Permissions/Permissions.android.cs#L232-L233

Seems like it happens in this part of the code when checking permissions: https://github.com/xamarin/Essentials/blob/main/Xamarin.Essentials/Permissions/Permissions.android.cs#L82

You simply just return the status of the first, even though there might be other permissions that have been granted.

Steps to Reproduce

  1. set android:targetSdkVersion="31" and TFM to 12 or higher
  2. Check permisison with await Permissions.CheckStatusAsync<Permissions.LocationWhenInUse>();
  3. PermissionStatus will always be "Denied" if you selected approximate location when requsting

Expected Behavior

Some kind of granularity to know which of the two requested permissions in LocationWhenInUse have been permitted by the user.

Actual Behavior

PermissionStatus is Denied if "Approximate" is selected

Basic Information

Screenshots

Screenshot_20220422-140530

Reproduction Link

jfversluis commented 2 years ago

Are you sure you're using the latest version? We did some fixes around this.

@aritchie ?

aritchie commented 2 years ago

@jfversluis I fixed RequestAsync. This is a different method/code path.

jfversluis commented 2 years ago

@Cheesebaron would you be able to test the resulting NuGet from the linked PR and see if that has the desired result? If so, I can add it to the next release I want to put out this week/early next week.

Cheesebaron commented 2 years ago

Yep, will give it a spin and see how it behaves ☺️