This following code works on any android device (api >= 8) but not on Samsung Galaxy S3 (music player not found).
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
}
Samsung constructor layer is something to it? Does anyone have a solution to open the media player on a Galaxy S3?
As an update, I have changed my mistake but I still no get mediaplayer on 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
}
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…