0

I try to use ShareActionProvider (support.v7) to perform sharing for my app. All apps, such as Gmail, Evernote, et. al, work fine - except Facebook. I don't know what the problem is. Here is my code snipet:

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.share, menu);
    MenuItem shareItem = menu.findItem(R.id.action_share);
     mShareActionProvider = (ShareActionProvider) MenuItemCompat.getActionProvider(shareItem);
    mShareActionProvider.setShareIntent(shareIntent());

    return true;
}

public Intent shareIntent () {
    Intent shareIntent = new Intent(Intent.ACTION_SEND);
    shareIntent.setType("type/plain");
    shareIntent.setType("image/*");
    shareIntent.putExtra(Intent.EXTRA_SUBJECT,"SUBJECT");
    shareIntent.putExtra(Intent.EXTRA_TEXT,"TEXT TEXT");
    return shareIntent;
}
Adam Link
  • 2,783
  • 4
  • 30
  • 44
user2761885
  • 327
  • 1
  • 7
  • 13

1 Answers1

4

First, do not call setType() twice, as the second one will replace the first one.

Second, type/plain is not a valid MIME type. Try text/plain.

Third, if you are going to use image/*, you need to use EXTRA_STREAM to provide the image.

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
  • thanks very much, you save me an hour!! About sharing a image to facebook, can I use an external link like "http://www.abc.com/abc.png"? – user2761885 Sep 21 '13 at 15:01
  • 1
    @user2761885: Usually sharing is for local content. I cannot speak to whether Facebook supports sharing of links this way. – CommonsWare Sep 21 '13 at 15:47