Created
May 7, 2013 13:29
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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