QQ登入(1)-有客户端直接授权,没客户端web授权

准备jar文件3个:

android-support-v4.jar

下载地址:http://pan.baidu.com/s/1eQmoTm6

mta-sdk-1.6.2.jar

下载地址:http://pan.baidu.com/s/1vk4Bc

open_sdk.jar

下载地址:http://pan.baidu.com/s/1o64V0Em

添加权限

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

添加腾讯授权和支持页面activity

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

<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="tencent222222" />
<!-- 100380359 100381104 222222 -->
</intent-filter>
</activity>

添加页面代码:

 

package sdkjfs.e;

import org.json.JSONObject;

import com.tencent.connect.auth.QQAuth;
import com.tencent.tauth.IUiListener;
import com.tencent.tauth.Tencent;
import com.tencent.tauth.UiError;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.Toast;

public class MyQQloginShareActivity extends Activity {
    public  String mAppid="222222";
    public  QQAuth mQQAuth;
    private Tencent mTencent;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        mQQAuth = QQAuth.createInstance(mAppid, getApplicationContext());
        mTencent = Tencent.createInstance(mAppid, getApplicationContext());
    }
    public void myclick(View v){
        IUiListener listener = new IUiListener() {
            @Override
            public void onCancel() {
            Toast.makeText(getApplicationContext(), "取消登入", 0).show();            
            }
            @Override
            public void onComplete(Object arg0) {
                Toast.makeText(getApplicationContext(), "登录成功", 0).show();  
getUserInfo(); //获取用户信息 } @Override
public void onError(UiError arg0) { Toast.makeText(getApplicationContext(), "登录失败", 0).show(); } }; mTencent.login(this, "all", listener); } }

 退出登入:mTencent.logout(getApplicationContext());

 

完整案例源码: 源码:链接: http://pan.baidu.com/s/1qWwJQ24 

posted on 2014-04-19 23:27  clarenceV1  阅读(813)  评论(0编辑  收藏  举报

导航