react-native-background-geolocation: Android doesn't seem to be updating when increasing permissions

Your Environment

  • Plugin version: 4.17.6
  • Platform: Android
  • OS version: 13
  • Device manufacturer / model: Pixel 7 emulator
  • React Native version (react-native -v): 0.74.5
  • Plugin config
const geoLocationConfig: Config = {
  // Geolocation Config
  desiredAccuracy: BackgroundGeolocation.DESIRED_ACCURACY_HIGH,
  // This can get really annoying and we already check for permissions at the gig level.
  disableLocationAuthorizationAlert: true,
  // Activity Recognition
  stopTimeout: 5,
  // Application config
  debug: false, // IS_DEV, // <-- enable this hear sounds for background-geolocation life-cycle.
  logLevel: BackgroundGeolocation.LOG_LEVEL_VERBOSE,
  stopOnTerminate: false, // <-- Allow the background-service to continue tracking when user closes the app.
  startOnBoot: true, // <-- Auto start tracking when device is powered-up.
  // HTTP / SQLite config
  autoSync: false, // <-- [Default: true] Set true to sync each location to server as it arrives.
  enableHeadless: true,
  locationAuthorizationAlert: {
    titleWhenNotEnabled: "Location services are disabled",
    titleWhenOff: "Location services are turned off",
    instructions:
      "Without location access, you won't see your proximity to nearby Gigs or" +
      " be able to verify your attendance at Gigs which may delay or complicate your payment.",
    cancelButton: "Cancel",
    settingsButton: "Settings",
  },
  backgroundPermissionRationale: {
    title: "Allow {applicationName} to access to this device's location in the background?",
    message:
      "{applicationName} Gigpro accesses your location to display nearby Gigs," +
      " verify your work attendance, and ensure accurate payment. " +
      "You can turn off location access at any time from your device settings. " +
      "We value your privacy and are committed to handling your data responsibly.",
    positiveAction: "Change to {backgroundPermissionOptionLabel}",
    negativeAction: "Cancel",
  },
};

Expected Behavior

onProvider subscription is called when a user updates their permissions.

Actual Behavior

no log is sent until the app is killed and reloaded.

Steps to Reproduce

Code I’m using

Steps:

  1. Have lower permissions (i.e. “when in use”, “not allowed”)
  2. open app
  3. when prompted upgrade permissions.
export const useIsMinimalLocationAllowed = () => {
  const [isMinimalAllowed, setIsMinimalAllowed] = useState(false);

  useEffect(() => {
    const providerSub = BackgroundGeolocation.onProviderChange((event) => {
      console.log("EVENT CHANGE: ", event.status); // <= does not log
      setIsMinimalAllowed(event.status === BackgroundGeolocation.AUTHORIZATION_STATUS_ALWAYS);
    });

    return () => providerSub.remove();
  }, [flag]);

  return isMinimalAllowed;
};

Context

Sending a user to update their permissions and listening for that change.

Debug logs

Screenshot 2024-12-04 at 10 30 48 AM

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Comments: 17 (8 by maintainers)

Most upvoted comments

but a listener for permissions seems like it should have that sort of capability

This is not a new issue. People have been asking about it for years. Android doesn’t feel it’s important to provide a BroadcastReceiver for this.

That makes sense but also makes me question why even use “onProviderChange” if on Android

  • wifi toggled
  • Airplane mode toggled
  • settings->location (global one) toggled