检查 Android 上是否安装了视频播放器

Check for installed video Player on Android

我有一个使用 VideoView 和 MediaController 类 播放 MP4 视频的应用程序。

我希望在我的应用程序中添加对外部视频播放器的支持。我想做的是显示播放器列表并允许用户选择其中之一或继续使用内部应用程序播放器。

要显示我使用此代码的玩家列表:

Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(Uri.parse(f.getFileName()), "video/*");
startActivity(Intent.createChooser(intent, "Choose player"));

但我不知道如何让用户在不想使用其中之一的情况下继续使用我的应用程序。

我该如何选择?

罗伯托

请从以下link中检查'Example implicit intent'和'Forcing an app chooser':http://developer.android.com/guide/components/intents-filters.html

您可以使用

建立自己的列表
final Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(Uri.parse(f.getFileName()), "video/*");

final List<ResolveInfo> appList = context.getPackageManager().queryIntentActivities(intent , PackageManager.PERMISSION_GRANTED);

您可以通过以下方式获取每个项目的更多信息:

for (ResolveInfo resolveInfo : appList ) {


            try {
                ApplicationInfo ai =context.getPackageManager().getApplicationInfo(resolveInfo.activityInfo.packageName, 0);
                // your code here
            } catch (NameNotFoundException e) {
                e.printStackTrace();
            }
        }

要启动仅查找应用程序,在您的情况下,您可以使用:

// for your list you must remember Package name for each item
pn = resolveInfo.activityInfo.packageName;

//after user make selection, get selected PackageName and start desired app with your data.
Intent IntentLaunch = context.getPackageManager().getLaunchIntentForPackage(pn);
IntentLaunch.setAction(Intent.ACTION_VIEW);
IntentLaunch.setDataAndType(Uri.parse(f.getFileName()), "video/*");
IntentLaunch.setData(mData /* data that you want to pass to app*/);
startActivity(IntentLaunch);