flutter-geolocator icon indicating copy to clipboard operation
flutter-geolocator copied to clipboard

[Bug] Geolocator.requestPermission() doesn't return (Android API 28)

Open yoniker opened this issue 3 years ago • 8 comments

🐛 Bug Report

At Android API 30,everything is working fine all of the time. At android API 28 (I test this dozens of times): About half of the time, requestPermission works, but at the other half,Geolocator.requestPermission() doesn't return not shows anything to the user. Curiously, when the app state changes and upon resuming, it suddenly decides to ask the user for a permission (In some tests I have waited 2 minutes before putting the app in the background,so it isn't about time). See https://youtube.com/shorts/j60CfVZDsyE?feature=share

Expected behavior

Ask permissions from the user all of the time (and not half of the time)? :D

Reproduction steps

Call Geolocator.requestPermission() on an Android API 28 emulator. Possibly not working on other Android APIs (didn't test), note that on android 30 it is working all of the time.

Configuration

Version: 9.0.1

Platform:

  • [ ] :iphone: iOS
  • [X] :robot: Android

yoniker avatar Jul 31 '22 04:07 yoniker

Dear @yoniker,

It would help a lot if you could supply us with an output of flutter doctor -v. Furthermore, can you send us some minimal required code to reproduce this issue. Also, be aware that testing on simulators could also trigger some unusual behaviour.

TimHoogstrate avatar Jun 28 '23 07:06 TimHoogstrate

Without additional information, we are unfortunately not able to resolve this issue. Therefore, we reluctantly closed this issue for now. If you run into this issue later, feel free to file a new issue with a reference to this issue. Add a description of detailed steps to reproduce, expected and current behaviour, logs and the output of 'flutter doctor -v'. Thanks for your contribution.

github-actions[bot] avatar Jul 17 '23 17:07 github-actions[bot]

Kindly reopen the issue, I'm also facing the samilar issue in my project

lakshayXD avatar Jul 18 '23 12:07 lakshayXD

@lakshayXD

It would help a lot if you could supply us with an output of flutter doctor -v. Furthermore, can you send us some minimal required code to reproduce this issue. Also, be aware that testing on simulators could also trigger some unusual behaviour.

TimHoogstrate avatar Jul 19 '23 07:07 TimHoogstrate

Here's the output of flutter doctor -v

`[√] Flutter (Channel stable, 3.10.5, on Microsoft Windows [Version 10.0.22621.1992], locale en-IN) • Flutter version 3.10.5 on channel stable at C:\Users\LakshayChaudhary\flutter_windows_3.7.5-stable\flutter • Upstream repository https://github.com/flutter/flutter.git • Framework revision 796c8ef792 (5 weeks ago), 2023-06-13 15:51:02 -0700 • Engine revision 45f6e00911 • Dart version 3.0.5 • DevTools version 2.23.1

[√] Windows Version (Installed version of Windows is version 10 or higher)

[√] Android toolchain - develop for Android devices (Android SDK version 33.0.2) • Android SDK at C:\Users\LakshayChaudhary\AppData\Local\Android\sdk • Platform android-33-ext4, build-tools 33.0.2 • Java binary at: C:\Program Files\Android\Android Studio\jbr\bin\java • Java version OpenJDK Runtime Environment (build 17.0.6+0-b2043.56-9586694) • All Android licenses accepted.

[√] Chrome - develop for the web • Chrome at C:\Program Files\Google\Chrome\Application\chrome.exe

[X] Visual Studio - develop for Windows X Visual Studio not installed; this is necessary for Windows development. Download at https://visualstudio.microsoft.com/downloads/. Please install the "Desktop development with C++" workload, including all of its default components

[√] Android Studio (version 2022.2) • Android Studio at C:\Program Files\Android\Android Studio • Flutter plugin can be installed from: https://plugins.jetbrains.com/plugin/9212-flutter • Dart plugin can be installed from: https://plugins.jetbrains.com/plugin/6351-dart • Java version OpenJDK Runtime Environment (build 17.0.6+0-b2043.56-9586694)

[√] VS Code (version 1.79.2) • VS Code at C:\Users\LakshayChaudhary\AppData\Local\Programs\Microsoft VS Code • Flutter extension version 3.66.0

[√] Connected device (4 available) • IV2201 (mobile) • YPNRFEWSZDY5UCQW • android-arm64 • Android 13 (API 33) • Windows (desktop) • windows • windows-x64 • Microsoft Windows [Version 10.0.22621.1992] • Chrome (web) • chrome • web-javascript • Google Chrome 115.0.5790.98 • Edge (web) • edge • web-javascript • Microsoft Edge 114.0.1823.67

[√] Network resources • All expected network resources are available.`

Here's the function where I'm calling the Geolocator.requestPermission() method:

` static Future<Position> determinePosition() async { bool serviceEnabled; LocationPermission permission; Position? position;

serviceEnabled = await Geolocator.isLocationServiceEnabled();
if (!serviceEnabled) {
  await Geolocator.openLocationSettings();
}

permission = await Geolocator.checkPermission();

debugPrint('Permission???$permission');

if (permission == LocationPermission.denied &&
    permission != LocationPermission.deniedForever) {
  debugPrint('before permission');
  permission = await Geolocator.requestPermission();
  debugPrint('Permission???$permission');
  if (permission == LocationPermission.whileInUse ||
      permission == LocationPermission.always) {
    position = await Geolocator.getCurrentPosition();
  }
} else {
  if (permission != LocationPermission.deniedForever)
    position = await Geolocator.getCurrentPosition();
}

return position!;

}`

In above function the flow gets stuck at permission = await Geolocator.requestPermission();, & it never returns anything at all

Further, I'm facing this issue on a real device itself not any simulator

lakshayXD avatar Jul 21 '23 06:07 lakshayXD

I am currently facing the same issue, when run on an emulator it works fine but it doesn't work on a real device.

6lackGuy avatar Mar 02 '24 11:03 6lackGuy