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

Geolocation not working in background mode after a while

Open jchavezjs opened this issue 3 years ago • 7 comments

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

  1. Activate the background location service
  2. Put the app in background mode
  3. Wait for some successful request
  4. 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' }

jchavezjs avatar Dec 03 '20 21:12 jchavezjs

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.

jchavezjs avatar Dec 04 '20 00:12 jchavezjs

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.

jchavezjs avatar Dec 04 '20 01:12 jchavezjs

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

mikeslinkman avatar Dec 04 '20 10:12 mikeslinkman

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

bsor-dev avatar Jan 07 '21 07:01 bsor-dev

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 avatar Jan 08 '21 02:01 darron1217

@darron1217 hi is this also solved the stationary issue?

bsor-dev avatar Feb 05 '21 13:02 bsor-dev

@rosnaib11 I haven't experienced stationary issue. Would you submit an issue with additional information on my repo?

darron1217 avatar Feb 06 '21 02:02 darron1217