P H
P H

Reputation: 45

Android custom Intent chooser to list Activities

I'm trying to make a custom Intent chooser for the ACTION_SEND

PackageManager pm = getApplicationContext().getPackageManager();

Intent shareIntent = new Intent(android.content.Intent.ACTION_SEND)
    .setType("application/octet-stream");

List<Intent> targetedShareIntents = new ArrayList<Intent>();
List<ResolveInfo> resInfo = pm.queryIntentActivities(shareIntent, 0);
Collections.sort(resInfo, new ResolveInfo.DisplayNameComparator(pm));

for (ResolveInfo resolveInfo : resInfo) {
   String packageName = resolveInfo.activityInfo.packageName;
   Intent targetedShareIntent = new Intent(android.content.Intent.ACTION_SEND)
      .setType("application/octet-stream")
      .setPackage(packageName);
   targetedShareIntents.add(targetedShareIntent);
}
Intent chooserIntent = Intent.createChooser(targetedShareIntents.remove(0), "Title");
chooserIntent.putExtra( Intent.EXTRA_INITIAL_INTENTS, targetedShareIntents.toArray(new Parcelable[]{}));
startActivity(chooserIntent);

the problem is that for applications that have multiple activities with the same action (Like ES File Explorer), it is listed multiple times as "Android System" Like in Figure 1. https://i.sstatic.net/kxy2A.jpg

and then if selected it gives you the standard Intent chooser associated with that application Like in Figure 2.

The Question: how can I implement a custom Intent chooser like the build-in one, where each Activity is listed together. like in Figure 3.

Upvotes: 0

Views: 1154

Answers (1)

greenapps
greenapps

Reputation: 11224

Found something to get rid of the "Android-system" text and now its displaying "ES File Explorer" instead. And an es file explorer icon. I had added these log statements:

Log.d(TAG, packageName );
Log.d(TAG, resolveInfo.activityInfo.name );

and the result for ES File Explores was:

 com.estrongs.android.pop
 com.estrongs.android.pop.app.ESFileSharingActivity
 com.estrongs.android.pop
 com.estrongs.android.pop.app.SaveToESActivity

then i added following statement in the loop:

 targetedShareIntent.setClassName(packageName, resolveInfo.activityInfo.name);

So now you will see twice ES File Explorer. But unlucky twice the same info. And the same icon.

Think you should mail the guys of es file explorer a link to this post. They are helpfull. They will be interested.

Upvotes: 1

Related Questions