/** * Call system sharing function * Created by admin on 15-4-13. */public class Shareactivity extends Activity {@Override protected void onCreate (Bundle savedinstancestate) { Super.oncreate (savedinstancestate); Setcontentview (r.layout.share_layout); }//share text public void Sharetext (view view) {Intent shareintent = new Intent (); Shareintent.setaction (Intent.action_send); Shareintent.putextra (Intent.extra_text, "This is my Share TEXT."); Shareintent.settype ("Text/plain"); Set the title of the share list and show the Share list startactivity (Intent.createchooser (Shareintent, "share to") each time; }//share a single picture public void Sharesingleimage (view view) {String ImagePath = Environment.getexternalstoragedirecto Ry () + file.separator + "test.jpg"; The URI uri Imageuri = uri.fromfile (new file) is obtained by the file (ImagePath); LOG.D ("Share", "uri:" + Imageuri); Output: file:///storage/emulated/0/test.jpg Intent shareintent = new Intent (); Shareintent.setaction (Intent.action_send); Shareintent.putextra (Intent.extra_stream, Imageuri); Shareintent.settype ("image/*"); StartActivity (Intent.createchooser (Shareintent, "share to")); }//share multiple pictures public void sharemultipleimage (view view) {ArrayList 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 shareintent = new Intent (); Shareintent.setaction (intent.action_send_multiple); Shareintent.putparcelablearraylistextra (Intent.extra_stream, urilist); Shareintent.settype ("image/*"); StartActivity (Intent.createchooser (Shareintent, "share to")); }}
To invoke the sharing function of the system