flutter_background_geolocation icon indicating copy to clipboard operation
flutter_background_geolocation copied to clipboard

Use geofence onEntry event in terminated mode

Open MuhammadEhsanMirzaei opened this issue 3 years ago • 8 comments

Does this package save geofence onEnter in the database when the app is terminated? Is there any way to save on entry when the app is terminated and use it when opening the app or use it in the background to send an event to the server?

MuhammadEhsanMirzaei avatar Aug 22 '22 12:08 MuhammadEhsanMirzaei

when the app is terminated and use it when opening the app or

The persists each geofence event in its SQLite database.

If you’ve configured a Config.url, the plugin will automatically post each event to your server, regardless if terminated.

see api docs “HTTP Guide”

christocracy avatar Aug 22 '22 14:08 christocracy

Also see api docs Config.enableHeadless

christocracy avatar Aug 22 '22 14:08 christocracy

I found this in the document: [PERSIST_MODE_ALL] | (DEFAULT) Persist both geofence and location events But that didn't work. Do I set this persistMode: 2? That didn't work too

MuhammadEhsanMirzaei avatar Aug 22 '22 15:08 MuhammadEhsanMirzaei

Show me the Config you supplied to .ready(), which was requested in the issue template that you ignored

christocracy avatar Aug 22 '22 16:08 christocracy

bg.BackgroundGeolocation.ready(
      bg.Config(
        pausesLocationUpdatesAutomatically: false,
        disableLocationAuthorizationAlert: true,
        reset: true,
        stopOnStationary: false,
        stopTimeout: 0,
        stopAfterElapsedMinutes: 0,
        desiredAccuracy: bg.Config.DESIRED_ACCURACY_NAVIGATION,
        distanceFilter: 100,
        stopOnTerminate: false,
        startOnBoot: true,
        debug: true,
        persistMode: 2,
        logLevel: bg.Config.LOG_LEVEL_VERBOSE,
      ),
    ).then((bg.State state) {
      if (!state.enabled) {
        bg.BackgroundGeolocation.start();
      }
    });

MuhammadEhsanMirzaei avatar Aug 22 '22 16:08 MuhammadEhsanMirzaei

Since you’ve not provided an url in your Config, each event is still available to you in the plug-in’s SQLite db. See api docs BackgroundGeolocation.locations.

Also, why did you do this?

stopAfterElapsedMinutes: 0,

That means “.stop() after elapsed minutes".

if you don’t know exactly what that does, don’t configure it.

christocracy avatar Aug 22 '22 16:08 christocracy

I set stopAfterElapsedMinutes: 0 because I manually stop the background. For checking the database, I used this code String log = await bg.Logger.getLog(bg.SQLQuery( start: DateTime.parse('2022-08-22 16:25'), end: DateTime.now())); But geofence in terminated mode didn't record.

MuhammadEhsanMirzaei avatar Aug 22 '22 16:08 MuhammadEhsanMirzaei

because I manually stop the background.

delete that Config option.

christocracy avatar Aug 22 '22 17:08 christocracy

This issue is stale because it has been open for 30 days with no activity.

github-actions[bot] avatar May 28 '24 01:05 github-actions[bot]

This issue was closed because it has been inactive for 14 days since being marked as stale.

github-actions[bot] avatar Jun 11 '24 01:06 github-actions[bot]