Baseflow / Baseflow/flutter-geolocator
[Foreground service] Notifications are visible on older devices, but not on newer devices.
- Dominant language
- Dart
- Stars
- 1.3k
- Forks
- 803
- Avg merge
- 8h 16m
- Merged PRs (30d)
- 1
Description
I'm trying to use Geolocator.getPositionStream() in the background to receive the position continuously for a long time even when the app is closed.
**The problem is that notifications are visible on older devices, but not on newer devices.**
It seems to be related to the answer in the url below. (Is my guess correct?)
https://stackoverflow.com/a/50634187
> It's because of Android O bg services restrictions.
So now you need to call startForeground() only for services that were started with startForegroundService() and call it in first 5 seconds after service has been started.
Here is the guide - https://developer.android.com/about/versions/oreo/background#services
Like this:
```
//Start service:
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
startForegroundService(new Intent(this, YourService.class));
} else {
startService(new Intent(this, YourService.class));
}
```
https://developer.android.com/about/versions/oreo/background#services
> Prior to Android 8.0, the usual way to create a foreground service was to create a background service, then promote that service to the foreground. With Android 8.0, there is a complication; the system doesn't allow a background app to create a background service. For this reason, Android 8.0 introduces the new method [startForegroundService()](https://developer.android.com/reference/android/content/Context#startForegroundService(android.content.Intent)) to start a new service in the foreground. After the system has created the service, the app has five seconds to call the service's [startForeground()](https://developer.android.com/reference/android/app/Service#startForeground(int,%20android.app.Notification)) method to show the new service's user-visible notification. If the app does not call [startForeground()](https://developer.android.com/reference/android/app/Service#startForeground(int,%20android.app.Notification)) within the time limit, the system stops the service and declares the app to be [ANR](https://developer.android.com/training/articles/perf-anr).
If the notification doesn't appear means the service isn't running as a ForegroundService normally, I'm afraid the service is being killed by the system.
Contributor guide
Research direction
Start by tracing Geolocator.getPositionStream() into the Android foreground-service implementation and compare service startup and notification behavior across older and newer Android versions. Verify whether the service calls startForegroundService() and startForeground() as described in the issue, then reproduce the missing notification on a newer device.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- android, dart, flutter
- Domain
- mobile
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 35/100