Kastri icon indicating copy to clipboard operation
Kastri copied to clipboard

CrossPlatformLocation: Consistent foreground service notification display

Open alexsawers opened this issue 1 year ago • 3 comments

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 setForegroundServiceBehavior to FOREGROUND_SERVICE_IMMEDIATE so 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 setOngoing to true so 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_NOTIFICATIONS permission (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.

alexsawers avatar Sep 18 '24 19:09 alexsawers

Thanks for the tips! I have a "reboot" of this demo in the works, and will consider your suggestions for it.

DelphiWorlds avatar Sep 18 '24 22:09 DelphiWorlds

I've pushed the work in progress to the Playground repo. Please have a look and let me know what you think.

DelphiWorlds avatar Sep 27 '24 03:09 DelphiWorlds

Thanks. I will put any feedback on the Playground repo.

alexsawers avatar Sep 27 '24 13:09 alexsawers