Search code examples
androidandroid-auto

Sending API requests from MusicBrowserServiceCompat in Android Auto


I am trying to build a music app like Spotify. I am having difficulties in integrating the app with Android Auto. I have a background service extended from MediaBrowserServiceCompat that plays music. In Android auto mode, when and from where I send a request to the remote server to get playlists and songs?

I checked the Google's Universal Player codes, I couldn't understand how they are getting the songs (and it was in Kotlin... the codes were too short to understand) https://github.com/android/uamp

I also found MediaBrowserCompat that has something to do with connections, however I am not sure whether it is a API connection or a Service.

How do I do it? How do we send requests to a remote server, get results, and populate them?


Solution

  • So just to clarify your question, you are trying to replicate Google's Universal Player codes which can be found https://github.com/android/uamp, but in java and you aren't sure where they are calling the API/getting the songs themselves?

    It appears that they are creating a ConnectionService in AutomotiveMusicService.kt and from that they are calling the API in the common section.

    I think this music demo might also help as I believe it is accomplishing the same thing.