Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Android12] Location is not received when approximate location is granted #352

Open
rubverma opened this issue Jul 8, 2022 · 2 comments

Comments

@rubverma
Copy link

rubverma commented Jul 8, 2022

Description

When targeting Android 12 on a device running Android 12, prompting the user for location permission access has the option for both precise and approximate. If the user selects 'approximate' & 'All the time' then in code Geolocation.GetLocationAsync() is not returning location coordinates. I have a foreground Service started and Geolocation.GetLocationAsync() is called when the app is in a background state (When the user is not actually using the app).

Bug Information

Version Number of Plugin:
Device Tested On: Pixel 4a
Simulator Tested On:
Version of VS: 16.11.11
Version of Xamarin: 16.11
Versions of other things you are using: 4.5.0.6

Steps to reproduce the Behavior

  1. Create a new Xamarin.Android solution
  2. Add the latest Xamarin.Essentials (1.7.3).
  3. Start a foreground service using
    [Service(ForegroundServiceType = global::Android.Content.PM.ForegroundService.TypeLocation)]
  4. Wire up a button that will request the user's permission for LocationAlways
  5. Wire up another button that will be used to retrieve the user's location
  6. Update the AndroidManifest with the following permissions and features:
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
    <uses-permission android:name="android.permission.ACCESS_BACKGROUND_LOCATION" />
    <uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
    <uses-feature android:name="android.hardware.location" android:required="false" />
    <uses-feature android:name="android.hardware.location.gps" android:required="false" />
    <uses-feature android:name="android.hardware.location.network" android:required="false" />
  7. Wire up the first button and click with the following request for location permission:
    await Permissions.RequestAsync<Permissions.LocationAlways>();
  8. Wire up the second button and click with the following user location request:
    private CancellationTokenSource _cts;//this should be a field at the class level for the code behind file
    var request = new GeolocationRequest(GeolocationAccuracy.High, TimeSpan.FromSeconds(10));
    _cts = new CancellationTokenSource();
    var location = await Geolocation.GetLocationAsync(request, _cts.Token);
  9. Add a 2s delay in the second button click before calling the location method, to simulate getting the location in the background state (for the actual use case GetLocationAsync method is getting called from the BLE device)
    await Task.Delay(2000);

Expected Behavior

Upon pressing the first button the user will be prompted to choose between precise or approximate location (select approximate)
then the app location permission setting page will be displayed (select All the time).
Upon pressing the second button and placing the app in the background the user's location should be retrieved.

Actual Behavior

Upon pressing the first button the user will be prompted to choose between precise or approximate location (select approximate)
then the app location permission setting page will be displayed (select All the time). After pressing the second button and placing the app in the background, location information is not received. It is not even throwing an error. Location is available once I'll bring the app to the foreground.

@rubverma
Copy link
Author

any update?

@alok1upadhyay
Copy link

yes, exactly same issue reproducible at my end also.
How to fix it?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants