Android: Geofence events not triggered
Your Environment
- Plugin version: 3.0.5
- Platform: Android
- OS version: 7.0
- Device manufacturer / model: Huawei P9
- React Native version (
react-native -v): 0.59.9 - Plugin config
BackgroundGeolocation.onGeofence(Location.onGeofence);
BackgroundGeolocation.ready({
reset: true,
// Geolocation Config
desiredAccuracy: BackgroundGeolocation.DESIRED_ACCURACY_HIGH,
locationUpdateInterval: 1000,
disableStopDetection: true,
// distanceFilter: 100,
// elasticityMultiplier: 2,
useSignificantChangesOnly: false,
// Activity Recognition
// stopTimeout: 5,
// Application config
debug: false, // <-- enable this hear sounds for background-geolocation life-cycle.
logLevel: BackgroundGeolocation.LOG_LEVEL_DEBUG,
stopOnTerminate: false, // <-- Allow the background-service to continue tracking when user closes the app.
startOnBoot: true, // <-- Auto start tracking when device is powered-up.
enableHeadless: true,
});
Expected Behavior
Geofence events should trigger and call Location.onGeofence. Even when device is stationary an event should be triggered when I add a geofence.
Actual Behavior
Geofence events are almost never triggered, sometimes they are.
Specifically the initial event is not triggered, when stationary, but inside the geofence. I didn't test a lot with walking outside yet.
Also if I understood that correctly I should get a new location update every second with these settings: locationUpdateInterval: 1000, disableStopDetection: true,, however I am only getting one after calling BackgroundGeolocation.start.
Steps to Reproduce
- Install BackgroundGeolocation
- Configure as above
Context
I'm planning to use the use the useSignificantChangesOnly option, because I need only very unprecise times and locations. However it is very important, that every geofence event will trigger at some point after entering or exiting. I tested it first by driving around with the bike, I am getting correct notification updates frequently as expected, just the geofence event is not triggered.
For the log I called start and stop a few times. With every stop I also removed all geofences and after start I added it to the position, where the user currently is.
Debug logs
Logs
06-30 14:21:46.019 DEBUG [TSConfig c] ℹ️ Persist config, dirty: [desiredAccuracy, disableStopDetection, enableHeadless, logLevel, startOnBoot, stopOnTerminate]
06-30 14:21:46.040 DEBUG [BackgroundGeolocation ready] LocationPermission :true
06-30 14:21:47.065 INFO [a a]
✅ Home
06-30 14:21:47.078 DEBUG [TSGeofenceManager c] ℹ️ Persist monitored geofences: []
06-30 14:21:47.096 DEBUG [b a]
ℹ️ LocationAuthorization: Permission granted
06-30 14:21:47.121 INFO [TSGeofenceManager stopMonitoringSignificantLocationChanges]
🔴 Stop monitoring significant location changes
06-30 14:21:47.133 INFO [HeartbeatService a]
🔴 Stop heartbeat
06-30 14:21:47.146 DEBUG [b a]
ℹ️ LocationAuthorization: Permission granted
06-30 14:21:47.153 INFO [TrackingService a]
🔵 setPace: false → false
06-30 14:21:47.159 INFO [ActivityRecognitionService a]
🎾 Start motion-activity updates
06-30 14:21:47.163 INFO [TSGeofenceManager start]
🎾 Start monitoring geofences
06-30 14:21:47.167 DEBUG [HttpService startMonitoringConnectivityChanges]
🎾 Start monitoring connectivity changes
06-30 14:21:47.177 DEBUG [a c]
🎾 Start monitoring powersave changes
06-30 14:21:47.177 DEBUG [HttpService a]
╔═════════════════════════════════════════════
║ 📶 Connectivity change: connected? true
╠═════════════════════════════════════════════
06-30 14:21:47.210 INFO [LocationRequestService a]
╔═════════════════════════════════════════════
║ motionchange LocationResult: 1
╠═════════════════════════════════════════════
╟─ 📍 Location[fused 52******,13****** acc=23 et=+13h59m9s234ms alt=95.69999694824219], age: 39ms, time: 1561897307169
06-30 14:21:47.227 INFO [TSLocationManager onSingleLocationResult]
🔵 Acquired motionchange position, isMoving: false
06-30 14:21:47.236 DEBUG [TSLocationManager calculateMedianAccuracy] Median accuracy: 23.222
06-30 14:21:47.278 INFO [c persist]
✅ INSERT: 45ccb20e-a251-4431-9b68-26ebb4b6d0ba
06-30 14:21:47.292 DEBUG [ActivityRecognitionService a]
🚘 ️DetectedActivity [type=STILL, confidence=100]
06-30 14:21:47.331 DEBUG [TSGeofenceManager startMonitoringStationaryRegion]
🎾 Start monitoring stationary region (radius: 150.0 meters)
06-30 14:21:47.342 INFO [TSLog log]
ℹ️ Location.onLocation called
06-30 14:21:47.347 INFO [ActivityRecognitionService a]
🎾 Start motion-activity updates
06-30 14:21:47.370 INFO [TSLog log]
ℹ️ {"tracking":true,"tripState":0}
06-30 14:21:47.383 DEBUG [ActivityRecognitionService onDestroy]
🔴 ActivityRecognitionService destroyed
06-30 14:21:47.390 DEBUG [TSGeofenceManager$b run] evaluation buffer timer elapsed
06-30 14:21:47.402 DEBUG [TSGeofenceManager c] ℹ️ Persist monitored geofences: [Home]
06-30 14:21:47.411 INFO [TrackingService f]
╔═════════════════════════════════════════════
║ TrackingService motionchange: false
╠═════════════════════════════════════════════
06-30 14:21:47.427 DEBUG [TSGeofenceManager a]
╔═════════════════════════════════════════════
║ TSGeofenceManager found 1/1 within 1000 meters
╠═════════════════════════════════════════════
╟─ 🎾 Home
╚═════════════════════════════════════════════
06-30 14:21:47.431 DEBUG [TrackingService onDestroy]
🔴 TrackingService destroyed
06-30 14:21:47.472 INFO [a a]
✅ Home
06-30 14:21:47.481 INFO [a a]
✅ Home
06-30 14:21:47.487 DEBUG [TSGeofenceManager c] ℹ️ Persist monitored geofences: []
06-30 14:21:47.543 DEBUG [ActivityRecognitionService a]
🚘 ️DetectedActivity [type=STILL, confidence=100]
06-30 14:21:47.563 DEBUG [ActivityRecognitionService onDestroy]
🔴 ActivityRecognitionService destroyed
06-30 14:21:47.613 DEBUG [ActivityRecognitionService a]
🚘 ️DetectedActivity [type=STILL, confidence=100]
06-30 14:21:47.632 DEBUG [ActivityRecognitionService onDestroy]
🔴 ActivityRecognitionService destroyed
06-30 14:21:47.751 DEBUG [TSGeofenceManager$b run] evaluation buffer timer elapsed
06-30 14:21:47.763 DEBUG [TSGeofenceManager c] ℹ️ Persist monitored geofences: [Home]
06-30 14:21:47.769 DEBUG [TSGeofenceManager a]
╔═════════════════════════════════════════════
║ TSGeofenceManager found 1/1 within 1000 meters
╠═════════════════════════════════════════════
╟─ 🎾 Home
╚═════════════════════════════════════════════
06-30 14:21:52.121 INFO [TSScheduleManager oneShot]
⏰ Scheduled OneShot: TERMINATE_EVENT in 10000ms (jobID: -1708771588)
06-30 14:22:01.703 INFO [TSScheduleManager oneShot]
⏰ Scheduled OneShot: TERMINATE_EVENT in 10000ms (jobID: -1708771588)
06-30 14:22:03.323 INFO [a c] ✅
06-30 14:22:03.342 DEBUG [TSGeofenceManager c] ℹ️ Persist monitored geofences: []
06-30 14:22:03.347 DEBUG [TSGeofenceManager b]
🔴 Stop monitoring geofences
06-30 14:22:03.354 INFO [TSGeofenceManager stopMonitoringSignificantLocationChanges]
🔴 Stop monitoring significant location changes
06-30 14:22:03.372 DEBUG [TSGeofenceManager stopMonitoringStationaryRegion]
🔴 Stop monitoring stationary region
06-30 14:22:03.379 DEBUG [TrackingService onDestroy]
🔴 TrackingService destroyed
06-30 14:22:03.387 INFO [ActivityRecognitionService b]
🔴 Stop motion-activity updates
06-30 14:22:03.393 DEBUG [GeofencingService onDestroy]
🔴 GeofencingService destroyed
06-30 14:22:03.404 INFO [HeartbeatService a]
🔴 Stop heartbeat
06-30 14:22:03.418 DEBUG [HttpService stopMonitoringConnectivityChanges]
🔴 Stop monitoring connectivity changes
06-30 14:22:03.430 DEBUG [a d]
🔴 Stop monitoring powersave changes
06-30 14:22:03.447 DEBUG [ActivityRecognitionService onDestroy]
🔴 ActivityRecognitionService destroyed
06-30 14:22:06.487 DEBUG [b a]
ℹ️ LocationAuthorization: Permission granted
06-30 14:22:06.502 INFO [TSGeofenceManager stopMonitoringSignificantLocationChanges]
🔴 Stop monitoring significant location changes
06-30 14:22:06.506 INFO [HeartbeatService a]
🔴 Stop heartbeat
06-30 14:22:06.517 DEBUG [b a]
ℹ️ LocationAuthorization: Permission granted
06-30 14:22:06.524 INFO [TrackingService a]
🔵 setPace: false → false
06-30 14:22:06.535 INFO [ActivityRecognitionService a]
🎾 Start motion-activity updates
06-30 14:22:06.546 INFO [TSGeofenceManager start]
🎾 Start monitoring geofences
06-30 14:22:06.589 DEBUG [HttpService startMonitoringConnectivityChanges]
🎾 Start monitoring connectivity changes
06-30 14:22:06.592 INFO [LocationRequestService a]
╔═════════════════════════════════════════════
║ motionchange LocationResult: 2
╠═════════════════════════════════════════════
╟─ 📍 Location[fused 52******,13****** acc=23 et=+13h59m28s612ms alt=94.19999694824219], age: 44ms, time: 1561897326548
06-30 14:22:06.599 DEBUG [a c]
🎾 Start monitoring powersave changes
06-30 14:22:06.601 DEBUG [HttpService a]
╔═════════════════════════════════════════════
║ 📶 Connectivity change: connected? true
╠═════════════════════════════════════════════
06-30 14:22:06.611 DEBUG [TSGeofenceManager a]
╔═════════════════════════════════════════════
║ TSGeofenceManager found 0/1 within 1000 meters
╠═════════════════════════════════════════════
╚═════════════════════════════════════════════
06-30 14:22:06.625 INFO [TSLocationManager onSingleLocationResult]
🔵 Acquired motionchange position, isMoving: false
06-30 14:22:06.639 DEBUG [TSLocationManager calculateMedianAccuracy] Median accuracy: 23.288
06-30 14:22:06.667 INFO [c persist]
✅ INSERT: 235087e8-2c68-47b0-af2c-0b204dabc563
06-30 14:22:06.693 DEBUG [ActivityRecognitionService a]
🚘 ️DetectedActivity [type=STILL, confidence=100]
06-30 14:22:06.711 DEBUG [TSGeofenceManager startMonitoringStationaryRegion]
🎾 Start monitoring stationary region (radius: 150.0 meters)
06-30 14:22:06.719 INFO [ActivityRecognitionService a]
🎾 Start motion-activity updates
06-30 14:22:06.723 INFO [TSLog log]
ℹ️ Location.onLocation called
06-30 14:22:06.730 INFO [TSLog log]
ℹ️ {"tracking":true,"tripState":0}
06-30 14:22:06.742 DEBUG [ActivityRecognitionService onDestroy]
🔴 ActivityRecognitionService destroyed
06-30 14:22:06.770 INFO [a a]
✅ Home
06-30 14:22:06.773 INFO [TrackingService f]
╔═════════════════════════════════════════════
║ TrackingService motionchange: false
╠═════════════════════════════════════════════
06-30 14:22:06.788 DEBUG [TrackingService onDestroy]
🔴 TrackingService destroyed
06-30 14:22:06.831 DEBUG [TSGeofenceManager c] ℹ️ Persist monitored geofences: []
06-30 14:22:06.918 DEBUG [ActivityRecognitionService a]
🚘 ️DetectedActivity [type=STILL, confidence=100]
06-30 14:22:06.935 DEBUG [ActivityRecognitionService onDestroy]
🔴 ActivityRecognitionService destroyed
06-30 14:22:06.976 DEBUG [ActivityRecognitionService a]
🚘 ️DetectedActivity [type=STILL, confidence=100]
06-30 14:22:06.993 DEBUG [ActivityRecognitionService onDestroy]
🔴 ActivityRecognitionService destroyed
06-30 14:22:07.024 DEBUG [ActivityRecognitionService a]
🚘 ️DetectedActivity [type=STILL, confidence=100]
06-30 14:22:07.040 DEBUG [ActivityRecognitionService onDestroy]
🔴 ActivityRecognitionService destroyed
06-30 14:22:07.088 DEBUG [TSGeofenceManager$b run] evaluation buffer timer elapsed
06-30 14:22:07.103 DEBUG [TSGeofenceManager c] ℹ️ Persist monitored geofences: [Home]
06-30 14:22:07.110 DEBUG [TSGeofenceManager a]
╔═════════════════════════════════════════════
║ TSGeofenceManager found 1/1 within 1000 meters
╠═════════════════════════════════════════════
╟─ 🎾 Home
╚═════════════════════════════════════════════
06-30 14:22:09.536 INFO [TSScheduleManager oneShot]
⏰ Scheduled OneShot: TERMINATE_EVENT in 10000ms (jobID: -1708771588)
06-30 14:22:19.586 INFO [ScheduleEvent onOneShot]
╔═════════════════════════════════════════════
║ ⏰ OneShot event fired: TERMINATE_EVENT
╠═════════════════════════════════════════════
06-30 14:22:19.600 DEBUG [TerminateEvent <init>]
ℹ️ TERMINATE_EVENT ignored (MainActivity is still active).
06-30 14:24:28.811 INFO [TSScheduleManager oneShot]
⏰ Scheduled OneShot: TERMINATE_EVENT in 10000ms (jobID: -1708771588)
06-30 14:24:38.846 INFO [ScheduleEvent onOneShot]
╔═════════════════════════════════════════════
║ ⏰ OneShot event fired: TERMINATE_EVENT
╠═════════════════════════════════════════════
06-30 14:24:38.856 DEBUG [TerminateEvent <init>]
ℹ️ TERMINATE_EVENT ignored (MainActivity is still active).
Update: I updated to 3.0.7 now, issue persists. On the iOS simulator everything works fine.
I now also tried it without removing the geofence, because if I understood that right, they should persist. So what I do in detail:
- Call
BackgroundGeolocation.readyandBackgroundGeolocation.start. - Add a geofence with the current coordinates
- Call
BackgroundGeolocation.stop - Call
BackgroundGeolocation.start
After calling start I immediately get a location change event as expected, but the geofence is not triggered, as I would expect.
Huawei are the worst possible device.
After #stop/#start, pick up device in hand and shake it vigorously for about 10s to simulate movement.
For some reason I was never able to make the plugin respond to me shaking the phone. However I tested the motion activity system in real movement situations and it worked fine.
But still, shoudn't the geofence be triggered as soon as the first notification is received?
My actual problem is, that it doesn't trigger when moving, I just thought I was able to strip the issue down to the described problem. But if in the still case this is expected behaviour, I will record a log from a real trip to see why the geofence doesn't trigger an event.
The google play services Geofencing engine doesn’t evaluate geofences unless Motion is detected.
Ok, thanks! Thats good to know. I will record a log from a real situation then.
Huawei really are the worst possible device. I regularly test with a P20 and it almost never works, while my 11 other test devices work perfectly, including OnePlus, Xiaomi and Samsung.
See http://dontkillmyapp.com
Ok, so do you think it would be a bad idea to disable geofencing completely and check distances myself in the onNotification method to make my app more stable on all devices? Because the notification updates came quite frequently, even with useSignificantChangesOnly: true. I will have a maximum of two geofences at the same time.