In front I wrote two articles about QQ and sharing (http://blog.csdn.net/dawanganban/article/details/42015249) (http://blog.csdn.net/dawanganban/ article/details/40478317) This article we look at how to realize the microblog sharing function.
Weibo reference documents on the open platform for a long day, did not find, finally surprised to find in the SDK demo, or my old ideas, encountered this third-party access to the fastest best starting point is the entry document and the official demo, open the demo we will see the relevant documents and source code, Because the front of the AppID application and QQ, almost, so I do not repeat here, you can refer to the above two articles. Next, I will glue the source code I have encapsulated as follows:
public class sinasharemanager{/** * text */public static final int sina_share_way_text = 1;/** * Picture */public static final in T sina_share_way_pic = 2;/** * Link */public static final int sina_share_way_webpage = 3;private static String Sinaappkey;pu Blic static final String SCOPE = "Email,direct_messages_read,direct_messages_write," + "friendships _groups_read,friendships_groups_write,statuses_to_me_read, "+" follow_app_official_microblog, "+" INVITATION_WR Ite "; /** the interface instance shared by Weibo */private IWEIBOSHAREAPI Sinaapi; public void Registsina (context context) {//Get appkey if (Sinaappkey = = null) {Sinaappkey = Sinashareutil.getsinaapp Key (context); }//Initialize Weibo share code if (Sinaappkey! = null) {Initsinashare (context); }/** * Sina Weibo sharing method * @param sharecontent shared content */public void Sharebysina (sharecontent sharecontent, context context) {if ( Sinaapi = = null) Return;switch (Sharecontent.getshareway ()) {case Sina_share_way_text:sharetext (sharecontent); Break;case sina_share_way_pic:sharepicture (sharecontent, context); Break;case Sina_share_way_webpage:sharewebpage (sharecontent, context); break;}} /* * Share text */private void Sharetext (Sharecontent sharecontent) {//Initialize Weibo share message weibomessage weibomessage = new Weibomessage () ; weibomessage.mediaobject = Gettextobj (Sharecontent.getcontent ());//Initialize a message request from a third party to a microblog sendmessagetoweiborequest Request = new Sendmessagetoweiborequest (); request.transaction = Buildtransaction ("Sinatext"); request.message = weibomessage;//send request information to Weibo, evoke Weibo sharing interface sinaapi.sendrequest (request);} /* Share picture */private void SharePicture (sharecontent sharecontent, Context context) {Weibomessage weibomessage = new Weibomes Sage (); weibomessage.mediaobject = Getimageobj (Sharecontent.getpicresource (), context);// Initialize message requests from third-party to Weibo sendmessagetoweiborequest request = new Sendmessagetoweiborequest (); request.transaction = Buildtransaction ("Sinatext"); request.message = weibomessage;//sends request information to Weibo, evoking Weibo sharing interface sinaapi.sendrequest (request);} private void Sharewebpage (SHarecontent sharecontent, Context context) {Weibomessage weibomessage = new Weibomessage (); weibomessage.mediaobject = Getwebpageobj (sharecontent, context);//Initialize message requests from third parties to Weibo sendmessagetoweiborequest request = new Sendmessagetoweiborequest (); request.transaction = Buildtransaction ("Sinatext"); request.message = weiboMessage;// Send request information to Weibo, evoke Weibo sharing interface sinaapi.sendrequest (request);} /** * Welcome attention-Sunshine Cockroach-http://blog.csdn.net/dawanganban * @author Lixiaoqiang * */private abstract class sharecontent{protected abstract int Getshareway ();p rotected abstract String getcontent ();p rotected abstract String getTitle ();p rotected Abstract String GetURL ();p rotected abstract int getpicresource ();} /** * Set the content of shared text * @author Administrator * */public class Sharecontenttext extends Sharecontent{private String content;/** * Constructs the shared text class * @param text sharing content */public Sharecontenttext (String content) {this.content = content;} @Overrideprotected String getcontent () {return content;} @Overrideprotected String GetTitle () {return null;} @Overrideprotected String GetURL () {return null;} @Overrideprotected int Getpicresource () {return-1;} @Overrideprotected int Getshareway () {return sina_share_way_text;}} /** * Set contents of shared images * @author Administrator * */public class Sharecontentpic extends sharecontent{private int Picresource;publ IC sharecontentpic (int picresource) {this.picresource = Picresource;} @Overrideprotected String getcontent () {return null;} @Overrideprotected String GetTitle () {return null;} @Overrideprotected String GetURL () {return null;} @Overrideprotected int Getpicresource () {return picresource;} @Overrideprotected int Getshareway () {return sina_share_way_pic;}} /** * Set the content of the share link * @author Administrator * */public class Sharecontentwebpage extends Sharecontent{private String title;pri Vate string content;private string url;private int picresource;public sharecontentwebpage (string title, string content, S Tring URL, int picresource) {this.title = Title;this.content = Content;this.url = Url;this.picresource = PicResource;} @Overrideprotected String getcontent () {return content;} @Overrideprotected String GetTitle () {return title;} @Overrideprotected String GetURL () {return URL;} @Overrideprotected int Getpicresource () {return picresource;} @Overrideprotected int Getshareway () {return sina_share_way_webpage;}} /** * Create a text message object. * * @return Text Message object. */Private Textobject gettextobj (String text) {Textobject textobject = new Textobject (); Textobject.text = text; return textobject; } private Imageobject getimageobj (int picresource, context context) {Imageobject imageobject = new Imageobject ( ); Bitmap bmp = Bitmapfactory.decoderesource (Context.getresources (), Picresource); Imageobject.setimageobject (BMP); return imageobject; } private Webpageobject Getwebpageobj (sharecontent sharecontent, Context context) {Webpageobject Mediaobject = n EW Webpageobject (); Mediaobject.identify = Utility.generateguid (); Mediaobject.titlE = Sharecontent.gettitle (); Mediaobject.description = Sharecontent.getcontent (); Set the Bitmap type of picture into the video object Bitmap BMP = Bitmapfactory.decoderesource (Context.getresources (), Sharecontent.getpicresou Rce ()); Mediaobject.setthumbimage (BMP); Mediaobject.actionurl = Sharecontent.geturl (); Mediaobject.defaulttext = Sharecontent.getcontent (); return mediaobject; }private void Initsinashare (Context context) {//Create a microblog SDK interface instance Sinaapi = Weibosharesdk.createweiboapi (Context, SINAA Ppkey); Check version support status Checksinaversin (context); Sinaapi.registerapp ();} private void Checksinaversin (final context context) {//Get information about Weibo clients, such as whether to install, support version of SDK, Boolean Isinstalledweibo = Sin Aapi.isweiboappinstalled (); int supportapilevel = Sinaapi.getweiboappsupportapi (); If the Weibo client is not installed, set the callback if (!isinstalledweibo) {Sinaapi.registerweibodownloadlistener (new Iweibodownlo) for the download microblog. Adlistener () { @Override public void OnCancel () {Toast.maketext (context, "Cancel Download", Toast.length_short). Show (); } }); }}private string buildtransaction (final string type) {return (type = = null)? String.valueof (System.currenttimemillis ()): Type + System.currenttimemillis ();}}If in doubt can put forward or add blog next to the QQ group to exchange, I hope these three articles to help you.
Android for Weibo sharing and considerations