react-native-background-geolocation
react-native-background-geolocation copied to clipboard
Geolocation not working in background mode after a while
Your Environment
- Plugin version: 0.6.3
- Platform: Android
- OS version: 10
- Device manufacturer and model: Samsung Galaxy A10
- Running in Simulator: No
- React Native version: 0.63.3
- Plugin configuration options: BackgroundGeolocation.configure({ desiredAccuracy: BackgroundGeolocation.HIGH_ACCURACY, stationaryRadius: 50, distanceFilter: 50, notificationTitle: 'Background tracking', notificationText: 'enabled', debug: false, startOnBoot: false, startForeground: true, stopOnTerminate: true, locationProvider: BackgroundGeolocation.ACTIVITY_PROVIDER, interval: 1000, fastestInterval: 5000, activitiesInterval: 10000, stopOnStillActivity: false, });
- Link to your project: https://github.com/jchavezjs/geolocationtest
Context
The library works fine when i have the app open, but when i minimize the app and the notification is active it only gets the location like 5 times more and it stop after that. The location is available again when i open the app. I realized that using android.permission.ACCESS_BACKGROUND_LOCATION it works perfectly, but i don't want to depend on that permission because is not available in many androids. I already have android.permission.FOREGROUND_SERVICE as a permission in my manifest but it doesn't work.
Expected Behavior
The geolocation should continue in background mode
Actual Behavior
The geolocation stops after 4 or 5 request when I am in background mode
Possible Fix
I believe the problem is something that makes the library don't work as foreground service because with backgound location it works nice.
Steps to Reproduce
- Activate the background location service
- Put the app in background mode
- Wait for some successful request
- The foreground service is not working until you re open the app
Context
Just trying to do normal background geolocation when app is running as foreground service
Debug logs
This is the log after the last time the geolaction is called in background
2020-12-03 17:04:08.308 1897-1897/com.geolocationtest D/com.marianhello.bgloc.provider.ActivityRecognitionLocationProvider: Location change: Location[fused 13.683869,-89.273859 hAcc=5 et=+11d18h22m17s458ms alt=929.0 vel=0.5 bear=284.0 vAcc=100 sAcc=20 bAcc=10 {Bundle[mParcelledData.dataSize=52]}] 2020-12-03 17:04:08.328 1897-1897/com.geolocationtest D/com.marianhello.bgloc.service.LocationServiceImpl: New location BGLocation[fused 13.683869,-89.273859 id=null acc=5 t=1607036652000 et=+11d18h22m17s458ms alt=929.0 vel=0.5 bear=284.0 {Bundle[mParcelledData.dataSize=52]} locprov=1] 2020-12-03 17:04:08.352 1897-1897/com.geolocationtest D/com.marianhello.bgloc.BackgroundGeolocationFacade: Received MSG_ON_LOCATION 2020-12-03 17:04:08.369 1897-2511/com.geolocationtest I/ReactNativeJS: '[DEBUG] BackgroundGeolocation location', { id: 54, bearing: 284, altitude: 929, mockLocationsEnabled: false, speed: 0.5, accuracy: 5, latitude: 13.6838688, longitude: -89.2738585, locationProvider: 1, time: 1607036652000, isFromMockProvider: false, provider: 'fused' }
I already found the problem. The bug is in android 10, I tested in a Samsung S8 plus with android 9 and works pretty well. I don't know how to do the migration but that's all.
I was reading in many places and it seems that the only way to use this library in android 10 is using the android.permission.ACCESS_BACKGROUND_LOCATION in the manifest and selecting always use location in the interface. I don't know if there is a way to solve it without this permission but its not likely. I keep this issue open if somebody has another idea but my recomendation is to condition the permissions in order to make it functional for all devices.
Hi,
Due to privacy concerns it will NOT be possible to use this library without this permission setup. This simply has to do with the way Android implements the allowance of this permission. And to add additional information for Android 11 the permission dialog will no longer show the "always permissions" in the dialog. With my application we added an additional custom dialog that informs the user about these changes. Hope this helps a little
In android 10 u need a permission "allow all the time" or else it will terminate the process in the background after couple of seconds
I created fork to solve this issue. (And it also fixes Gradle4 issue) https://github.com/darron1217/react-native-background-geolocation
You can install it by command below (Updated)
yarn add @darron1217/react-native-background-geolocation
@darron1217 hi is this also solved the stationary issue?
@rosnaib11 I haven't experienced stationary issue. Would you submit an issue with additional information on my repo?