qq 登陸 cordova插件

1.下載open-sdk.jar文件和mta_sdk_x.x.x.jar文件拷貝到libs(或lib)目錄下
這個連接 很容易的把環境配置好
http://wiki.connect.qq.com/%E5%88%9B%E5%BB%BA%E5%B9%B6%E9%85%8D%E7%BD%AE%E5%B7%A5%E7%A8%8B_android_sdk
2. 配置AndroidManifest
我配置錯誤
因此我加了Demo中的數據就能夠了java

 1    <activity android:exported="true" android:label="@string/app_name" android:launchMode="singleTask" android:name="com.tencent.sample.wxapi.WXEntryActivity">
 2             <intent-filter>
 3                 <action android:name="android.intent.action.VIEW" />
 4                 <category android:name="android.intent.category.DEFAULT" />
 5                 <data android:scheme="sdksample" />
 6             </intent-filter>
 7         </activity>
 8         <receiver android:name="com.tencent.sample.AppRegister" android:permission="com.tencent.mm.plugin.permission.SEND">
 9             <intent-filter>
10                 <action android:name="com.tencent.mm.plugin.openapi.Intent.ACTION_REFRESH_WXAPP" />
11             </intent-filter>
12         </receiver>
13         <activity android:name="com.tencent.connect.avatar.ImageActivity" />
14         <activity android:name="com.tencent.connect.common.AssistActivity" android:screenOrientation="portrait" android:theme="@android:style/Theme.Translucent.NoTitleBar" />
15         <activity android:launchMode="singleTask" android:name="com.tencent.tauth.AuthActivity" android:noHistory="true">
16             <intent-filter>
17                 <action android:name="android.intent.action.VIEW" />
18                 <category android:name="android.intent.category.DEFAULT" />
19                 <category android:name="android.intent.category.BROWSABLE" />
20                 <data android:scheme="tencent222222" />
21             </intent-filter>
22         </activity>

3.環境配置好了以後android

建立本身的插件git

4.github

package cn.debi.cordova;
import java.text.SimpleDateFormat;

import org.apache.cordova.CallbackContext;
import org.apache.cordova.CordovaPlugin;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;




import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.widget.Toast;

import com.tencent.tauth.IUiListener;
import com.tencent.tauth.UiError;

import com.tencent.tauth.Tencent;
public class qqlogin extends CordovaPlugin{
    
    public static final String APPID ="222222";
      //private static final String APPID = "100363349";
    private Tencent mTencent = null;
    private CallbackContext  mCallbackContext = null;
    

    @Override
    public boolean execute(String action, JSONArray args, CallbackContext callbackContext) {
        mCallbackContext=callbackContext;

        if (action.equals("qqlogins")) {
            this.qqLogin();


        }else if(action.equals("qqLogout")){
            Context context = this.cordova.getActivity().getApplicationContext();

            mTencent.logout(context);
            mCallbackContext.success();

            
        }
        else {
            return false;
        }
        return true;
    }
    
    
    public void qqLogin(){
        // 建立受權認證信息
        final Activity activity = this.cordova.getActivity();

        Context context = this.cordova.getActivity().getApplicationContext();
        mTencent = Tencent.createInstance(APPID, context);
        
        final IUiListener listener = new BaseUiListener() {
            @Override
            protected void doComplete(JSONObject values) {
                

            }
            
            
            
        };
        
        this.cordova.getActivity().runOnUiThread(new Runnable() {
            @Override
            public void run() {

                mTencent.login(activity, "all", listener);
            }
        });
        
        
    }
    
    

    private class BaseUiListener implements IUiListener {

        @Override
        public void onComplete(Object response) {
            String uid=mTencent.getOpenId();
            String token=mTencent.getAccessToken();
            Log.d("uid111",uid);

            JSONObject res=new JSONObject();
            try {
       
                res.put("uid", uid);
                res.put("token", token);
                mCallbackContext.success(res);

            } catch (JSONException e) {
                // TODO Auto-generated catch block
                mCallbackContext.error(0);
                e.printStackTrace();
            }

        }

        protected void doComplete(JSONObject values) {


        }

        @Override
        public void onError(UiError e) {
            mCallbackContext.error(0);


        }

        @Override
        public void onCancel() {
            
            mCallbackContext.error(0);

        }

        
    }


}

5.qqlogin.jsapache

1 var exec = require('cordova/exec');
2 
3 exports.getqqlogin = function(messege,success, error) {
4     exec(success, error, "qqlogin", "qqlogins", [messege]);
5 };
6 exports.getqqlogout= function(messege,success, error) {
7     exec(success, error, "qqlogin", "qqlogout", [messege]);
8 };

6.plugin.xmljson

 1 <?xml version="1.0" encoding="utf-8"?>
 2 <plugin id="cn.debi.cordova" version="0.0.1" 
 3         xmlns="http://apache.org/cordova/ns/plugins/1.0"
 4         xmlns:android="http://schemas.android.com/apk/res/android">
 5     <name>qqlogin</name>
 6     <description>Description</description>
 7     <js-module name="qqlogin" src="www/qqlogin.js">
 8         <clobbers target="cordova.plugins.qqlogin"/>
 9     </js-module>
10     <platform name="android">
11         <config-file parent="/*" target="res/xml/config.xml">
12             <feature name="qqlogin">
13                 <param name="android-package" value="cn.debi.cordova.qqlogin"/>
14             </feature>
15         </config-file>
16         <source-file src="src/android/qqlogin.java" target-dir="src/cn/debi/cordova"/>
17     </platform>
18 </plugin>

7.調用api

1 var extraInfo = cordova.require('cn.debi.cordova.qqlogin');
2     extraInfo.getqqlogin('cole.log',function(message) {
3          alert(message);
4     }, function(message) {
5          alert(message);
6     });

 8.添加直接插件app

cordova plugin add Login_QQide

9.完成ui

github 地址

相關文章
相關標籤/搜索