Closed willhaslett closed 3 years ago
I consistently get location data when polling it for up to 2 hours after a kill and/or reboot, but after 2 hours, I get this in logcat:
ActivityManager: Foreground service started from background can not have location/camera/microphone access: service com.###########/com.almoullim.background_location.LocationUpdatesService
Is there anything I can do to prevent this? Is more context needed? By the way, I was getting "Not important enough" errors after awhile post-reboot, related to the dummy notification, but those seem to have gone away after I forked the repo and upped the importance of the notification: https://github.com/willhaslett/background_location_important
I tried your git but it only callback exactly 12 times in the background.
@phuhungstdio. I have learned more about this stuff since posting. I believe it's all related to Android's "doze mode". You can use the adb
commands here to disable doze for testing purposes, and you should find that you continue to get location data indefinitely.
The good news is, for location, my testing (Pixel 4A, Android 11) has shown that the phone comes out of doze mode for a time whenever it is moved, e.g., just walking across the street to get the mail. If that is reliably true, and I think it is, then you're not missing any location data anyway. If there are no data, either the phone was off or it hadn't moved since the last data point. This all assumes that you've got keep-alive working for your app. In my case, that required using flutter_backround (or similar) in addition to this library.
@phuhungstdio. I have learned more about this stuff since posting. I believe it's all related to Android's "doze mode". You can use the
adb
commands here to disable doze for testing purposes, and you should find that you continue to get location data indefinitely.The good news is, for location, my testing (Pixel 4A, Android 11) has shown that the phone comes out of doze mode for a time whenever it is moved, e.g., just walking across the street to get the mail. If that is reliably true, and I think it is, then you're not missing any location data anyway. If there are no data, either the phone was off or it hadn't moved since the last data point. This all assumes that you've got keep-alive working for your app. In my case, that required using flutter_backround (or similar) in addition to this library.
So can flutter app run app when the app was killed?
Yes, sort of. You can run a Dart process that survives app kills and even reboots. It runs in a distinct Dart isolate, which is like a thread, except that it doesn't share memory. That non-app process can use Dart libraries that are used by your app, so it can do things (non-UI background things) that your app itself is capable of. The docs for flutter_background are pretty good. This is Android-only.
I consistently get location data when polling it for up to 2 hours after a kill and/or reboot, but after 2 hours, I get this in logcat:
Is there anything I can do to prevent this? Is more context needed? By the way, I was getting "Not important enough" errors after awhile post-reboot, related to the dummy notification, but those seem to have gone away after I forked the repo and upped the importance of the notification: https://github.com/willhaslett/background_location_important