以下代码适用于任何安卓设备(api 8),但不适用于三星>= S3 (找不到音乐播放器)。
try {
String name;
try {
name = (String) MediaStore.class.getDeclaredField("INTENT_ACTION_MUSIC_PLAYER").get(null);
} catch(Exception e) {
name = (String) Intent.class.getDeclaredField("CATEGORY_APP_MUSIC").get(null);
}
startActivity(new Intent(name));
} catch(Exception e) {
// music player not found
}
三星的构造层是什么呢?有没有人有办法在Galaxy S3上打开媒体播放器?
作为更新,我已经改变了我的错误,但我仍然无法在Galaxy S3上获得mediaplayer:
try {
try {
// 8 <= API < 15
String action = (String) MediaStore.class.getDeclaredField("INTENT_ACTION_MUSIC_PLAYER").get(null);
Intent intent = new Intent(action);
startActivity(intent);
} catch(Exception e) {
// 15 <= API
String category = (String) Intent.class.getDeclaredField("CATEGORY_APP_MUSIC").get(null);
Method method = Intent.class.getMethod("makeMainSelectorActivity", String.class, String.class);
Intent intent = (Intent) method.invoke(null, Intent.ACTION_MAIN, category);
startActivity(intent);
}
catch(Exception e) {
// music player not found
}
发布于 2012-09-21 22:55:51
CATEGORY_APP_MUSIC是一个类别。直接在这上面打开一个意图是行不通的。
根据文档:
公共静态最终字符串CATEGORY_APP_MUSIC
自: API级别15与ACTION_MAIN一起使用以启动音乐应用程序。该活动应能够播放、浏览或操作存储在设备上的音乐文件。
注意:这不应该用作意图的主键,因为它不会导致应用程序启动时具有正确的操作和类别。取而代之的是,将其与makeMainSelectorActivity(String,String)一起使用,以在选择器中生成具有此类别的主意图
您需要使用action MAIN打开它,并将类别设置为CATEGORY_APP_MUSIC
https://stackoverflow.com/questions/12532207
复制相似问题