Skip to content

[Bug]: onProviderChange not triggered if the permission is changed while the app is in background on Android #891 #2612

Description

@medreres

Required Reading

  • Confirmed

Plugin Version

5.1.1

Mobile operating-system(s)

  • iOS
  • Android

Device Manufacturer(s) and Model(s)

Google Pixel 7a

Device operating-systems(s)

Android 16

React Native / Expo version

React Native 0.79.6, Expo 53.0.25

What happened?

Reopening #891 that was never resolved

Expected Behavior

onProviderChanged should be triggered when switching the location permission from OFF to ON from the settings.

Actual Behavior

onProviderChanged is not triggered when switching the location permission from OFF to ON.

Steps to Reproduce

function debugOnProviderChange() {
  BackgroundGeolocation.onProviderChange(provider => {
    console.log('onProviderChange', { provider });
  });

  BackgroundGeolocation.ready(backgroundGeolocationConfiguration)
    .then(state => {
      if (!state.enabled) {
        BackgroundGeolocation.start(() => {
          console.log('started successfully');
        });
      }
    })
    .catch(error => {
      console.error({ error });
    });
}
  1. run the above function
  2. do not grant the permission when prompted
  3. go to settings
  4. turn location permission ON
  5. notice that onProviderChange did not get called.

Context

I'm trying to get an accurate representation of the permission state

Plugin Code and/or Config

javascript 
const backgroundGeolocationConfiguration = {
  // Common
  desiredAccuracy: BackgroundGeolocation.DESIRED_ACCURACY_HIGH,
  distanceFilter: 200,

  // IOS
  stationaryRadius: 50,
  disableMotionActivityUpdates: false,
  activityType: 'AutomotiveNavigation',
  preventSuspend: true,

  // Android
  locationUpdateInterval: 1 * 60 * 1000, // in ms ~ 1 mins
  foregroundService: true,

  // Common Activity Recognition
  activityRecognitionInterval: 10000,
  stopTimeout: 2, // 2 minutes
  minimumActivityRecognitionConfidence: 80, // 0-100%.  Minimum activity-confidence for a state-change
  stopDetectionDelay: 1, // <--  minutes to delay after motion stops before engaging stop-detection system

  // Common Application Config
  debug: false,
  stopOnTerminate: true,
  startOnBoot: false,
  heartbeatInterval: 60
};

Relevant log output

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions