dev-hwang / geofence_service Goto Github PK
View Code? Open in Web Editor NEWThis plugin is a geofence service with activity recognition API.
Home Page: https://pub.dev/packages/geofence_service
License: MIT License
This plugin is a geofence service with activity recognition API.
Home Page: https://pub.dev/packages/geofence_service
License: MIT License
Error when building for android emulator
Launching lib\main.dart on sdk gphone x86 arm in debug mode...
lib\main.dart:1
e: D:\Flutter.io\flutter\.pub-cache\hosted\pub.dartlang.org\flutter_activity_recognition-1.2.0\android\src\main\kotlin\com\pravera\flutter_activity_recognition\service\ActivityRecognitionManager.kt: (91, 59): Unresolved reference: S
e: D:\Flutter.io\flutter\.pub-cache\hosted\pub.dartlang.org\flutter_activity_recognition-1.2.0\android\src\main\kotlin\com\pravera\flutter_activity_recognition\service\ActivityRecognitionManager.kt: (92, 65): Unresolved reference: FLAG_MUTABLE
Verson: geofence_service: ^3.4.4
build.gradle has these in default config
minSdkVersion 27
targetSdkVersion 30
multiDexEnabled true
$ flutter doctor -v
[√] Flutter (Channel stable, 2.5.3, on Microsoft Windows [Version 10.0.19042.1348], locale en-GB)
• Flutter version 2.5.3 at D:\Flutter.io\flutter
• Upstream repository https://github.com/flutter/flutter.git
• Framework revision 18116933e7 (6 weeks ago), 2021-10-15 10:46:35 -0700
• Engine revision d3ea636dc5
• Dart version 2.14.4
... No issues
OS: Android s10
Can you provide an example code that shows how to use the library in the background?
does not work in the background state.
$ flutter doctor
Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, 3.10.2, on macOS 13.3.1 22E772610a darwin-arm64, locale ko-KR)
[✓] Android toolchain - develop for Android devices (Android SDK version 31.0.0)
[✓] Xcode - develop for iOS and macOS (Xcode 14.2)
[✓] Chrome - develop for the web
[✓] Android Studio (version 2022.2)
[✓] IntelliJ IDEA Ultimate Edition (version 2023.1.2)
[✓] IntelliJ IDEA Ultimate Edition (version 2023.1.2)
[✓] IntelliJ IDEA Ultimate Edition (version 2022.3.3)
[✓] IntelliJ IDEA Ultimate Edition (version 2023.1.1)
[✓] VS Code (version 1.78.2)
[✓] Connected device (3 available)
[✓] Network resources
Hi @Dev-hwang , I am using this plugin and its really nice, but when the app is in background its not listening.
I want the app to listen in background as well.
Any help would be appreciated!!
Thanks !!
Hey,
I use this package to send a notification when the user arrives someplace but when an app is open application wok correctly but when the app in the background or closed nothing happened.
Is there any way to send a notification when the app is in the background or closed?
Does this plugin still does not support full background geofencing?
The onWillPop
method of WillPopScope is ignored when the child is WillStartForegroundTask.
Also reordering the widget tree does not help. When removing WillStartForegroundTask from the widget, WillPopScope is working as expected.
WillPopScope(
onWillPop: () async {
print("POP");
Navigator.of(context).maybePop();
return false;
},
child:
WillStartForegroundTask(
onWillStart: () async {
...
When clicking on a notification triggered by onGeofenceStatusChanged
, I get following error:
android.app.RemoteServiceException: Context.startForegroundService() did not then call Service.startForeground(): ServiceRecord{845dc41 u0 com.example.xxx/com.pravera.geofence_service.foreground_service.ForegroundSer
vice}
I implemented the plugin according to your guide and also changed the AndroidManifest.xml.
The notification is accomplished with the flutter_local_notifications
package, but the error seems to be within this package.
When app is minimised and in foreground everything work fine but when app is closed location update and geofence both not working.
Getting below error -
Tried to send a platform message to Flutter, but FlutterJNI was detached from native C++. Could not send. Channel: plugins.pravera.com/fl_location/updates. Response ID: 0
I am using this package in my project. I have added all dependencies mentioned in the Read.me but there is no notification shown on my mobile when geofence trigger .Dev logs shows the status change of geofence but no notification is visible. Can anyone help me with this
When using geofence_service together with flutter_local_notifications, when you minimize the app on an iOS device, the local notifications no longer trigger methods on notification clicks.
The breaking point on this issue (as far as I can tell) is on the app minimize, notification clicks trigger correctly if you start the app and never minimize it or if you stop the geofence_service before the first app minimize.
After the app minimizes once with the geofence_service on, I can no longer get the notifications to trigger any methods on click.
Steps to reproduce:
Any help on this would be greatly appreciated.
Hi There, thank you for a great plugin. I have implemented it and am getting an output in the console for each of my GeoFences, which is excellent.
I am a bit of a newb, so apologies for the question, but if you could help, it may assist others.
I need to do two things:
Could you help me out with this? I am so close to getting this working, and your plugin has helped with a very complex element thus far.
Thank you in advance
Dear Dev-hwang,
Is it possible to send text messages between users within the geofence?
안녕하세요,
Geofence service를 백그라운드에서 실행하는 방법에 대해 문의 드립니다.
현재, 어플을 종료하면 geofence service도 종료되어버리는 상황입니다. 이를 아래와 같이 해결하고 싶은데 방법을 잘 몰라서 문의드립니다.
1 geofence service를 5분 간격으로 백그라운드에서 실행시키고 싶습니다.
2 geofence 반경 안에 유저가 들어갈 경우 local notification이 오게 하고 싶습니다. (어플 실행 중이 아닐 때도 local notification이 오도록 하고 싶습니다.)
위 두가지 사항이 geofence 패키지에서 가능한지, 또한 가능하다면 그 방법에 대해 알려주시면 감사하겠습니다.
바쁘신 와중에 문의 드려 죄송합니다.
감사합니다.
I am having trouble getting Geofence_Service to stop when I kill the app.
The two functions we would like to achieve are.
1.I would like to run Geofence_Service in the background at 5 minute intervals.
2.I would like to send out a local notification when a Geofence is crossed.
An error popped up in Crashtlytics on our production env. I opened a new issue for further investigation.
Context.startForegroundService() did not then call Service.startForeground(): ServiceRecord{...
Brand:Samsung
Model:Galaxy Z Fold3 5G
Version:Android 13
# Crashlytics - Stack trace
# Application: com.example.app
# Platform: android
# Version: 3.0.5 (577)
# Issue: 09bb529dadf96b173165f5972dd4308b
# Session: 6576CDC503420001716854EBA52ED2D8_DNE_0_v2
# Date: Mon Dec 11 2023 11:53:44 GMT+0300 (GMT+03:00)
Fatal Exception: android.app.RemoteServiceException$ForegroundServiceDidNotStartInTimeException: Context.startForegroundService() did not then call Service.startForeground(): ServiceRecord{8df5c85 u0 com.example.app/com.pravera.flutter_foreground_task.service.ForegroundService}
at android.app.ActivityThread.generateForegroundServiceDidNotStartInTimeException(ActivityThread.java:2251)
at android.app.ActivityThread.throwRemoteServiceException(ActivityThread.java:2222)
at android.app.ActivityThread.-$$Nest$mthrowRemoteServiceException()
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2518)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loopOnce(Looper.java:226)
at android.os.Looper.loop(Looper.java:313)
at android.app.ActivityThread.main(ActivityThread.java:8810)
at java.lang.reflect.Method.invoke(Method.java)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:604)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1067)
Caused by android.app.StackTrace: Last startServiceCommon() call for this service was made here
at android.app.ContextImpl.startServiceCommon(ContextImpl.java:1988)
at android.app.ContextImpl.startForegroundService(ContextImpl.java:1933)
at android.content.ContextWrapper.startForegroundService(ContextWrapper.java:839)
at q0.a$f.b()
at q0.a.p()
at com.pravera.flutter_foreground_task.service.a.d(:39)
at ed.b.onMethodCall(:139)
at ue.j$a.a(:17)
at ie.c.l(:18)
at ie.c.m(:40)
at ie.c.i()
at ie.b.run(:12)
at android.os.Handler.handleCallback(Handler.java:942)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loopOnce(Looper.java:226)
at android.os.Looper.loop(Looper.java:313)
at android.app.ActivityThread.main(ActivityThread.java:8810)
at java.lang.reflect.Method.invoke(Method.java)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:604)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1067)
Crashlytics Exception Handler1:
at dalvik.system.VMStack.getThreadStackTrace(VMStack.java)
at java.lang.Thread.getStackTrace(Thread.java:1841)
at java.lang.Thread.getAllStackTraces(Thread.java:1909)
at t9.v.z(:16)
at t9.v.o(:4)
at t9.v.j(:45)
at t9.v.d(:44)
at t9.u0.r(:19)
at t9.u0.s(:32)
at t9.r$b.a(:49)
at t9.r$b.call()
at t9.o$c.a(:2)
at e8.x.run(:8)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1137)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:637)
at t9.b0$a$a.a(:2)
at t9.e.run(:5)
at java.lang.Thread.run(Thread.java:1012)
Cuikd errors occurring when adding geofence_service
\fl_location-1.2.2\android\src\main\kotlin\com\pravera\fl_location\service\LocationDataProvider.kt: (137, 23): Only safe (?.) or non-null asserted (!!.) calls are allowed on a nullable receiver of type Location? etc
Resolved by updating the fl_location version.
PR added #27
location is not being used while app is in background, but when we use the flutter_foreground_task from the master branch directly it is working
I removed the activity permissions and the setOnActivityChanged once I don't have a real use for those data. But when I call the service the app crashes and returns "[access] This app has crashed because it attempted to access privacy-sensitive data without a usage description. The app's Info.plist must contain an NSMotionUsageDescription key with a string value explaining to the user how the app uses this data."
. Is there a way to prevent this? Thank you
By the way, I am currently on version 1.0.3 because this app is still in flutter 1.22.6
Firstly, thank you for your (continued) work on this and other libraries.
When the Android app is running in the foreground (in a Paused lifecycle state), and when I kill the app by swiping it up from the App Overview (the third button in a 3-button navigation layout), the emulator does not exit and I get the following recurring message:
Tried to send a platform message to Flutter, but FlutterJNI was detached from native C++.
Could not send. Channel: plugins.pravera.com/fl_location/updates. Response ID: 12
Note this behaviour doesn't happen if you kill the app by selecting the App Overview button when the app is Active - only when the app is already in the foreground and paused (I have a habit of closing the apps on my phone periodically, and I noticed the battery usage of this app spiked following killing of the app)
I have tried setting android:stopWithTask="false"
and calling dispose manually, and many different attempts to cancel the stream listener manually - however it seems killing the app running in foreground kills the Flutter engine before cancelling the location calculation stream and I don't know how to reorder this sequence. The Android Studio Logcat error that I also tried to unsuccessfully troubleshoot is below:
2021-12-05 01:42:02.642 533-3929/system_process W/InputManager-JNI: Input channel object '32225f9 com.example.test_app2/com.example.test_app2.MainActivity (client)' was disposed without first being removed with the input manager!
2021-12-05 01:42:02.644 533-562/system_process W/UsageStatsService: Unexpected activity event reported! (com.example.test_app2/com.example.test_app2.MainActivity event : 23 instanceId : 209389694)
I created a repo with the current setup embedded in a basic Flutter app here: https://github.com/stantonius/geolocation_debug_app
Any ideas about why this might be occurring?
The flutter doctor is below
[✓] Flutter (Channel beta, 2.8.0-3.3.pre, on macOS 12.0.1 21A559 darwin-arm, locale en-GB)
• Flutter version 2.8.0-3.3.pre at /Development/flutter
• Upstream repository https://github.com/flutter/flutter.git
• Framework revision 262b70ece1 (3 days ago), 2021-12-01 13:00:48 -0800
• Engine revision 06a7363b0c
• Dart version 2.15.0 (build 2.15.0-268.18.beta)
[✓] Android toolchain - develop for Android devices (Android SDK version 31.0.0)
• Android SDK at /Library/Android/sdk
• Platform android-31, build-tools 31.0.0
• ANDROID_SDK_ROOT = /Library/Android/sdk
• Java binary at: /Downloads/Android Studio.app/Contents/jre/Contents/Home/bin/java
• Java version OpenJDK Runtime Environment (build 11.0.10+0-b96-7249189)
• All Android licenses accepted.
[✗] Xcode - develop for iOS and macOS
✗ Xcode installation is incomplete; a full installation is necessary for iOS development.
Download at: https://developer.apple.com/xcode/download/
Or install Xcode via the App Store.
Once installed, run:
sudo xcode-select --switch /Applications/Xcode.app/Contents/Developer
sudo xcodebuild -runFirstLaunch
✗ CocoaPods not installed.
CocoaPods is used to retrieve the iOS and macOS platform side's plugin code that responds to your plugin usage on the Dart side.
Without CocoaPods, plugins will not work on iOS or macOS.
For more info, see https://flutter.dev/platform-plugins
To install see https://guides.cocoapods.org/using/getting-started.html#installation for instructions.
[✓] Chrome - develop for the web
• Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome
[✓] Android Studio (version 2020.3)
• Android Studio at
• Flutter plugin can be installed from:
🔨 https://plugins.jetbrains.com/plugin/9212-flutter
• Dart plugin can be installed from:
🔨 https://plugins.jetbrains.com/plugin/6351-dart
• Java version OpenJDK Runtime Environment (build 11.0.10+0-b96-7249189)
[✓] IntelliJ IDEA Community Edition (version 2021.2.3)
• IntelliJ at /Applications/IntelliJ IDEA CE.app
• Flutter plugin version 62.0.3
• Dart plugin version 212.5632
[✓] VS Code (version 1.62.3)
• VS Code at /Applications/Visual Studio Code.app/Contents
• Flutter extension version 3.29.0
[✓] Connected device (2 available)
• sdk gphone64 arm64 (mobile) • emulator-5554 • android-arm64 • Android 12 (API 31) (emulator)
• Chrome (web) • chrome • web-javascript • Google Chrome 96.0.4664.55
FAILURE: Build failed with an exception.
Could not create an instance of type com.android.build.api.variant.impl.LibraryVariantBuilderImpl.
Namespace not specified. Please specify a namespace in the module's build.gradle file like so:
android {
namespace 'com.example.namespace'
}
I am using WillStartForegroundTask to check the location when the app is paused or inactive. But I want it to be killed, when the app is killed via task manager. Currently I still get the push notification that the app is still runnning in the background, even if it is complelety closed an not shown in the task manager of my android device.
WillStartForegroundTask(
onWillStart: () {
// You can add a foreground task start condition.
return geofenceService.isRunningService;
},
androidNotificationOptions: AndroidNotificationOptions(
channelId: 'geofence_service_notification_channel',
channelName: 'Geofence Service Notification',
channelDescription:
'This notification appears when the geofence service is running in the background.',
channelImportance: NotificationChannelImportance.HIGH,
priority: NotificationPriority.HIGH),
iosNotificationOptions: IOSNotificationOptions(),
notificationTitle: 'Aschaffenburger Geheimnisse läuft im Hintergrund',
notificationText: 'Klicke, um in die App zurückzukehren!',
child:
AnnotatedRegion(
value: SystemUiOverlayStyle.light,
child:
Container();
));
Hi, can you check whats this problem on this case
I got forced closed app then i have error this like this
java.lang.IncompatibleClassChangeError: Found interface com.google.android.gms.location.SettingsClient, but class was expected (declaration of 'com.google.android.gms.location.SettingsClient' appears in /data/app/com.kiatanandagroup.driver-UsfQeG2gVgt3Cq3AzhaG7Q==/base.apk) E/AndroidRuntime(12461): at com.pravera.fl_location.service.LocationDataProvider.checkLocationSettingsAndStartLocationUpdates(LocationDataProvider.kt:68) E/AndroidRuntime(12461): at com.pravera.fl_location.service.LocationDataProvider.requestLocationUpdates(LocationDataProvider.kt:60) E/AndroidRuntime(12461): at com.pravera.fl_location.service.LocationDataProviderManager.requestLocationUpdates(LocationDataProviderManager.kt:47) E/AndroidRuntime(12461): at com.pravera.fl_location.LocationStreamHandlerImpl.onListen(LocationStreamHandlerImpl.kt:39) E/AndroidRuntime(12461): at io.flutter.plugin.common.EventChannel$IncomingStreamRequestHandler.onListen(EventChannel.java:218) E/AndroidRuntime(12461): at io.flutter.plugin.common.EventChannel$IncomingStreamRequestHandler.onMessage(EventChannel.java:197) E/AndroidRuntime(12461): at io.flutter.embedding.engine.dart.DartMessenger.invokeHandler(DartMessenger.java:295) E/AndroidRuntime(12461): at io.flutter.embedding.engine.dart.DartMessenger.lambda$dispatchMessageToQueue$0$DartMessenger(DartMessenger.java:319) E/AndroidRuntime(12461): at io.flutter.embedding.engine.dart.-$$Lambda$DartMessenger$TsixYUB5E6FpKhMtCSQVHKE89gQ.run(Unknown Source:12) E/AndroidRuntime(12461): at android.os.Handler.handleCallback(Handler.java:883) E/AndroidRuntime(12461): at android.os.Handler.dispatchMessage(Handler.java:100) E/AndroidRuntime(12461): at android.os.Looper.loop(Looper.java:237) E/AndroidRuntime(12461): at android.app.ActivityThread.main(ActivityThread.java:8034) E/AndroidRuntime(12461): at java.lang.reflect.Method.invoke(Native Method) E/AndroidRuntime(12461): at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493) E/AndroidRuntime(12461): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1076) I/Process (12461): Sending signal. PID: 12461 SIG: 9
I'm trying to build the example app on my macbook but it does not seem to be working.
Steps taken:
Error:
CFURLRequestSetHTTPCookieStorageAcceptPolicy_block_invoke: no longer
implemented and should not be called
** BUILD FAILED **
Using Xcode 12 and MacOS Big Sur
Sadly, it does not work when the app is completely terminated. I builded the app exactly like you did in your example. Any tips or reasons why this is not working?
Is there a way to create multiple _geofenceServices and run them both? I want to have two geofence-Services with a different loiteringDelayMs. Thanks!
How to remove the notifications (from the method WillStartForegroundTask() ) for Android devices? For iOS I just set showNotification = false. But there is not (or I haven't found it yet) a similar approach for Android notifications. If I remove the notifications in the "WillStartForegroundTask" method (or set them to zero, i.e. androidNotificationOptions: null), the app crashes as soon as I leave it
Can you provide an update for this plugin with an upgrade of Geolocator dependency to ^7.0.1 version?
I am asking the user for permission to track the location always or only while using the app via permission_handler package. I am storing this bool in a global variable. How can I prevent the ForegroundTask to start when the permission for the background is not given?
At the moment the pin in the statusbar disappears for 1 second when closing the app, but appears again immediately afterwards.
How can I prevent the app from using the location when being closed?
This is my code:
`@override
Widget build(BuildContext context) {
return WillStartForegroundTask(
onWillStart: () {
// You can add a foreground task start condition.
if (permissions.background.value) {
print("ONWILLSTART");
return true;
} else {
print("ONWILLSTARTNOT");
return false;
}
},`
When closing the app it prints "ONWILLSTARTNOT", but the notification disappears and comes back immediately.
Any idea what I am doing wrong?
How can it be implemented that the notification is only sent when "GeofenceStatus.DWELL" is activated? Thanks!
In Android (according to the default settings in the interval of 5000 milliseconds), the data is output to the console after the specified time. On iOS, however, this only happens once when the app is opened and then no longer. Is this a bug with the iOS simulator or is this normal? I always run it via Xcode (for Android via Visual Studio Code). Thanks !
Hi
Recently I added this package to our project in order to use the geo-fencing feature, but it seems that its dependencies use shared_preferences_ios which is incompatible with the latest shared_preferences package as "shared_preferences: ^2.0.18"
it causes an error as follows:
[VERBOSE-2:dart_vm_initializer.cc(41)] Unhandled Exception: MissingPluginException(No implementation found for method getAll on channel plugins.flutter.io/shared_preferences)
Could you please tell me what's going on?
Android 14 requires to declare a new permission: https://developer.android.com/develop/background-work/services/fg-service-types#location
Docs should be updated based on this.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.