以下代码适用于任何 android 设备(api >= 8),但不适用于三星 Galaxy 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 上获得媒体播放器:
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
}