I am sending a notification from a worker that has an action which should open the media app. In other words, I want to start the MediaBrowserServiceCompat when the action is clicked. I tried this code:
val serviceIntent = Intent(applicationContext, MusicService::class.java).apply {
action = MediaBrowserService.SERVICE_INTERFACE
}
val servicePendingIntent = PendingIntent.getService(applicationContext, 0, serviceIntent, 0)
val builder = NotificationCompat.Builder(
applicationContext,
CHANNEL_ID
)
.addAction(NotificationCompat.Action(R.drawable.icon, "Listen", servicePendingIntent))
Now, it is true that the service is created and started, however, the Automotive app is not open. I compared the created service from when the launcher is clicked with the one created from my side and I found that there are a bunch of connection records in the former that make the difference:
Is there something I can do to mimic the creation of the service as It is done when the launcher is clicked?
I haven't tried it myself, but I believe you should be able to do this using the CAR_INTENT_ACTION_MEDIA_TEMPLATE
and CAR_EXTRA_MEDIA_COMPONENT
as described here.