react-native-background-geolocation icon indicating copy to clipboard operation
react-native-background-geolocation copied to clipboard

RNBackgroundGeolocation is not working in background mode android above OS 11 versions

Open SatyaBaddireddy890 opened this issue 2 years ago • 10 comments

Your Environment

  • Plugin version: 4.10.1
  • Platform: Android
  • OS version: Above 11
  • Device manufacturer / model: All devices
  • React Native version (react-native -v):0.70.6
  • Plugin config
BackgroundGeolocation.onGeofence(geofence => {
  console.log("[geofence] ", geofence);
  if (geofence.identifier == "DANGER_ZONE") {
    if (geofence.action == "ENTER") {
      // Entering the danger-zone, we want to aggressively track location.
      BackgroundGeolocation.start();
      console.log('enter the region');
    } else if (geofence.action == "EXIT") {
      // Exiting the danger-zone, we resume geofences-only tracking.
      BackgroundGeolocation.startGeofences();
    }
  }
})

// Add a geofence.
BackgroundGeolocation.addGeofence({
  identifier: "DANGER_ZONE",
  radius: 200,
  latitude: this.state.destinationLatitude,
  longitude: this.state.destinationLongitude,
  notifyOnEntry: true,
  notifyOnExit: true,
})

// Ready the plugin.
BackgroundGeolocation.ready({
  desiredAccuracy: BackgroundGeolocation.DESIRED_ACCURACY_HIGH,
  distanceFilter: 10,
  // url: "http://your.server.com/locations",
  geofenceModeHighAccuracy: true,
  autoSync: true
}, state => {
  BackgroundGeolocation.startGeofences();
  
})

Expected Behavior

How it is working in foreground when we reach destination in same way in background mode as well

Actual Behavior

Working only in foreground mode only in android

Steps to Reproduce

1.run the application 2.and moving the app into background mode checking console in emulator as well as real device 3. no logs updated as per background mode 4.

Context

updated the config object and some changes in build.gradle file

Debug logs

image image

SatyaBaddireddy890 avatar Mar 17 '23 12:03 SatyaBaddireddy890

Do no post screenshots of logs. Post actual text

As for the error you see about FLAG_MUTABLE or FLAG_IMMUTABLE, the plugin has supported these flags for the last two years.

Plugin version: 4.10.1

I think you are lying about the version you're actually using. I think you're using a much older version.

christocracy avatar Mar 17 '23 13:03 christocracy

I primarily develop on Android 13 devices with targetSdkVersion 33, compileSdkVersion 33. The problem is on your end, not with the plugin.

christocracy avatar Mar 17 '23 13:03 christocracy

image

SatyaBaddireddy890 avatar Mar 17 '23 14:03 SatyaBaddireddy890

image

SatyaBaddireddy890 avatar Mar 17 '23 14:03 SatyaBaddireddy890

Let me know how to reproduce this error in a simple Hello World app.

christocracy avatar Mar 17 '23 14:03 christocracy

Now its throwing "BackgroundGeolocation is disabled" this issue whenever we call ready function

SatyaBaddireddy890 avatar Mar 20 '23 09:03 SatyaBaddireddy890

Because you’re implementing the code incorrectly and probably trying to call .changePace(true) before .ready has resolved.

christocracy avatar Mar 20 '23 11:03 christocracy

how can we call change pace everytime or after ready state enabled coming false many times. is there any solution? Did you tried the above scenario to overcome the above issue

SatyaBaddireddy890 avatar Mar 20 '23 12:03 SatyaBaddireddy890

Did you tried the above scenario to overcome the above issue

I don’t have to “try” it. You are clearly trying to tell the plug-in to .changePace(true) while State.enabled == false.

It’s like trying to push the accelerator pedal in car while the engine is off.

// turn on the engine
await BackgroundGeolocation.start()
// hit the gas
await BackgroundGeolocation.changePace(true)

christocracy avatar Mar 20 '23 13:03 christocracy

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

github-actions[bot] avatar May 23 '24 01:05 github-actions[bot]

This issue was closed because it has been inactive for 14 days since being marked as stale.

github-actions[bot] avatar Jun 06 '24 01:06 github-actions[bot]