CrossPlatformLocation: Consistent foreground service notification display
The CrossPlatformLocation demo works nicely, but I think some improvements can be made to keep the app behavior consistent across distinct Android versions, most specifically related to the foreground service notification display:
-
Notification should
setForegroundServiceBehaviortoFOREGROUND_SERVICE_IMMEDIATEso it displays as soon the service starts (Android 12+). I get the rationale behind the 10-second delay introduced in Android 12 but I think a background location service is expected to run for several minutes anyway. Also, such a delay made me think that the foreground service was not being started at all on my first tests 🤦♂️. -
Notification should
setOngoingtotrueso that the user doesn't dismiss it. Since Android 13 the user can dismiss foreground service notifications, but for a sensitive thing like background location tracking I think it should stay permanent, like on older Android versions, and also for ease of access to the app. -
App should request the runtime
POST_NOTIFICATIONSpermission (Android 13+). The foreground service still runs without this permission but the notification doesn't shows up as it never asks for this permission.
I also thought about suggesting to call startForeground with the foregroundServiceType parameter (Android 13+), but given it defaults to all service types declared in the manifest I see that's only relevant for apps with multiple such types declared.
Thanks for the tips! I have a "reboot" of this demo in the works, and will consider your suggestions for it.
I've pushed the work in progress to the Playground repo. Please have a look and let me know what you think.
Thanks. I will put any feedback on the Playground repo.