In my app I have a menu item that I want to open up the user's preferred media player, only interested in audio. Ideally the first time the user chooses this item it would choose the only media player on the phone if they only have one installed, or present them with a list if they have more than one. I would then save off their choice so next time it would open that one.
As I understand it, Android has no default media player. I have the original Droid and it has a media player, but I understand other carriers use their own, or the user can uninstall the standard one.
I have tried a few things but can't get anything to work.
I tried this code, which is supposed to get a list of packages that support the intent. It works for some things like "application/pdf" and "video/*". When I try it with "audio/*" I get an empty list, even though I have both the stock Android media player and MixZing installed. Have also tried it with "media/*" and get nothing.
PackageManager packageManager = getPackageManager();
Intent testIntent = new Intent(Intent.ACTION_VIEW);
testIntent.setType("audio/*");
List list = packageManager.queryIntentActivities(testIntent, 0);
I have seen this code which works and opens an audio file with the default player, however I don't want to open a file, I just want to open up the audio app as if the user opened it from the application drawer.
Intent i = new Intent(Intent.ACTION_VIEW);
Uri u = Uri.withAppendedPath(MediaStore.Audio.Media.INTERNAL_CONTENT_URI,"1");
i.setData(u);
startActivity(i);
The only other thing I can think to do is go out and get the package names of the most popular media players and hard code them in and search the phone to see which ones are installed, but this doesn't seem like the best approach. I don't understand why the first bit of code doesn't work. Maybe the intent filters aren't properly set for those apps or I am using the wrong code or mime types.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…