How do i launch the music player

2019-07-30 12:29发布

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);

2条回答
SAY GOODBYE
2楼-- · 2019-07-30 13:04

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

查看更多
可以哭但决不认输i
3楼-- · 2019-07-30 13:08

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);
}
查看更多
登录 后发表回答