我的应用程序使用VideoView和MediaController类来播放MP4的视频。
我希望在我的应用中添加对外部视频播放器的支持。我想要做的是显示播放器列表,并允许用户选择其中一个或继续使用内部应用播放器。
要显示我使用此代码的玩家列表:
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(Uri.parse(f.getFileName()), "video/*");
startActivity(Intent.createChooser(intent, "Choose player"));
但我不知道如果用户不想使用其中任何一个,如何允许用户继续使用我的应用。
我该如何做这个选择?
罗伯特
答案 0 :(得分:1)
您可以使用
建立自己的列表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);
答案 1 :(得分:0)
请检查&#39;示例隐含意图&#39;和强迫应用选择器&#39;来自以下链接:http://developer.android.com/guide/components/intents-filters.html