Closed techrav2021 closed 2 years ago
Show me your code where you're expecting to receive the geofence
event when your app is terminated.
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
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:
Which is it? Background OR Terminated?
@christocracy Terminated state we are not able to get any event.
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
Your Environment
flutter doctor
):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.
Plugin config: