Previously wrote an article using friends and other third parties to achieve sharing, Weibo and watercress and other third-party social networking sites. This time we use the system comes with the sharing function to do, although simple, but for the former like Friends of the Alliance and other third-party social sharing components have not done mature time, is also a good choice. So here directly on the code to the system share to make a record, the code is necessary to comment, so do not do what the explanation:
/** * Pop-up share list */private void Showsharedialog () {Alertdialog.builder Builder = new Alertdialog.builder (thread_conte Nt_activity.this); Builder.settitle ("Select share Type"); Builder.setitems (New string[]{"Mail", "SMS", "Other"}, new Dialoginterface.onclicklistener () {@Overridepublic void OnClick ( Dialoginterface dialog, int which) {//TODO auto-generated method Stubdialog.dismiss (); switch (which) {Case 0://mail Sendmai L ("http://www.google.com.hk/"); break;case 1://SMS Sendsms ("http://www.google.com.hk/"); break;case 3://call system Share Intent Intent=new Intent (Intent.action_send); Intent.settype ("Text/plain"); Intent.putextra (Intent.extra_subject, "sharing"); Intent.putextra (Intent.extra_text, "I am browsing this, feel really good, recommend to you OH ~ Address:" + "http://www.google.com.hk/"); Intent.setflags ( Intent.flag_activity_new_task); StartActivity (Intent.createchooser (Intent, "share")); break;default:break;}}); Builder.setnegativebutton ("Cancel", new Dialoginterface.onclicklistener () {@Override public void OnClick (DialoginterFace dialog, int which) {Dialog.dismiss (); } }); Builder.create (). Show (); /** * Send mail * @param emailbody */private void SendMail (String emailurl) {Intent email = new Intent (android.conte Nt. Intent.action_send); Email.settype ("Plain/text"); String emailbody = "I am browsing this, feel really good, recommend to you OH ~ Address:" + emailurl;//Mail subject Email.putextra (Android.content.Intent.EXTRA_SUBJECT, SUBJECTSTR);//mail Content Email.putextra (Android.content.Intent.EXTRA_TEXT, emailbody); Startactivityforresult (Email, "Please select email content"), 1001); /** * Text message */private void Sendsms (String webUrl) {string smsbody = "I am looking at this, I feel really good, recommend to you OH ~ Address:" + we BURL; Uri Smstouri = Uri.parse ("Smsto:"); Intent sendintent = new Intent (Intent.action_view, Smstouri); Sendintent.putextra ("Address", "123456"); Phone number, this line is removed, the default is no phone//SMS Content Sendintent.putextra ("Sms_body", smsbody); Sendintent.settype ("vnd.android-dir/mms-sms"); StartaCtivityforresult (Sendintent, 1002); }
Android call system sharing feature realizes sharing to SMS, mail and other