Skip to content

Instantly share code, notes, and snippets.

@aegis123
Created May 7, 2013 13:29
Show Gist options
  • Save aegis123/5532563 to your computer and use it in GitHub Desktop.
Save aegis123/5532563 to your computer and use it in GitHub Desktop.
create a share intent with ShareActionProvider and text/plain to share something on android
@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
super.onCreateOptionsMenu(menu, inflater);
MenuItem actionItem = menu.findItem(R.id.menu_item_share);
ShareActionProvider actionProvider = (ShareActionProvider) actionItem.getActionProvider();
actionProvider.setShareHistoryFileName(ShareActionProvider.DEFAULT_SHARE_HISTORY_FILE_NAME);
// Note that you can set/change the intent any time,
// say when the user has selected an image.
actionProvider.setShareIntent(createShareIntent());
}
private Intent createShareIntent() {
Intent shareIntent = new Intent(Intent.ACTION_SEND);
shareIntent.putExtra(
Intent.EXTRA_TEXT,
getSherlockActivity().getString(R.string.share_text,
getSherlockActivity().getString(R.string.share_url)
)
);
shareIntent.putExtra(
Intent.EXTRA_SUBJECT,
getSherlockActivity().getString(R.string.share_subject)
);
shareIntent.setType("text/plain");
return shareIntent;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment