capacitor-community / capacitor-community/background-geolocation
background location is canceled
- Dominant language
- Java
- Stars
- 249
- Forks
- 79
- PR merge metrics
- No merged PRs in 30d
Description
**Describe the bug**
When I start the watch code on iOS everything works correctly but on Android When it runs to start in the background the location icon appears and then disappears
```
this.plt.pause.subscribe( () => {// background
// dont work on android
this.bgGeoS.enable_bg_track()
});
this.plt.resume.subscribe(() => {// foreground
this.bgGeoS.disable_bg_track()
});
```
But if before sending the app to the background it already has the watch code initialized. works correctly
Maybe the way I want to abort this functionality is not correct. I tried to find out if there was a way to detect more before the platform goes into the background
**To Reproduce**
Just create a project and initialize the watch code just when it goes to the background
**Expected behavior**
initializing the watch code just when the platform goes to the background should work on android
**Smartphone (please complete the following information):**
- Device: iphone 15, lenovo z6 , zuk z6
- OS: IOS:latest , andorid 10 and 13
**Additional context**
```
async enable_bg_track() {
const callback = (position?: Location, error?: CallbackError) =>{
this.last_location = position || undefined
console.log(this.last_location);
if(error) {
console.error(error);
if(this.idWatch) BackgroundGeolocation.removeWatcher({id:this.idWatch});
}
}
const options: WatcherOptions = {
requestPermissions: false,
stale: false,
backgroundTitle: "Obteniendo tu ubicación",
backgroundMessage: "Cancelar"
}
BackgroundGeolocation.addWatcher(options, callback).then((id)=> { this.idWatch = id }).catch(err =>{ console.error(err) });
}
```
At the moment my solution is to activate tracking when I start the application. If anyone has any suggestions I would like to hear them.
Contributor guide
Research direction
The reported entry points are enable_bg_track() and BackgroundGeolocation.addWatcher(), called from the plt.pause handler; start by reproducing the Android-only behavior when the watcher is initialized during backgrounding. Compare it with the working case where the watcher is initialized before backgrounding, and consider the issue done when the watcher remains active and delivers location updates in the reported Android scenarios.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- android, typescript
- Domain
- mobile-dev
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100