pivu0
pivu0

Reputation: 138

one explicit Intent for a list of activities

A implicit intent will present a list of Apps to the user when several apps meets the action. The user then chooses an this app is launched.

However, if you have a list of packagenames (or/and classname) is the same possible for explicit intent? Something like (does not work this way, but this is what I want):

Intent i = new Intent().setClassName(ListofPackagenames, ListofClassnames)
startActivity(i);

With ListofPackagenames a (Array)List of packagenames and ListofClassnames an (Array)List of classnames. With startActivity, a dialog should be presented much like when you want to start an implicit intent.

If this is not possible, ofcourse I can make a costum dialog. Is there then a way, only from the packagename or classname, to get appicon?

Upvotes: 0

Views: 102

Answers (1)

isma3l
isma3l

Reputation: 3853

You can use PackageManager to get the launch activity and create a chooser intent with EXTRA_INITIAL_INTENTS. Something like:

List<String> listofPackageNames=....
List<Intent> intentList=new ArrayList<Intent>();
PackageManager pm = getPackageManager();
for(String packageName:listofPackageNames){
    intentList.add(pm.getLaunchIntentForPackage(packageName));
}
Intent[] intents=new Intent[intentList.size()];
intents=intentList.toArray(intents);
Intent chooser=Intent.createChooser(intents[0],"Choose ...");
chooser.putExtra(Intent.EXTRA_INITIAL_INTENTS,Arrays.copyOfRange(intents,1,intents.length));
startActivity(chooser);

Upvotes: 1

Related Questions