Android 集成QQ登录详细教程和Lorg/apache/http/conn/scheme/Sch处理

首先 现在SDK,目前只能通过Jar包的形式引入

下载地址

https://wiki.open.qq.com/wik

然后:

https://open.tencent.com/ 选择:

Android 集成QQ登录详细教程和Lorg/apache/http/conn/scheme/Sch处理_第1张图片

然后下一步下一步 等创建好:

打开刚才下载的SDK 

 

Android 集成QQ登录详细教程和Lorg/apache/http/conn/scheme/Sch处理_第2张图片

 

拷贝到项目的libs或者jniLibs  然后AddasLibra

 

然后在Manifest中



    
        
        
        
        
    


 

 

Code:

在需要集成的页面

 

mTencent = Tencent.createInstance(Constant.QQ_APP_ID, this.getApplicationContext());

登录方法

//qq登录
llQQLogin.setOnClickListener(v -> {
    if (!mTencent.isSessionValid()) {
        mTencent.login(this, "all", this);
    }
});

需要实现:

implements IUiListener

Code::::::::::::::::::

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    Tencent.onActivityResultData(requestCode,resultCode,data,this);
}
/**
 * 腾讯QQ登录回调
 * */
@Override
public void onComplete(Object object) {

    initOpenIdAndToken(object);
    //获取用户信息
    getUserInfo();
}
private void initOpenIdAndToken(Object object) {
    JSONObject jb = (JSONObject) object;
    try {
        String openID = jb.getString("openid");  //openid用户唯一标识
        String access_token = jb.getString("access_token");
        String expires = jb.getString("expires_in");

        mTencent.setOpenId(openID);
        mTencent.setAccessToken(access_token, expires);
    } catch (JSONException e) {
        e.printStackTrace();
    }
}
private void getUserInfo() {
    QQToken token = mTencent.getQQToken();
    UserInfo mInfo = new UserInfo(context, token);
    mInfo.getUserInfo(new IUiListener() {
        @Override
        public void onComplete(Object object) {
            JSONObject jb = (JSONObject) object;
            try {
                String name = jb.getString("nickname");
                String figureurl = jb.getString("figureurl_qq_2");  //头像图片的url
                ToastUtils.show(name);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }

        @Override
        public void onError(UiError uiError) {
        }

        @Override
        public void onCancel() {
        }
    });
}

@Override
public void onError(UiError uiError) {

}

@Override
public void onCancel() {

}

集成完可能会遇到:

NoClassDefFoundError: Failed resolution of: Lorg/apache/http/conn/scheme/Sch

 

经过测试一般会发生在9.0+的版本上

首先最好加入https网络权限:

请参考:

https://blog.csdn.net/qq_29769851/article/details/105663758

 

然后:

在Manifest中:加入


 

你可能感兴趣的:(QQ登录,androidx,android)