How do i launch the music player

2019-07-30 12:43发布

问题:

How am i suppose to use this

android.intent.category.APP_MUSIC

to launch the music player? it doesn't work if i call makeMainSelectorActivity

 Intent intent = new Intent();  
 intent.makeMainSelectorActivity(intent.ACTION_MAIN, 
 "android.intent.category.APP_MUSIC");
  startActivity(intent);

回答1:

This solution might help someone looking to launch default Music Player:

if(android.os.Build.VERSION.SDK_INT>=15){        
    Intent intent=Intent.makeMainSelectorActivity(Intent.ACTION_MAIN,
    Intent.CATEGORY_APP_MUSIC);
    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);//Min SDK 15
    startActivity(intent);
}else{
    Intent intent = new Intent("android.intent.action.MUSIC_PLAYER");//Min SDK 8
    startActivity(intent);
}


回答2:

Used below code :

Uri uri = Uri.withAppendedPath(MediaStore.Audio.Media.INTERNAL_CONTENT_URI, "1");   
Intent it = new Intent(Intent.ACTION_VIEW, uri);   
startActivity(it);

or

Intent intent = new Intent("android.intent.action.MUSIC_PLAYER");
startActivity(intent);

Ans also prefer url :

Launching the default music player