I would like to create a MEDIA_PLAY_FROM_SEARCH
(or other) intent that will search for and play a song in any major Android music app. I expected the following command line to work on multiple apps:
adb shell am start -a "android.media.action.MEDIA_PLAY_FROM_SEARCH" -e android.intent.extra.focus "vnd.android.cursor.item/*" -e query "yellow\ submarine\ by\ the\ beatles" -f 268435456
This corresponds to the code:
Intent intent = new Intent(MediaStore.INTENT_ACTION_MEDIA_PLAY_FROM_SEARCH);
intent.putExtra(MediaStore.EXTRA_MEDIA_FOCUS, "vnd.android.cursor.item/*");
intent.putExtra(SearchManager.QUERY, "yellow submarine by the beatles");
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
This launches a chooser on my Pixel 2 listing different apps that can handle the request. If I select Google Play Music, it plays Yellow Submarine. If I select Spotify, it does a search but does not play, even though I have a Spotify premium subscription. YouTube Music also does only a search.
I purposely don't specify whether the query is an artist or song (or both, as in this example), since I want to leave the determination to the music app.
The behavior is the same (in Google Play Music and Spotify) if I remove the MediaStore.EXTRA_MEDIA_FOCUS
extra and the flag:
$ adb shell am start -a "android.media.action.MEDIA_PLAY_FROM_SEARCH" -e query "yellow\ submarine\ by\ the\ beatles"
What do I need in my intent to make it play songs in any major music app (i.e., those supported by Google Assistant)?