add only specific apps to shareactionprovider

882 Views Asked by At

ShareActionProvider provides share for every compatible app on the device. I would like to specify which apps I want to allow sharing, like only twitter and gmail for example.

How would I do this?

2

There are 2 best solutions below

2
On BEST ANSWER

Google don't recommend that you share to specific apps as there are various different Twitter clients - it's better to just let people chose where they want to share it.

However, the following code will send the message "hello twitter" to twitter on a button press.

String message = "hello Twitter";

try {
    //try to open the official twitter app
    Intent sharingIntent = new Intent(Intent.ACTION_SEND);
    sharingIntent.setType("text/plain");
    sharingIntent.putExtra(
            android.content.Intent.EXTRA_SUBJECT, "Subject");
    sharingIntent.putExtra(Intent.EXTRA_TEXT, message);
    sharingIntent.setPackage("com.twitter.android");
    startActivity(sharingIntent);

} catch (Exception e) {
    //fallback on opening an internet browser
    Log.e("Danielle", "exception=" + e.toString());
    Intent i = new Intent();
    i.putExtra(Intent.EXTRA_TEXT, message);
    i.setAction(Intent.ACTION_VIEW);
    i.setData(Uri
            .parse("https://mobile.twitter.com/compose/tweet"));
    startActivity(i);
}

Hope that helps.

0
On

If you are ok with just using a popup, the answer by dacoinminster in this question How to filter specific apps for ACTION_SEND intent (and set a different text for each app) will do it.

But if you specifically want it to be an actionprovider dropdown, I have not find this solution either.