transistorsoft / flutter_background_geolocation

Sophisticated, battery-conscious background-geolocation & geofencing with motion-detection
https://www.transistorsoft.com/shop/products/flutter-background-geolocation
Other
649 stars 239 forks source link

Not getting enter geofence event when app- is closed. #763

Closed techrav2021 closed 2 years ago

techrav2021 commented 2 years ago

Your Environment

Doctor summary (to see all details, run flutter doctor -v): [✓] Flutter (Channel unknown, 2.10.4, on macOS 12.3 21E230 darwin-x64, locale en-IN) [✓] Android toolchain - develop for Android devices (Android SDK version 32.1.0-rc1) [✓] Xcode - develop for iOS and macOS (Xcode 13.1) [✗] Chrome - develop for the web (Cannot find Chrome executable at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome) ! Cannot find Chrome. Try setting CHROME_EXECUTABLE to a Chrome executable. [✓] Android Studio (version 2021.2) [✓] Android Studio (version 2020.3) [✓] VS Code (version 1.67.2) [✓] Connected device (1 available) [✓] HTTP Host Availability

! Doctor found issues in 1 category.


## Expected Behavior
<!--- Tell us what should happen -->
We want to get event when app is closed when user enters in geofence area. so we can send user the local notification.

## Actual Behavior
<!--- Tell us what happens instead -->
Right now we are not able to get the event when user enters in geofence when the app is terminated.however we are getting that event in foreground mode.

## Steps to Reproduce
1. Use same config as in your demo code.

## Context
<!--- What were you trying to do? -->

## Debug logs
<!-- include iOS / Android logs
- ios XCode logs,
- use #getLog #emailLog methods (@see docs)
- Android: $ adb logcat -s TSLocationManager
-->
<details>
    <summary>Logs</summary>

``` <!-- syntax-highligting:  DO NOT REMOVE -->
[background-geolocation.log](https://github.com/transistorsoft/flutter_background_geolocation/files/8829907/background-geolocation.log)

christocracy commented 2 years ago

Show me your code where you're expecting to receive the geofence event when your app is terminated.

techrav2021 commented 2 years ago
void _onGeofence(bg.GeofenceEvent event) async {
    print('[${bg.Event.GEOFENCE}] - $event');

    bg.BackgroundGeolocation.startBackgroundTask().then((int taskId) async {
      // Execute an HTTP request to test an async operation completes.

      if (event.action == 'ENTER') {
        print("\n--------------------------------------\n");
        print("\nNotification Triggered\n");
        print("\n--------------------------------------\n");

    AwesomeNotifications().createNotification(
          content: NotificationContent(
            id: Random().nextInt(20),
            channelKey: NotificationService
                .appNotificationChannel()
                .channelKey,
            title: "Hello",
            body: "Test Notification",
            icon: "resource://drawable/notification_icon",
            notificationLayout: NotificationLayout.Default,
            payload: Map<String, String>.from({
              "safeZoneId": "4inN5Z6sltTiCySQLaaZ",
              "safeZoneName": "A third safe zone",
              "safeZoneKey": "TIJFUY8K3K",
              "safeZoneOwner": "Jef Waumans Co",
              "safeZoneOrganization": "oe6O9ZuuIww4E8ridOm7",
              "safeZoneUpdated": "Apr 28, 2022, 8:41:19 AM"
            }),
          ),
        );
      }

      String url = "${ENV.TRACKER_HOST}/api/devices";
      bg.State state = await bg.BackgroundGeolocation.state;
      http.read(Uri.parse(url), headers: {
        "Authorization": "Bearer ${state.authorization.accessToken}"
      }).then((String result) {
        print("[http test] success: $result");
        bg.BackgroundGeolocation.playSound(
            util.Dialog.getSoundId("TEST_MODE_CLICK"));
        bg.BackgroundGeolocation.stopBackgroundTask(taskId);
      }).catchError((dynamic error) {
        print("[http test] failed: $error");
        bg.BackgroundGeolocation.stopBackgroundTask(taskId);
      });
    });

    setState(() {
      events.insert(
          0, Event(bg.Event.GEOFENCE, event, event.toString(compact: false)));
    });
  }

@christocracy on home screen we are making the notification generation code. but we are not able to get it in background

christocracy commented 2 years ago

In your issue title:

Not getting enter geofence event when app- is closed.

In your last message:

but we are not able to get it in background

There are THREE states for an application:

  1. Foreground
  2. Background
  3. Terminated (closed)

Which is it? Background OR Terminated?

techrav2021 commented 2 years ago

@christocracy Terminated state we are not able to get any event.

christocracy commented 2 years ago

It seems you’re not aware of the lifecycle of an Android app (of course) when the app is terminated.

Your Flutter App no longer exists, including any event-listeners subscribed via BackgroundGeolocation.onXxx

clearly you work with @bajjajjrajjesh