[Feature] Android secondary position stream for foreground notification updates #1406
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Changes summary
These changes aim to make it possible to implement a GPS track recording app with optimal battery usage in the background while also having a highly responsive UI while the app is in the foreground, without having to declare the
ACCESS_BACKGROUND_LOCATION
permission, essentially fulfilling the following requirements on Android:ACCESS_BACKGROUND_LOCATION
permission at allWithout these changes, a limitation of this library on Android is that you can only have a single location stream active at a given time. And a new location stream cannot start when the app is in the background unless you have declared and granted access to the dangerous
ACCESS_BACKGROUND_LOCATION
permission. This limitation does not affect iOS since you can still start a location stream for a little while after the app has been put in the background.If you want to change the location stream parameters (e.g.
distanceFilter
,intervalDuration
, etc.), you have to cancel your current stream subscription and start a new one. Ideally, an app recording location in the background sets parameters to reduce the location updates frequency to preserve battery, but keeps a high frequency update while the app is in the foreground.These changes allow to have two separate streams (started while the app is in the foreground) with different parameters, and cancel them individually:
foregroundNotificationConfig
is null, then the regular stream is startedforegroundNotificationConfig
is set, then the foreground service stream is startedWhen the app is put in the background, the high frequency UI stream can be canceled while the lower frequency foreground service stream remains active.
How to use this in your code today
If you want to test / use this code before it has been merged and published, you can use the following dependency overrides in your
pubspec.yaml
.Draft disclaimer
This is currently a draft, and the pre-launch checklist below is not complete, because I'm not sure if this is a direction the maintainers of this library would want to take. If so, please let me know, I'll put in the work to complete the checklist and polish this PR.
Pre-launch Checklist
pubspec.yaml
with an appropriate new version according to the pub versioning philosophy, or this PR is does not need version changes.CHANGELOG.md
to add a description of the change.///
).main
.dart format .
and committed any changes.flutter analyze
and fixed any errors.