Start a Foreground Service From a Quick Tile on Android (targetSdkVersion 34 and higher)

324 views Asked by At

I am the developer of a simple Android app that records location movements on behalf of the user. One can start the recording from the main Activity as well as from a Quick Tile. The recording takes place in a Foreground Service that displays a notification.

I recently updated the dependencies to targetSdkVersion 34. Since then the recording service cannot be started from the app's Quick Tile anymore.

This is how I start the recording Foreground Service from a Quick Tile:

  • the app registers a TileService
  • the TileService listens for taps on the Quick Tile in onClick()
  • the recording Foreground Service is started from within the TileService via application.startForegroundService(intent)

This setup used to work with targetSdkVersion 33.

On targetSdkVersion 34 a tap on the Quick Tile causes a crash. The log shows:

android.app.ForegroundServiceStartNotAllowedException: startForegroundService() not allowed due to mAllowStartForeground false: service org.y20k.trackbook/.TrackerService

I looked at the Android 14 features and changes list and specifically at Restrictions on starting activities from the background. But I fail to see what changed between Android 13 and 14 that affects my case.

I considered the following solutions:

  1. Start an Activity from the TileService that in turn starts the Foreground Service. This approach seems to be clunky.
  2. Implement the recording functionality into the TileService and try to promote it to a Foreground Service and show the notification from within the TileService

What do you think? Can anyone come up with a better solution?

0

There are 0 answers