参考文档
一、导入sdk\jar\open_sdk.jar 和 sdk\sample\libs\mta-sdk-1.0.0.jar两个jar文件。
二、在manifest文件添加权限并在application节点内添加配置代码。
1 <uses-permission android:name="android.permission.INTERNET"/> 2 <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> 3 <activity android:name="com.tencent.connect.common.AssistActivity" 4 android:theme="@android:style/Theme.Translucent.NoTitleBar" 5 android:screenOrientation="portrait" /> 6 7 <activity 8 android:name="com.tencent.tauth.AuthActivity" 9 android:launchMode="singleTask" 10 android:noHistory="true" > 11 <intent-filter> 12 <action android:name="android.intent.action.VIEW" /> 13 14 <category android:name="android.intent.category.DEFAULT" /> 15 <category android:name="android.intent.category.BROWSABLE" /> 16 17 <data android:scheme="tencent1103826395" /> 18 </intent-filter> 19 </activity>
三、使用范例代码
1 public class QQUtils implements IUiListener { 2 3 public final String APP_ID = "1103826395"; 4 private Tencent mTencent; 5 public static QQUtils qq = null; 6 private Activity mActivity; 7 8 /** 9 * 传入应用程序的全局context,可通过activity的getApplicationContext方法获取 10 * @param context 11 */ 12 private QQUtils(Activity context){ 13 mTencent = Tencent.createInstance(APP_ID, context.getApplicationContext()); 14 } 15 16 public static QQUtils getInstance(Activity context){ 17 if(qq == null){ 18 qq = new QQUtils(context); 19 } 20 return qq; 21 } 22 23 public void shareToQzone(Activity activity) { 24 mActivity = activity; 25 // 分享类型 26 final Bundle params = new Bundle(); 27 ArrayList<String> iamges = new ArrayList<String>(); 28 iamges.add("http://pic.cnitblog.com/avatar/670827/20140912111842.png"); 29 params.putInt(QzoneShare.SHARE_TO_QZONE_KEY_TYPE, QzoneShare.SHARE_TO_QZONE_TYPE_IMAGE_TEXT); 30 params.putString(QzoneShare.SHARE_TO_QQ_TITLE, "标题");// 必填 31 params.putString(QzoneShare.SHARE_TO_QQ_SUMMARY, "内容");// 选填 32 params.putString(QzoneShare.SHARE_TO_QQ_TARGET_URL, "http://www.cnblogs.com/StuLiuJun/");// 必填 33 params.putStringArrayList(QzoneShare.SHARE_TO_QQ_IMAGE_URL, iamges); 34 35 new Thread(){ 36 public void run() { 37 mTencent.shareToQzone(mActivity, params, qq); 38 } 39 }.start(); 40 41 } 42 43 @Override 44 public void onCancel() { 45 // TODO Auto-generated method stub 46 Toast("分享已取消"); 47 } 48 49 @Override 50 public void onComplete(Object arg0) { 51 // TODO Auto-generated method stub 52 Toast("分享成功"); 53 } 54 55 @Override 56 public void onError(UiError arg0) { 57 // TODO Auto-generated method stub 58 Toast("出错了"); 59 } 60 61 public void Toast(final String str){ 62 63 Toast.makeText(mActivity, str, Toast.LENGTH_SHORT).show(); 64 65 66 } 67 68 }
时间: 2024-12-19 08:48:59