Android Auto media app - How to change custom action icon

1k views Asked by At

I'm working on an Android Auto media app, and I'm currently creating some custom actions. I created a custom action to set the player repeat mode, and I'm using the Exoplayer icons, which is working perfectly. However, now I'm working on a custom action to toggle the shuffle mode. I created 2 vector drawable to be the icon, and the difference between both is just the color (White enabled, grey disabled).

    private inner class ShuffleModeActionProvider : MediaSessionConnector.CustomActionProvider {

    override fun getCustomAction(player: Player): PlaybackStateCompat.CustomAction? {
        val actionLabel: CharSequence = "Shuffle Mode"
        val iconResourceId: Int = if (player.shuffleModeEnabled) {
            R.drawable.ic_shuffle_on
        } else {
            R.drawable.ic_shuffle_off
        }

        return PlaybackStateCompat.CustomAction.Builder(ACTION_SHUFFLE_MODE, actionLabel, iconResourceId).build()
    }

    override fun onCustomAction(player: Player, action: String, extras: Bundle?) {
        player.shuffleModeEnabled = !player.shuffleModeEnabled
    }
}

When I test it, it only shows the ic_shuffle_on, the white icon. The button is working, and it's shuffling the playlist, however the icon is not changing. If I print the iconResourceId, it's changing between both icons id, but the visual display remain showing only the white. Has anyone had similar issues with the Android Auto? Android Auto shuffle icon

Thank you.

1

There are 1 answers

0
Gustavopeq On BEST ANSWER

After a long time struggling with these custom action icons, I was able to get it to work. Apparently, the DHU doesn't recognize the custom icons created right away. Therefore, every time I was adding a new icon, the DHU was displaying random icons that didn't match what I created. I had tried to uninstall the app from the cellphone, also restarting the DHU, but even though it wasn't recognizing the new icons.

The only way I got it to work, was following the steps bellow:

  1. Close the DHU if it's running
  2. Uninstall the app from your cellphone if you have it installed
  3. Stop the head unit server on your cellphone
  4. Reboot your cellphone
  5. Install the app
  6. Start the head unit server
  7. Run the DHU in your computer

After all this step, the DHU is able to recognize that there're new custom icons, and will update the display accordingly.

I tried multiple approaches, including but following those steps in order was the only way I got it to work. In case you have the same issue and find another way to fix it, let me know!