I've created an application which shares to facebook, twitter etc. But I want to perform **different functions** **dependent on who the user is sharing to**, for instance if the user is sharing to Facebook do one thing but if the user shares to twitter do another.

How do I do this?

My code so far is below:

```
private void ShareSub() {
    Intent i = new Intent(Intent.ACTION_SEND);
    i.setType("text/plain");
    i.putExtra(
            Intent.EXTRA_TEXT,
            "You've just shared "
                    + "Awesome");
    startActivity(i);
}

```

Further explanation of above code:

When the user presses the "*menu\_item\_share*" button in the action bar, the function above is triggered. This function then makes a box like the image below appear, which allows the user to select a particular option, e.g. Facebook or twitter. The `Intent.EXTRA_TEXT` is then shared to that particular app.

What I'm wanting is, when the user clicks for instance Facebook, a particular function is called e.g. Sharing via their (Facebook's) api etc.

![enter image description here](https://i.stack.imgur.com/6fJKim.png)

I'm not using **ShareActionProvider** like below:

```
   <item
        android:id="@+id/your_share_item"
        android:actionProviderClass="android.widget.ShareActionProvider"
        android:showAsAction="ifRoom"
        android:title="@string/share"/>

```

Instead, I've created a simple button which calls the function *ShareSub*:

```
<item
    android:id="@+id/menu_item_share"
    android:icon="@android:drawable/ic_menu_share"
    android:showAsAction="ifRoom"
    android:title="Share"/>

```

The reason I've chosen to do it this way is, I don't want the **recently shared to** button to appear, as in the image below. This is causing me problems when I attempt to use the code suggested below because I haven't used *ShareActionProvider*.

![enter image description here](https://i.stack.imgur.com/Rk9c9m.png)