capacitor-community / background-geolocation

A Capacitor plugin that sends you geolocation updates, even while the app is in the background.
MIT License
177 stars 54 forks source link

Background Geolocation stop working after 5 minutes #71

Closed ghimarcos closed 1 year ago

ghimarcos commented 1 year ago

Hi, i have a problem with background geolocation, it works perfectly for 5 minutes, after that it simply stops sending the POST with the location to my API. I configure distanceFilter to send POST every 100 meters, it's looking like a limitation of foreground service, or bad configuration on my part.

Link android limitation -> https://developer.android.com/about/versions/oreo/background?hl=en-US

I tested it on 3 different devices, 2 with android 11, and 1 with android 9, but same problem.

code example app.component.ts :


 this.watcher_id = BackgroundGeolocation.addWatcher(
      {
        backgroundMessage: "Cancel to prevent battery drain.",
        backgroundTitle: "Tracking You.",
        requestPermissions: true,
        stale: false,
        distanceFilter: 100
      },
      function callback(location, error) {
        if (error) {
          if (error.code === "NOT_AUTHORIZED") {
            Modals.confirm({
              title: "Location Required",
              message: (
                "This app needs your location, " +
                "but does not have permission.\n\n" +
                "Open settings now?"
              )
            }).then(function ({ value }) {
              if (value) {
                BackgroundGeolocation.openSettings();
              }
            });
          }
          return console.error(error);
        }
        if (window.navigator.onLine) {
          //***  SENDING POST HERE
        }
      }
    );

Exemple Android Manifest :

<?xml version="1.0" encoding="utf-8"?>


diachedelic commented 1 year ago

Duplicate of #14.