flutter-permission-handler icon indicating copy to clipboard operation
flutter-permission-handler copied to clipboard

locationAlways in android 12

Open DJafari opened this issue 3 years ago • 11 comments

calling Permission.locationAlways.request() doesn't show anything in android 12

DJafari avatar Feb 03 '22 21:02 DJafari

Same problem

kamami avatar Feb 04 '22 22:02 kamami

+1 recently

mono424 avatar Feb 05 '22 10:02 mono424

Really nothing? Is this package even still under maintenance? This is a serious issue

kamami avatar Feb 14 '22 10:02 kamami

seems fixed in 9.0.1

p.s : i test it, but not solved this problem yet

DJafari avatar Feb 15 '22 13:02 DJafari

9.1.0: API 31 (Android 12) - The issue is still present; API 30 (Android 11) - Fixed;

KirillBorodin avatar Feb 21 '22 08:02 KirillBorodin

Same problem!

yuriboeira11tx avatar Mar 08 '22 19:03 yuriboeira11tx

Try replacing below permission

<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />

With

<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" 
    android:maxSdkVersion="31" tools:replace="android:maxSdkVersion" />

anilthapa1939 avatar Mar 16 '22 12:03 anilthapa1939

The same issue I have but in Android 11. @anilthapa1939 your solution does not work at least to me.

neoacevedo avatar Mar 20 '22 18:03 neoacevedo

Scrolling through changelogs I found an entry mentioning a section in the readme detailing that to request locationAlways, you have to request locationWhenInUse first. When doing that on Android 12, things "work". After the initial popup of the location permission for while the app is in use, the app's location settings are opened.

It also seems like requesting locationAlways again after that (even if the user accepted them) will reopen the settings which isn't ideal.

mvarendorff avatar Apr 19 '22 07:04 mvarendorff

We really need a fix for the location. When we ask for precise location we only get approximated but our app needs the precise location

JK-404 avatar Apr 19 '22 19:04 JK-404

@Kampfotter did you used the accuracy: Location.navigation option in changeSettings? I think the default accuracy is enough, and your issue should be asked in flutter plugins .

neoacevedo avatar Apr 19 '22 20:04 neoacevedo

Hi everyone, thank you for reporting this issue.

I have investigated the issue, and there are some intricacies with Android starting from Android 10: https://developer.android.com/training/location/permissions#request-only-foreground.

It boils down to this: before you can request Permission.locationAlways, you need to obtain a foreground location permission via either Permission.location or Permission.locationWhenInUse. This has been described in the plugin in permissions.dart:

  /// Permission for accessing the device's location when the app is running in
  /// the background.
  ///
  /// Depending on the platform and version, the requirements are slightly
  /// different:
  ///
  /// **Android:**
  /// - When running on Android Q and above: Background Location Permission
  /// - When running on Android < Q: Fine and Coarse Location
  ///
  /// **iOS:** CoreLocation - Always
  /// - When requesting this permission, the user needs to grant permission for
  /// the `locationWhenInUse` permission first, clicking on the
  /// `Allow While Using App` option on the popup. After allowing the
  /// permission, the user can request the `locationAlways` permission and can
  /// click on the `Change To Always Allow` option.
  static const locationAlways = PermissionWithService._(4);

I think the documentation could use some work, because it is quite hard to find. Therefore, I have opened PRs #1133 and #1134. These should update both the documentation and add a section to the FAQ over on pub.dev.

JeroenWeener avatar Aug 31 '23 11:08 JeroenWeener