Advertisement
Guest User

Untitled

a guest
May 4th, 2016
49
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.28 KB | None | 0 0
  1. <?xml version="1.0" encoding="utf-8"?>
  2. <menu xmlns:android="http://schemas.android.com/apk/res/android"
  3. xmlns:app="http://schemas.android.com/apk/res-auto">
  4.  
  5. <item android:id="@+id/action_share"
  6. android:title="@string/share"
  7. app:showAsAction="always"
  8. app:actionProviderClass="android.support.v7.widget.ShareActionProvider"/>
  9.  
  10. <item android:id="@+id/about"
  11. android:title="@string/about"
  12. app:showAsAction="never"/>
  13.  
  14. </menu>
  15.  
  16. // Locate MenuItem with ShareActionProvider
  17. MenuItem item = menu.findItem(R.id.action_share);
  18. // Fetch and store ShareActionProvider
  19. mShareActionProvider = (ShareActionProvider) MenuItemCompat.getActionProvider(item);
  20.  
  21. return true;
  22. }
  23.  
  24. private void setShareIntent() {
  25.  
  26. Intent myShareIntent = new Intent(Intent.ACTION_SEND);
  27. myShareIntent.setType("text/plain");
  28. myShareIntent.putExtra(Intent.EXTRA_TEXT, "some text");
  29. mShareActionProvider.setShareIntent(myShareIntent);
  30. startActivity(myShareIntent);
  31.  
  32. }
  33.  
  34. @Override
  35. public boolean onOptionsItemSelected(MenuItem item) {
  36. // Handle item selection
  37. switch (item.getItemId()) {
  38. case R.id.action_share:
  39. setShareIntent();
  40. break;
  41. ....
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement