question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

background mode with geolocation plugin

See original GitHub issue

Hi, I was trying to activate the geolocation to the user location after X minutes, but when I locked the phone or put the app on the background it only get the position twice, then it stops working. I already use disableweboptimization and disablebatteryoptimization.

 this.backgroundMode.enable();
      this.backgroundMode.disableWebViewOptimizations();
      console.log('BACKGROUND');
      console.log(this.backgroundMode.isEnabled());
      this.backgroundMode.on('activate').subscribe(r => {
        this.backgroundMode.disableWebViewOptimizations();
        this.backgroundMode.disableBatteryOptimizations();
        // console.log('ONACTIVATE');
        // console.log('STATUS BACKLOCATION');
        this.intervalId = interval(10000);
        this.intervalSub = this.intervalId.subscribe(() => {
          // console.log('PRUEBA PRUEBA');
          this.backgroundMode.wakeUp();
          this.geolocation.getCurrentPosition().then(r => {
            // console.log('UBICACIONI');
            console.log(r.coords.latitude);

And when I unlock the app it resumes the geolocation for the times I was getting the location.

Issue Analytics

  • State:open
  • Created 3 years ago
  • Reactions:3
  • Comments:8

github_iconTop GitHub Comments

1reaction
alicarlocommented, Oct 2, 2020

I have a solution, in android 9 or lower the gps works in background mode, but in android 10 it does not, what you should do is go to settings-app & notifications-you select your app, select permissions, select location, 3 options will appear by default this is the one Option of allow only while using the app, you must select allow all time and once your application is done, the gps will work with background mode, in the documentation it is indicated that the previous steps must be indicated to the user

https://developer.android.com/training/location/permissions#background

image

hope it helps, please test on two different devices with android 10, test nokia 4.2, huawei p30 ligth

0reactions
alicarlocommented, Nov 27, 2021

hello @i-metlyuk

I did a background demo with gps and local notification, I add the url of the repository, do the test and tell me if it works for you, in case it works for you we will review your code again, I hope it will be of help to you and others, I’m waiting to see if it works for you: D

If you like the solution give me a like and a star in the repository

https://github.com/alicarlo/backGroundMode-Demo-Ali/tree/master

If you have android 10 or higher remember to enable allow all the time in settings that is for the gps to work in the background

Read more comments on GitHub >

github_iconTop Results From Across the Web

Cordova Background Geolocation Tracking - Ionic Framework
This Cordova plugin provides foreground and background geolocation and tracking with battery-saving 'circular region monitoring' and 'stop detection'.
Read more >
How to keep my app in the background and get geolocation?
I've developed a Plugin to track the location of a Device in Background and Foreground mode for Android and iOS. This plugin is...
Read more >
Background Geolocation v3 - Transistor Software - Medium
Version 3 of the Background Geolocation SDK for Cordova, React Native and Flutter (v1) is a significant refactor of the SDK's Android Service...
Read more >
Cordova Background Geolocation - Transistor Software
When your iOS app isn't currently requesting continuous location-updates, iOS will immediately put your app to sleep. However, the iOS Background Geolocation ......
Read more >
cordova-plugin-background-geolocation - npm package - Snyk
The plugin has features allowing you to control the behaviour of background-tracking, striking a balance between accuracy and battery-usage. In stationary-mode, ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found