Android: Call the system sharing function. android calls

Source: Internet
Author: User

Android: Call the system sharing function. android calls

Sample Code:

/*** Call the system sharing Function * Created by admin on 15-4-13. */public class extends Activity {@ Override protected void onCreate (Bundle savedInstanceState) {super. onCreate (savedInstanceState); setContentView (R. layout. pai_layout);} // share the text public void shareText (View view) {Intent = new Intent (); Intent. setAction (Intent. ACTION_SEND); Specify intent. putExtra (Intent. EXTRA_TEXT, "This is my Share text. "); specifies intent. setType ("text/plain"); // set the title of the share list, and the share list startActivity (Intent. createChooser (shareIntent, "share to");} // share a single image public void shareSingleImage (View view) {String imagePath = Environment. getExternalStorageDirectory () + File. separator + "test.jpg"; // uri Uri imageUri = Uri from the file. fromFile (new File (imagePath); Log. d ("share", "uri:" + imageUri); // output: file: // storage/emulated/0/test.jpg Intent specify Intent = new Intent (); Specify Intent. setAction (Intent. ACTION_SEND); Specify intent. putExtra (Intent. EXTRA_STREAM, imageUri); Specify intent. setType ("image/*"); startActivity (Intent. createChooser (shareIntent, "share to");} // share multiple images public void shareMultipleImage (View view) {ArrayList <Uri> uriList = new ArrayList <> (); string path = Environment. getExternalStorageDirectory () + File. separator; uriList. add (Uri. fromFile (new File (path + "australia_1.jpg"); uriList. add (Uri. fromFile (new File (path + "australia_2.jpg"); uriList. add (Uri. fromFile (new File (path + "australia_3.jpg"); Intent specify Intent = new Intent (); Specify Intent. setAction (Intent. ACTION_SEND_MULTIPLE); specifies intent. putParcelableArrayListExtra (Intent. EXTRA_STREAM, uriList); Specify intent. setType ("image/*"); startActivity (Intent. createChooser (shareIntent, "share "));}}

Page effect:


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.