Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <h1>Solution 1: Launch ACTION_SEND Intent</h1> <p>When launching a SEND intent, you should usually wrap it in a chooser (through <a href="http://developer.android.com/reference/android/content/Intent.html#createChooser(android.content.Intent,%20java.lang.CharSequence)">createChooser(Intent, CharSequence)</a>), which will give the proper interface for the user to pick how to send your data and allow you to specify a prompt indicating what they are doing.</p> <pre><code>Intent intent = new Intent(); intent.setAction(Intent.ACTION_SEND); # change the type of data you need to share, # for image use "image/*" intent.setType("text/plain"); intent.putExtra(Intent.EXTRA_TEXT, URL_TO_SHARE); startActivity(Intent.createChooser(intent, "Share")); </code></pre> <h1>Solution 2: Use ShareActionProvider</h1> <p>If you are just looking to add a Share button in Overflow Menu, also have a look at <a href="http://developer.android.com/reference/android/widget/ShareActionProvider.html">ShareActionProvider</a>.</p> <pre><code>public boolean onCreateOptionsMenu(Menu menu) { getMenuInflater().inflate(R.menu.share, menu); MenuItem item = menu.findItem(R.id.share_item); actionProvider = (ShareActionProvider) item.getActionProvider(); // Create the share Intent String shareText = URL_TO_SHARE; Intent shareIntent = ShareCompat.IntentBuilder.from(this) .setType("text/plain").setText(shareText).getIntent(); actionProvider.setShareIntent(shareIntent); return true; } </code></pre> <p>Hope this helps. :)</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload