我想点击我的音乐图标,让用户决定要使用哪个音乐播放器(如果google播放音乐或他们已经安装了另一个音乐播放器)
到目前为止,我已经做到了,但是它只是启动了默认的Google Play音乐应用
try {
Intent intent = Intent.makeMainSelectorActivity(Intent.ACTION_MAIN, Intent.CATEGORY_APP_MUSIC);
startActivity(intent);
} catch (Exception e) {
Log.d(TAG, "Exception for launching music player "+e);
}
相反,我一直在搜索所有内容,却找不到如何列出所有音乐播放器,选择一个音乐播放器并将其打开的任何想法?
这就是我要做的
答案 0 :(得分:0)
您可以为Intent设置数据类型:
public void openMusicPlayerChooser(File musicFile) {
if (Build.VERSION.SDK_INT >= 24) {
try {
Method method = StrictMode.class.getMethod("disableDeathOnFileUriExposure");
method.invoke(null);
} catch (Exception e) {
e.printStackTrace();
}
}
Intent intent = new Intent();
intent.setAction(android.content.Intent.ACTION_VIEW);
intent.setDataAndType(Uri.fromFile(musicFile), "audio/*");
startActivity(intent);
}
答案 1 :(得分:0)
这对我有用
print(affichage.solve())