Android sharing, how to filter the specified app, and send different content to different sharing mode?

Source: Internet
Author: User

Online Find an article about: for different applications, use different ways of articles. Original Address
String contentdetails = ""; String Contentbrief= ""; String Shareurl= ""; Intent it=NewIntent (intent.action_send); It.settype ("Text/plain"); List<ResolveInfo> resinfo = Getpackagemanager (). Queryintentactivities (IT, 0); if(!Resinfo.isempty ()) {List<Intent> targetedshareintents =NewArraylist<intent>();  for(ResolveInfo info:resinfo) {Intent targeted=NewIntent (intent.action_send); Targeted.settype ("Text/plain"); Activityinfo Activityinfo=Info.activityinfo; //judgments:activityInfo.packageName, Activityinfo.name, etc.                if(ActivityInfo.packageName.contains ("bluetooth") | | activityInfo.name.contains ("bluetooth")) {                    Continue; }                if(ActivityInfo.packageName.contains ("GM") | | ActivityInfo.name.contains ("Mail") {Targeted.putextra (Intent.extra_text, contentdetails); } Else if(ActivityInfo.packageName.contains ("zxing") {Targeted.putextra (Intent.extra_text, Shareurl); } Else{Targeted.putextra (Intent.extra_text, contentbrief);                } targeted.setpackage (Activityinfo.packagename);            Targetedshareintents.add (targeted); } Intent chooserintent= Intent.createchooser (targetedshareintents.remove (0), "Select app to share"); if(Chooserintent = =NULL) {                return; }            //A parcelable[] of Intent or Labeledintent objects as set with//PutExtra (String, parcelable[]) of additional activities to place//a The front of the list of choices, when shown to the user with a//Action_chooser.Chooserintent.putextra (Intent.extra_initial_intents, Targetedshareintents.toarray (New( parcelable[] {})); Try{startactivity (chooserintent); } Catch(Android.content.ActivityNotFoundException ex) {Toast.maketext ( This, "Can ' t find share component to share", Toast.length_short). Show (); }        }

  

Android sharing, how to filter the specified app, and send different content to different sharing mode?

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.