Is there any way to start playing a song in Google music player app from my app? I am trying following code, but google music player only opens the search results & does not actually play the song.
Intent intent = new Intent();
intent.setAction(MediaStore.INTENT_ACTION_MEDIA_PLAY_FROM_SEARCH);
intent.putExtra(SearchManager.QUERY, "It's my life");
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP);
intent.setPackage("com.google.android.music");
activity.startActivity(intent);
The documentation for INTENT_ACTION_MEDIA_PLAY_FROM_SEARCH says following - An intent to perform a search for music media and automatically play content from the result when possible.
So, according to documentation, it should be able to play the song. But, it only opens the search results and does not play it. Any ideas what I am missing here?
Thanks for any help you can offer.
Argh, finally figured it out by getting a heap dump of the Play Music process. You need to add
intent.putExtra("queryComplete", "It's my life");
and everything will work. The value has to be the same as the SearchManager.QUERY
extra.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With