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;
}
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.