如何获得安装媒体播放器的列表 [英] How to get a list of installed media players

查看:127
本文介绍了如何获得安装媒体播放器的列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的应用程序我有,我想开了用户的preferred媒体播放器,只热衷于音频菜单项。理想情况下,用户第一次选择这个项目会选择在手机上唯一的媒体播放器,如果他们只有一个安装,或与列表present他们,如果他们有一个以上的。然后我会自己选择,以便在下一次保存关闭它会打开一个。

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.

据我所知,Android有没有默认媒体播放器。我有原来的Droid,它有一个媒体播放器,但我知道其他运营商使用自己的,或者用户可以卸载的标准之一。

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.

我想这code,这是应该得到支持的意图包的列表。它适用于一些东西,如应用程序/ PDF格式和视频/ *。当我尝试用音频/ *我得到一个空列表,即使我有两个股票Android的媒体播放器和MixZing安装。曾经也试图与媒体/ *,并获得什么。

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);

我已经看到了这code的工作,然后打开与默认播放器的音频文件,但是我不想打开一个文件,我只是想打开音频应用程序,如果用户从打开了它应用程序抽屉中。

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); 

唯一的其他东西我能想到要做的就是走出去,并得到了最流行的媒体播放器和硬盘code它们的软件包名称和搜索手机查看安装了哪些,但这并不似乎是最好的办法。我不明白为什么code中的第一位是行不通的。也许意图过滤器没有正确设置这些应用程序或我使用了错误的code或MIME类型。

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.

推荐答案

确定这里是我问的操作系统已安装的音频播放器的列表。

OK here is how I ask the OS for a list of installed audio players.

Intent intent = new Intent(Intent.ACTION_VIEW);
Uri uri = Uri.withAppendedPath(MediaStore.Audio.Media.INTERNAL_CONTENT_URI,"1"); 
intent.setData(uri);
List<ResolveInfo> playerList;
playerList = packageManager.queryIntentActivities(intent, 0);

playerList将被填充ResolveInfo对象为自称处理音频在手机上每一个应用程序。从ResolveInfo你可以得到的东西像包的名称以启动活动中,你可以得到的图标和应用程序名称。我用它来填充一个自定义对话框的外观和行为像选择一个活动,推出股票Android的对话框。我还可以选择为用户设置所选择的应用程序的默认设置。

playerList will then be populated with ResolveInfo objects for every app on the phone that claims to handle audio. From the ResolveInfo you can get things like package name to launch the activity, you can get icons and app names. I use it to populate a custom dialog that looks and acts like the stock Android dialog for choosing an activity to launch. I also have the option for the user to set the chosen app as default.

这是不完美的。你是在操作系统和应用程序的意图过滤器的摆布。我曾试图与几部电话和下面的应用程序正确显示:库存媒体播放器原有的Droid,股票媒体播放器HTC手机,DoubleTwist的和MixZing。不过,我安装Zimly,并没有显示出来。我怀疑他们的意图过滤器没有设置为音频。

This isn't perfect. You are at the mercy of the OS and the app's intent filters. I have tried this with a few phones and the following apps show up properly: Stock media player for original Droid, stock media player for HTC phones, doubleTwist and MixZing. However, I installed Zimly and it does not show up. I suspect their intent filters aren't set up for audio.

我也担心可能存在这样的情况:MediaStore.Audio.Media.INTERNAL_CONTENT_URI没有任何音讯。我曾尝试code重新启动后立即和它的作品。我还没有尝试过在手机上没有安装用户媒体。

I was also worried there may be cases when MediaStore.Audio.Media.INTERNAL_CONTENT_URI does not have any audio. I have tried this code immediately following a reboot and it works. I have not tried it on a phone with no user media installed.

这篇关于如何获得安装媒体播放器的列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆