Android-based QQ sharing and precautions: androidqq sharing

Source: Internet
Author: User

Android-based QQ sharing and precautions: androidqq sharing

1. Obtain APPID and help documentation

In the previous section, I introduced the article "Android implementation sharing and precautions" shared in Android to see about QQ sharing.

For more information, see guide and access for new users: http://wiki.open.qq.com/wiki/access wikiindex for mobile apps.

Share the relevant documentation Description: http://wiki.open.qq.com/index.php? Title = Android_API call description & = 45038 #1.13 _. e5.88.86.E4. BA. AB. e6.B6.88. e6.81.AF. e5.88.B0QQ. EF. BC.88.E6.97. a0.E9.9C. 80QQ. e7.99.BB. e5.BD. 95. EF. BC.89

II. Implementation Code (reproduced please note the Source: http://blog.csdn.net/dawanganban)

Public class QQShareManager {/*** link */public static final int qq_gate_way_webpage = 3;/*** QQ */public static final int qq_polic_type_talk = 1; /*** QQ space */public static final int QQ_SHARE_TYPE_ZONE = 2;/*** shared successfully */public static final int CALLBACK_CODE_SUCCESS = 0; /*** cancel sharing */public static final int CALLBACK_CODE_CANCEL = 1;/*** reject access */public static final int CALLBACK_CODE_DENY = 2;/*** unknown */Public static final int shares = 3; private static String appId; private Tencent mTencent; private QQShare qqShare; private QzoneShare qzoneShare; private QQShareResponse qqShareResponse; public void registShare (Context context Context) {// initialize data if (appId = null) {appId = QQShareUtil. getQQAppId (context);} // initialize the shared code if (appId! = Null & (qqShare = null | qzoneShare = null) {mTencent = Tencent. createInstance (appId, context); qqShare = new QQShare (context, mTencent. getQQToken (); qzoneShare = new QzoneShare (context, mTencent. getQQToken ();}/*** share qq and space * @ param shareContent share content * @ param shareType select the type (qq and space) */public void shareByQQ (Activity activity, response content contains content, int shareType) {response webpage (activity, shar EType, publish content);} private void publish webpage (Activity activity, int shareType, publish content) {Bundle params = new Bundle (); if (shareType = qq_pai_type_zone) {publish webpageqzone (activity, protected content, params);} else {protected webpageqq (activity, protected content, params);} private void protected webpageqq (Activity activity, protected content, Bundle params) {params. putString (QQShare. SHARE _ TO_QQ_TITLE, response content. getTitle (); params. putString (QQShare. pai_to_qq_summary, please content. getContent (); params. putInt (QQShare. SHARE_TO_QQ_KEY_TYPE, QQShare. pai_to_qq_type_default); params. putString (QQShare. pai_to_qq_target_url, containing content. getURL (); params. putString (QQShare. pai_to_qq_image_url, containing content. getPicUrl (); doShareToQQ (activity, params, iUiListener);} private void javaswebp AgeQzone (Activity activity, response content containing content, Bundle params) {params. putString (QzoneShare. pai_to_qq_title, invalid content. getTitle (); params. putString (QzoneShare. pai_to_qq_summary, please content. getContent (); params. putInt (QzoneShare. SHARE_TO_QZONE_KEY_TYPE, QzoneShare. pai_to_qzone_type_image_text); params. putString (QzoneShare. pai_to_qq_target_url, containing content. getURL (); ArrayList <Str Ing> imageUrls = new ArrayList <String> (); imageUrls. add (Response content. getPicUrl (); params. putStringArrayList (QzoneShare. pai_to_qq_image_url, imageUrls); // params. putString (QzoneShare. pai_to_qq_image_url, containing content. getPicUrl (); doShareToQzone (activity, params, iUiListener);} private void doShareToQQ (final Activity activity, final Bundle params, final IUiListener iUiListener) {new Thread (new Runn Able () {@ Overridepublic void run () {if (qqShare! = Null) {qqShare. shareToQQ (activity, params, iUiListener );}}}). start ();} private void doShareToQzone (final Activity activity, final Bundle params, final IUiListener iUiListener) {new Thread (new Runnable () {@ Overridepublic void run () {if (qzoneShare! = Null) {qzoneShare. shareToQzone (activity, params, iUiListener );}}}). start ();} private final IUiListener iUiListener = new IUiListener () {@ Overridepublic void onCancel () {sendRespCode (response) ;}@ Overridepublic void onComplete (Object response) {sendRespCode (CALLBACK_CODE_SUCCESS) ;}@ Overridepublic void onError (UiError e) {sendRespCode (CALLBACK_CODE_DENY);} private void sendRespCode (int code)) {If (qqShareResponse! = Null) {qqShareResponse. respCode (code) ;}}; public interface QQShareResponse {/***** share the result * @ param code result code */public void respCode (int code );} /*** feedback for registration result ** @ param qqShareResponse */public void setOnQQShareResponse (QQShareResponse qqShareResponse) {this. qqShareResponse = qqShareResponse;}/*** welcome to follow-Sunshine Xiaoqiang-http://blog.csdn.net/dawanganban * @ author lixiaoqiang **/private abstract class plain content {protected abstract int getgateway (); protected abstract String getContent (); protected abstract String getTitle (); protected abstract String getURL (); protected abstract String getPicUrl ();} /*** set the content of the Sharing link * @ author Administrator **/public class internal contentwebpage extends plain content {private String title; private String content; private String url; private String picUrl; public protected contentwebpage (String title, String content, String url, String picUrl) {this. title = title; this. content = content; this. url = url; this. picUrl = picUrl ;}@ Overrideprotected String getContent () {return content ;}@ Overrideprotected String getTitle () {return title ;}@ Overrideprotected String getURL () {return url ;} @ Overrideprotected int getgateway () {return qq_gate_way_webpage;} @ Overrideprotected String getPicUrl () {return picUrl ;}}}

The text sharing, image sharing, and link sharing interfaces are implemented above, hoping to help friends who are learning Android and who need them.

In addition, the details are almost the same as those for sharing. For details, refer to Android implementation sharing and precautions.

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.