Below is the code for my Activity
import android.app.Activity;
import android.os.Bundle;
import android.support.v7.widget.ShareActionProvider;
The problem was that what @CommonsWare said about not using the support library ShareActionProvider and also even if i did then it also wont have worked out because when using Support Library we require Custom Prefixes for some actions like showAsAction
I had the same problem and I have found the solution:
1) You have to use:
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:bwq="http://schemas.android.com/apk/res-auto" >
<item
android:id="@+id/menu_share"
android:title="@string/menu_share"
bwq:actionProviderClass="android.support.v7.widget.ShareActionProvider"
bwq:showAsAction="always"/>
</menu>
2) and in Java
import android.support.v7.widget.ShareActionProvider;
and
// Locate MenuItem with ShareActionProvider
MenuItem item = menu.findItem(R.id.menu_share);
// Fetch and store ShareActionProvider
mShareActionProvider = (ShareActionProvider) MenuItemCompat.getActionProvider(item);