whathojeeves
whathojeeves

Reputation: 33

Android: Trying to launch the music player from my app with an input playlist

I'm trying to start the stock music player from my app. I did see a few stackoverflow questions like this one - Intent to open android playlist activity - but that didn't get me anywhere. This is the code I am trying to use right now -

Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setComponent(new ComponentName
        ("com.android.music","PlaylistBrowserActivity"));
intent.setType(MediaStore.Audio.Playlists.CONTENT_TYPE);
intent.setFlags(0x10000000);
intent.putExtra("oneshot", false);
intent.putExtra("playlist", playlistid);
startActivityForResult(intent,1);

I hit this exception -

java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.playlistsonthego/com.example.playlistsonthego.HomeSceen}: android.content.ActivityNotFoundException: Unable to find explicit activity class {com.android.music/PlaylistBrowserActivity}; have you declared this activity in your AndroidManifest.xml?

Can someone point me in the right direction? Thanks!

Upvotes: 3

Views: 1295

Answers (1)

Prashant Thakkar
Prashant Thakkar

Reputation: 1403

Try following

Intent intent = new Intent(Intent.ACTION_PICK);
 intent.setType(MediaStore.Audio.Playlists.CONTENT_TYPE);     
 intent.putExtra("playlist", playlistid);
 intent.putExtra("oneshot", false); 
 startActivityForResult(intent, 1);

what I have changed is from ACTION_VIEW to ACTION_PICK.

Upvotes: 1

Related Questions