title: Using Android action bar share intent
body: <p>I'm using a menu item on the action bar and I want to share my app by clicking the share icon. When I click the share icon it doesn't work. Also, I want to add text saying <code>"install this app"</code> when shared.</p>
  
  <p>Here is my code:</p>
  
  <pre><code>private ShareActionProvider mShareActionProvider;
  
  @Override
  public boolean onCreateOptionsMenu(Menu menu) {
      // Inflate the menu; this adds items to the action bar if it is present.
      getMenuInflater().inflate(R.menu.mainpage, menu);
      MenuItem item = menu.findItem(R.id.menu_item_share);
      mShareActionProvider = (ShareActionProvider) item.getActionProvider();
  
      return true;
  }
  
  private void setShareIntent(Intent shareIntent) {
      if (mShareActionProvider != null) {
          mShareActionProvider.setShareIntent(shareIntent);
      }
  }
  </code></pre>
  
  <p><strong>Mainpage.xml menu:</strong></p>
  
  <pre><code>&lt;menu xmlns:android="http://schemas.android.com/apk/res/android" &gt;
  &lt;item android:id="@+id/menu_item_share"
      android:showAsAction="ifRoom"
      android:title="Share"
      android:icon="@drawable/ic_store"
      android:actionProviderClass="android.widget.ShareActionProvider" /&gt;
  &lt;/menu&gt;
  </code></pre>