Android call system sharing feature realizes sharing to SMS, mail and other

Source: Internet
Author: User

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

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.