3
String message = "Text I want to share";
Intent share = new Intent(Intent.ACTION_SEND);
share.setType("text/plain");
share.putExtra(Intent.EXTRA_TEXT, message);
startActivity(Intent.createChooser(share,"Share on"));

right now it shows the default options like: Bluetooth, Email, Facebook, Gmail, LinkedIn, Messaging, Share Via Barcode.

or are these the installed apps?

what i want is to know, how i can remove few from this list. like i want to remove Share Via Barcode.

and add something else?

Thank You

Archie.bpgc
  • 23,812
  • 38
  • 150
  • 226

3 Answers3

8

Use below code to add a new Item to the Chooser Screen.

Intent share = new Intent(Intent.ACTION_SEND);
share.setType("text/plain");       
share.putExtra(Intent.EXTRA_TEXT, message);

Intent addIntent = ;//whatever you want

Intent chooser = new Intent(Intent.ACTION_CHOOSER);
chooser.putExtra(Intent.EXTRA_INTENT, share );      
chooser.putExtra(Intent.EXTRA_TITLE, "title");

Intent[] intentArray =  {addIntent }; 
chooser.putExtra(Intent.EXTRA_INITIAL_INTENTS, intentArray);
startActivity(chooser);

But removing specific items is not possible. So you could resolve the intent using Packagemanager.resolveActivity and create your own custom list view

nandeesh
  • 24,740
  • 6
  • 69
  • 79
  • i mean you didn't add this in the code: "chooser.putExtra(Intent.EXTRA_TEXT, message);" i just want to know whether you forgot or that its no possible this way – Archie.bpgc Aug 24 '12 at 12:24
  • no it needs to be in the share intent. share.putExtra(Intent.EXTRA_TEXT, message); and not in the chooser – nandeesh Aug 24 '12 at 12:25
  • fine. thanks a lot. so i get i better use a custom submenu to have just what all options i want. But how can i get the implementation? – Archie.bpgc Aug 24 '12 at 12:26
  • i mean like, in the submenu i want to add messaging and something else. how can i make messaging work just like the one i am getting right now? – Archie.bpgc Aug 24 '12 at 12:27
  • You could actually use chooser also, you can pass a long list of all intents in intentArray in the code i pasted – nandeesh Aug 24 '12 at 12:28
  • let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/15761/discussion-between-nandeesh-and-archie-bpgc) – nandeesh Aug 24 '12 at 12:31
3

I used the following code to get a list of all eMail and SMS apps installed on the device:

Intent shareSMS = new Intent(Intent.ACTION_SENDTO, Uri.fromParts("smsto", "12346556", null));
shareSMS.addCategory(Intent.CATEGORY_DEFAULT);
shareSMS.putExtra("sms_body", message);

Intent shareEmail = new Intent(Intent.ACTION_SENDTO, Uri.fromParts("mailto", "", null));
PackageManager pm = getPackageManager();
List<ResolveInfo> mailActivityList = pm.queryIntentActivities(shareEmail, PackageManager.MATCH_DEFAULT_ONLY);

List<Intent> mailIntents = new ArrayList<Intent>();
for (ResolveInfo resInfo : mailActivityList) {
    Intent targetedOpenIntent = new Intent(android.content.Intent.ACTION_SENDTO, Uri.fromParts("mailto", "", null))
            .setPackage(resInfo.activityInfo.packageName)
            .putExtra(Intent.EXTRA_EMAIL, emails)
            .putExtra(Intent.EXTRA_SUBJECT, subject)
            .putExtra(Intent.EXTRA_TEXT, message);
    mailIntents.add(targetedOpenIntent);
}

Intent chooser = new Intent(Intent.ACTION_CHOOSER);
chooser.putExtra(Intent.EXTRA_INTENT, shareSMS);
chooser.putExtra(Intent.EXTRA_TITLE, "Send request");
chooser.putExtra(Intent.EXTRA_INITIAL_INTENTS, mailIntents.toArray(new Parcelable[] { }));

startActivity(chooser);
JBernhardt
  • 414
  • 3
  • 7
0

Adding Option to chooser

            Intent share = new Intent(Intent.ACTION_SEND);
            share.setType("text/plain");       
            share.putExtra(Intent.EXTRA_TEXT, message);

            Intent extraOptionToAdd = new Intent(this, ExtraOptionActivity.class);
            extraOptionToAdd.putExtra(Intent.EXTRA_TEXT, "Text");
            LabeledIntent labeledExtraOption = new LabeledIntent(extraOptionToAdd, getPackageName(), "Extra Option!", 0);

            Intent chooser = Intent.createChooser(share, "Share Now!");
            Intent[] intentArray =  {labeledExtraOption};
            chooser.putExtra(Intent.EXTRA_INITIAL_INTENTS, intentArray);
            startActivity(chooser);
beginner
  • 2,366
  • 4
  • 29
  • 53