1

I want to share my application via Facebook, Twitter, email, and messaging. I do not want to share it with the other options that are presented when using the share button.

I am currently using the following code for the share button:

sharebuton.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View v) {
        // TODO Auto-generated method stub
        String TEXT = "I shared the file " + " via MyApp";
        Intent sendIntent = new Intent(Intent.ACTION_SEND);
        sendIntent.setType("text/plain");
        sendIntent.putExtra(Intent.EXTRA_TEXT, TEXT);
        startActivity(Intent.createChooser(sendIntent, "Share the program:"));
    }
});

When using this code the user is presented with other options to share the application like Gmail, Notepad, Peep, Bluetooth, etc. as well as the four options mentioned above.

Is it possible to filter the share options so that only the four options (Facebook, Twitter, email, and messaging) are presented to the user?

Dipak Keshariya
  • 22,193
  • 18
  • 76
  • 128
Sriraman Ranjan
  • 79
  • 2
  • 10

2 Answers2

1

Not sure if you're still looking for an answer but I recently come across my own solution for exactly what you're trying to do, but the exact opposite - I wanted to create a custom list of applications the user could share with by excluding Facebook. You'll need to know the package names of those apps you wish to exclude/include. Here's my code which basically takes a list of available packages registered to handle the ACTION_SEND command and then you can choose which items in the list you want to display.

    List<Intent> targetedShareIntents = new ArrayList<Intent>();
    Intent intent = new Intent(Intent.ACTION_SEND);
    intent.setType("image/jpeg");
    List<ResolveInfo> resInfo = getPackageManager().queryIntentActivities(intent, 0);
    if (!resInfo.isEmpty()) {
        for (ResolveInfo resolveInfo : resInfo) {
            String packageName = resolveInfo.activityInfo.packageName;
            Intent targetedShareIntent = new Intent(android.content.Intent.ACTION_SEND);
            targetedShareIntent.setType("image/jpeg");
            targetedShareIntent.putExtra(Intent.EXTRA_TITLE, "Title string");
            targetedShareIntent.putExtra(Intent.EXTRA_SUBJECT, "Subject string");
            if ("com.facebook.katana".equals(packageName) || "com.facebook.orca".equals(packageName)) {
                    // don't add Facebook or Facebook messenger app to list
                continue;
            } else {
                targetedShareIntent.putExtra(Intent.EXTRA_TEXT, bodyStr);
            }
            targetedShareIntent.setPackage(packageName);
            targetedShareIntents.add(targetedShareIntent);
        }
        Intent chooserIntent = Intent.createChooser(targetedShareIntents.remove(0), getString(R.string.results_share_title));
        chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, targetedShareIntents.toArray(new Parcelable[]{}));
        startActivity(chooserIntent);
    }
pilcrowpipe
  • 2,528
  • 6
  • 29
  • 41
  • By the way if you have working code that shares you're application, dynamic text, icon and http link with Facebook I'd love to see it... that's the current problem I'm facing elsewhere ;-) – pilcrowpipe Jan 21 '12 at 02:36
0

Try this.

If you want to share application via Facebook, twitter, email and messaging.

For doing so you need to make a layout in which you will have to give options where you want to share. You can make set of buttons for these.

Then on click on button then you need to handle action for each button like email you need to open email app and for facebook you need to open facebook same as for others.

Bill the Lizard
  • 398,270
  • 210
  • 566
  • 880
Ajay S
  • 48,003
  • 27
  • 91
  • 111