android QQ好友分享

最近开发用到了QQ分享,写个博客梳理一下。

  • 申请APPID

    1104979439

  • 导入jar包

    mta-sdk-1.6.2.jar
    open_sdk_r5756.jar

  • 代码示例

配置AndroidManifest.xml文件

 <activity
            android:name="com.tencent.tauth.AuthActivity"
            android:launchMode="singleTask"
            android:noHistory="true">
            <intent-filter>
                <action android:name="android.intent.action.VIEW" />

                <category android:name="android.intent.category.DEFAULT" />
                <category android:name="android.intent.category.BROWSABLE" />

                <data android:scheme="tencent1104979439" />
            intent-filter>
        activity>

  <activity
            android:name="com.tencent.connect.common.AssistActivity"
            android:configChanges="orientation|keyboardHidden|screenSize"
            android:theme="@android:style/Theme.Translucent.NoTitleBar" />

相关权限

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />

private Tencent mTencent;

注册APP_ID

mTencent = Tencent.createInstance("1104979439", this.getApplicationContext());

分享QQ好友。

    public void QQshare() {
        ShareListener shareListener = new ShareListener();
        final Bundle params = new Bundle();
        params.putInt(QQShare.SHARE_TO_QQ_KEY_TYPE, QQShare.SHARE_TO_QQ_TYPE_DEFAULT);
        params.putString(QQShare.SHARE_TO_QQ_TITLE, "标题");
        params.putString(QQShare.SHARE_TO_QQ_SUMMARY, "内容");
        params.putString(QQShare.SHARE_TO_QQ_TARGET_URL, "www.baidu.com");
        //params.putString(QQShare.SHARE_TO_QQ_IMAGE_URL, "https://www.baidu.com/img/bd_logo1.png");
        params.putString(QQShare.SHARE_TO_QQ_IMAGE_URL, "图标");
        mTencent.shareToQQ(this, params, shareListener);
    }

 private class ShareListener implements IUiListener {

        @Override
        public void onCancel() {
            // TODO Auto-generated method stub
            showToast(getString(R.string.share_er_text));
        }

        @Override
        public void onComplete(Object arg0) {
            // TODO Auto-generated method stub
            showToast(getString(R.string.share_er_ok));
        }

        @Override
        public void onError(UiError arg0) {
            // TODO Auto-generated method stub
            showToast(getString(R.string.share_ers));
        }
    }

你可能感兴趣的:(android,qq,jar,android,sdk)