I've an app which uses the VideoView and MediaController classes to play MP4's videos.
I wish to add to my app the support for external video players. What I wish to do is to show the list of players and allow the users to choose one of them or to continue using the internal app player.
To show the list of players I use this code:
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(Uri.parse(f.getFileName()), "video/*");
startActivity(Intent.createChooser(intent, "Choose player"));
but I don't know how to allow the user to continue with my app if him don't want to use one of them.
How can i do this selection?
Roberto
You can build your own list using
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);
you can get more info for each item with:
for (ResolveInfo resolveInfo : appList ) {
try {
ApplicationInfo ai =context.getPackageManager().getApplicationInfo(resolveInfo.activityInfo.packageName, 0);
// your code here
} catch (NameNotFoundException e) {
e.printStackTrace();
}
}
To launch just find app, in your case you can use :
// 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);