There is nothing to say about calling the sharing method of the system. Just say how to share different content for different sharing methods, and paste the Demo code. If there is a better way, you can leave a message.
/***** Shared tool class ** @ filename shareutil. java * @ author naibo-liao * @ createtime 2013-4-19 am 11:01:04 */public class shareutil {private list <resolveinfo> resinfo; private packagemanager PM; private Map <string, Boolean> nopicapps; private settingmanager msettingmanager; Private Static shareutil mshareutil; private shareutil () {msettingmanager = settingmanager. getinstance (girlapplication. getinstance (); PM = Gi Rlapplication. getinstance (). getpackagemanager (); getsharenopicapps ();} public static shareutil getinstance () {If (mshareutil = NULL) {mshareutil = new shareutil ();} return mshareutil ;} /*** get the sharing target ** @ return */public list <intent> gettargetedshareintents (string picurl) {try {string Path = fileutils. copyfile (picurl); file = new file (PATH); intent = new intent (intent. action_send); intent. sett Ype ("text/plain"); If (null = resinfo) {resinfo = PM. queryintentactivities (intent, 0);} If (! Resinfo. isempty () {list <intent> targetedincluintents = new arraylist <intent> (); For (resolveinfo info: resinfo) {intent targeted = new intent (intent. action_send);/*** the following code can be roughly understood as obtaining apps with local sharing actions, such as Weibo and others. * different content is allocated based on the package name or application name. */Activityinfo = info. activityinfo; string packagename = activityinfo. packagename; packageinfo pinfo = PM. getpackageinfo (packagename, 0); string appname = pinfo. applicationinfo. loadlabel (PM ). tostring (); If (null! = Nopicapps & nopicapps. size ()> 0) {// The application that requires special processing of shared content. The server distributes if (nopicapps. containskey (appname. touppercase () {targeted. settype ("text/plain");} else {targeted. settype ("image/*"); targeted. putextra (intent. extra_stream, Uri. fromfile (File);} else {// The application that needs to handle the shared content must be judged locally. The code is a bit redundant. Haha if (appname. contains ("") | appname. contains ("UC") {targeted. settype ("text/plain");} else {targeted. settype ("image/*"); tar Geted. putextra (intent. extra_stream, Uri. fromfile (File) ;}/// share the text information targeted. putextra (intent. extra_text, reconfigurationsharemessage (appname); // targeted. setclassname (getapplication (), classname); targeted. setpackage (packagename); targetedshareintents. add (targeted);} return targetedshareintents;} catch (exception e) {} return NULL;}/*** application for retrieving images that do not need to be shared */private void getsharenopicapps () {If (nopicapps = Null) {nopicapps = new hashmap <string, Boolean> (); If (! Textutils. isempty (msettingmanager. getsharenopicapps () {string [] strnopicapps = msettingmanager. getsharenopicapps (). split (","); For (INT I = 0; I <strnopicapps. length; I ++) {nopicapps. put (strnopicapps [I]. touppercase (), true) ;}}}/*** build shared content ** @ Param appname * @ return */private string reconfigurationsharemessage (string appname) {string message = msettingmanager. getsharemessage (); string shard URL = Msettingmanager. getresponse URL (); string encode = "frapp =" + urlencoder. encode (appname) + "& frid =" + encryptutils. encrypttomd5 (netparameters. IMEI ). substring (8, 24); If (! Textutils. isempty (signed URL) {If (signed URL. Contains ("? ") {Response url = Response URL +" & "+ encode;} else {response url = Response URL + "? "+ Encode ;}}if (message. Contains (" # response URL #}")&&! Textutils. isempty (signed URL) {return message. Replace ("{# signed URL #}", signed URL) ;}return message ;}}
List <intent> targetedshareintents = shareutil. getinstance (). gettargetedshareintents (picdetail. getpictureurl (); // the title of the Sharing box, intent chooserintent = intent. createchooser (targetedshareintents. remove (0), "share with friends"); If (chooserintent = NULL) {return;} chooserintent. putextra (intent. extra_initial_intents, targetedshareintents. toarray (New parcelable [] {}); chooserintent. setflags (intent. flag_activity_new_task); startactivity (chooserintent );