接入QQ登录遇到的坑

1.按照文档,下载SDK,将jar放入libs,

2.配置AndroidManifest:

        
        
                
        
            
                
                
                
                
            
        
        

3.创建实例:

// Tencent类是SDK的主要实现类,开发者可通过Tencent类访问腾讯开放的OpenAPI。
// 其中APP_ID是分配给第三方应用的appid,类型为String。
mTencent = Tencent.createInstance(APP_ID, this);

这里实例化的时候一直崩溃,信息:

 java.lang.NoClassDefFoundError: Failed resolution of: Lorg/apache/http/conn/scheme/SchemeRegistry;

解决:

在AndroidManifest.xml文件的application标签里面加入


4.实现回调 IUiListener

 @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        if (requestCode == Constants.REQUEST_LOGIN ||
                requestCode == Constants.REQUEST_APPBAR) {
            Tencent.onActivityResultData(requestCode, resultCode, data, loginListener);
        }

        super.onActivityResult(requestCode, resultCode, data);
    }


    IUiListener loginListener = new BaseUiListener() {
        @Override
        protected void doComplete(JSONObject values) {
            Log.d("SDKQQAgentPref", "AuthorSwitch_SDK:" + SystemClock.elapsedRealtime());
        }
    };

    private class BaseUiListener implements IUiListener {

        @Override
        public void onComplete(Object response) {
            if (null == response) {
               Log.d(TAG, "返回为空, 登录失败");
               return;
            }
            JSONObject jsonResponse = (JSONObject) response;
            if (null != jsonResponse && jsonResponse.length() == 0) {
               Log.d(TAG, "返回为空, 登录失败");
               return;
           }
           Util.showResultDialog(MainActivity.this, response.toString(), "登录成功");
           doComplete((JSONObject) response);
        }

        protected void doComplete(JSONObject values) {

        }

        @Override
        public void onError(UiError e) {
        }

        @Override
        public void onCancel() {
        }
    }

5.跳转到QQ请求登录

mTencent.login(this, "all", loginListener);

你可能感兴趣的:(接入QQ登录遇到的坑)