flutter_background_geolocation icon indicating copy to clipboard operation
flutter_background_geolocation copied to clipboard

[Help Wanted]: Precise location permission and "Allow all the time" permission pop up unasked.

Open yuva-dev opened this issue 2 months ago • 5 comments

Required Reading

  • [x] Confirmed

Plugin Version

flutter_background_geolocation: "4.16.10"

Mobile operating-system(s)

  • [ ] iOS
  • [x] Android

Device Manufacturer(s) and Model(s)

One Plus Nord CE 5

Device operating-systems(s)

Oxygen OS 15

What do you require assistance about?

  1. I have explicitly handled requesting permissions in my code, but the app pops up Location permission and "Allow all the time" permission notification unannounced.

  2. This happens only when the app is installed from the play store (internal testing). This does not happen when installing debug/release version through USB.

Image

My main.dart file looks like the one below.

Future<void> main() async {
  WidgetsFlutterBinding.ensureInitialized();
  await Firebase.initializeApp();

  //configuration settings need to be updated at app open
  await MobileLocationService.initConfigure();

  // Set up background listeners
  bg.BackgroundGeolocation.registerHeadlessTask(onBackgroundHeadlessEvent);
  BackgroundFetch.registerHeadlessTask(onBackgroundFetch);

  // Set up foreground listeners
  bg.BackgroundGeolocation.onLocation(onForegroundLocation);
  bg.BackgroundGeolocation.onHeartbeat(onForegroundHeartbeat);

  runApp(const MyApp());
}

my mobile_location_service.dart looks like this

static Future<void> initConfigure() async {
    if (_isConfigured) {
      return MyLogger.print("initConfigure: MLS already configured, skipping");
    }

    // bg.BackgroundGeolocation.destroyLocations();
    await bg.BackgroundGeolocation.ready(bg.Config(
      desiredAccuracy: isIos() ? bg.Config.DESIRED_ACCURACY_NAVIGATION : bg.Config.DESIRED_ACCURACY_HIGH,
      //battery heavy setting
      distanceFilter: 0,
      //battery heavy setting
      disableStopDetection: true,
      locationUpdateInterval: 60000,
      stopOnTerminate: false,
      startOnBoot: true,
      foregroundService: true,
      enableHeadless: true,
      preventSuspend: true,
      debug: MyConst.isDebugSettingsEnabled,
      //let me handle the permsissiona
      locationAuthorizationRequest: "Any",
      //let me handle the permsissiona
      disableLocationAuthorizationAlert: true,
      notification: bg.Notification(
        title: MyConst.appName,
        text: "Background location tracking in progress.",
        channelName: "Background Location",
        // smallIcon: "mipmap/ic_launcher",
        sticky: true,
        priority: bg.Config.NOTIFICATION_PRIORITY_HIGH,
      ),
      logLevel: MyConst.isDebugSettingsEnabled ? bg.Config.LOG_LEVEL_VERBOSE : bg.Config.LOG_LEVEL_INFO,
    )).then((bg.State state) {
      MyLogger.print("initConfigure: BG ready. ${state.toString()}");
    });

    _isConfigured = true;
  }


Inspite of all these settings it is still showing up as shown above. Please resolve this issue.

[Optional] Plugin Code and/or Config

static Future<void> initConfigure() async {
    if (_isConfigured) {
      return MyLogger.print("initConfigure: MLS already configured, skipping");
    }

    // bg.BackgroundGeolocation.destroyLocations();
    await bg.BackgroundGeolocation.ready(bg.Config(
      desiredAccuracy: isIos() ? bg.Config.DESIRED_ACCURACY_NAVIGATION : bg.Config.DESIRED_ACCURACY_HIGH,
      //battery heavy setting
      distanceFilter: 0,
      //battery heavy setting
      disableStopDetection: true,
      locationUpdateInterval: 60000,
      stopOnTerminate: false,
      startOnBoot: true,
      foregroundService: true,
      enableHeadless: true,
      preventSuspend: true,
      debug: MyConst.isDebugSettingsEnabled,
      //let me handle the permsissiona
      locationAuthorizationRequest: "Any",
      //let me handle the permsissiona
      disableLocationAuthorizationAlert: true,
      notification: bg.Notification(
        title: MyConst.appName,
        text: "Background location tracking in progress.",
        channelName: "Background Location",
        // smallIcon: "mipmap/ic_launcher",
        sticky: true,
        priority: bg.Config.NOTIFICATION_PRIORITY_HIGH,
      ),
      logLevel: MyConst.isDebugSettingsEnabled ? bg.Config.LOG_LEVEL_VERBOSE : bg.Config.LOG_LEVEL_INFO,
    )).then((bg.State state) {
      MyLogger.print("initConfigure: BG ready. ${state.toString()}");
    });

    _isConfigured = true;
  }

[Optional] Relevant log output


yuva-dev avatar Nov 11 '25 11:11 yuva-dev

Please provide logs of this occurring.

Also provide exact reproduction steps.

christocracy avatar Nov 11 '25 12:11 christocracy

Screen recording of the occurrence https://github.com/user-attachments/assets/60559882-0ef8-4aa7-907f-377c0ade5111

Logs after_install.log

yuva-dev avatar Nov 12 '25 09:11 yuva-dev

Calling await MobileLocationService.initConfigure(); and registering event listeners (eg .onLocation) should only be called *inside* MyApp`, not before it's instantiated.

The SDK does not request permission until you call .start().

You must not call any method which requires permission until .ready(config) has resolved (eg .getCurrentPosition).

christocracy avatar Nov 12 '25 13:11 christocracy

Okay I'll change it the way you said but my main problem is this.

Why does occur ONLY in the version downloaded from the play store ? This does not occur in debug or even release versions while building and installing via usb from the mac

yuva-dev avatar Nov 13 '25 09:11 yuva-dev

I've never heard of this before.

The only way the plug-in asks for permissions is when a method is called upon it that requires permissions (eg .start(), .getCurrentPosition, .requestPermission)

christocracy avatar Nov 13 '25 12:11 christocracy

This issue is stale because it has been open for 30 days with no activity.

github-actions[bot] avatar Dec 14 '25 02:12 github-actions[bot]