DanielRM
DanielRM

Reputation: 666

Android intent to enter a search query for google play music app

Hello i am trying to automatically fill the search bar on Google Play Music with a String that my app provides. I currently have the intent to open Google Play Music, but I have not been able to find the right params to fill the search bar on Google Play Music. Here is my code

Intent intent = getApplicationContext().getPackageManager()
.getLaunchIntentForPackage("com.google.android.music");
startActivity(intent);

Would anyone know the right intent? Thanks in advance

Upvotes: 4

Views: 2000

Answers (2)

Aryan Singh
Aryan Singh

Reputation: 38

Below is the working code to play a song with given title.

String title = "Iridescent";

Intent intent = new Intent(MediaStore.INTENT_ACTION_MEDIA_PLAY_FROM_SEARCH);
            intent.putExtra(MediaStore.EXTRA_MEDIA_FOCUS,
                    MediaStore.Audio.Artists.ENTRY_CONTENT_TYPE);
            intent.putExtra(MediaStore.EXTRA_MEDIA_TITLE,title);               
            intent.putExtra(SearchManager.QUERY,title);
            if (intent.resolveActivity(getPackageManager()) != null) {
                startActivity(intent);
            }

Upvotes: 1

DanielRM
DanielRM

Reputation: 666

I found the answer to my question. The documentation can be found here. I had to choose google play music as my default music player, but after that was done the songs were searched for/played automatically with the following code.

Intent intent = new Intent(MediaStore.INTENT_ACTION_MEDIA_PLAY_FROM_SEARCH);
            intent.putExtra(MediaStore.EXTRA_MEDIA_ARTIST, track.getArtistName());
            intent.putExtra(MediaStore.EXTRA_MEDIA_TITLE, track.getName());
            intent.putExtra(SearchManager.QUERY, track.getName());

            startActivity(intent);

Upvotes: 3

Related Questions