Skip to content

一、腾讯信鸽集成

1.1 介绍

腾讯信鸽是腾讯团队开发的一套快速、稳定、高效的移动推送。通过集成SDK实现APP推送能力,支持主流Android、iOS平台的通知栏推送、应用内透穿消息。 官网地址:https://xg.qq.com/ 开发文档:https://xg.qq.com/docs/

1.2 Android 端集成

  1. 需要使用的jar以及相关资源: 56632874.png

  2. Androidmainfest.xml里的配置参数 需要的权限:

xml
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.RECEIVE_USER_PRESENT" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_SETTINGS" />

<application>节点下配置:

xml
     <receiver android:name="com.tencent.android.tpush.XGPushReceiver" android:process=":xg_service_v4">
        <intent-filter android:priority="0x7fffffff">
            <action android:name="com.tencent.android.tpush.action.SDK" />
            <action android:name="com.tencent.android.tpush.action.INTERNAL_PUSH_MESSAGE" />
            <action android:name="android.intent.action.USER_PRESENT" />
            <action android:name="android.net.conn.CONNECTIVITY_CHANGE" />
            <action android:name="android.bluetooth.adapter.action.STATE_CHANGED" />
            <action android:name="android.intent.action.ACTION_POWER_CONNECTED" />
            <action android:name="android.intent.action.ACTION_POWER_DISCONNECTED" />
        </intent-filter>
   s
    <service android:exported="true" android:name="com.tencent.android.tpush.service.XGPushServiceV4" android:persistent="true" android:process=":xg_service_v4"/>
    <service android:exported="true" android:name="com.tencent.android.tpush.rpc.XGRemoteService">
    <intent-filter>
        <action android:name="com.asiainfo.gzltwsl.PUSH_ACTION" />
    </intent-filter>
    </service>
    <provider android:authorities="com.asiainfo.gzltwsl.AUTH_XGPUSH" android:exported="true" android:name="com.tencent.android.tpush.XGPushProvider" />
    <provider android:authorities="com.asiainfo.gzltwsl.TPUSH_PROVIDER" android:exported="false" android:name="com.tencent.android.tpush.SettingsContentProvider" />
    <provider android:authorities="com.asiainfo.gzltwsl.TENCENT.MID.V3" android:exported="true" android:name="com.tencent.mid.api.MidProvider"/>
    <meta-data android:name="XG_V2_ACCESS_ID" android:value="2100326910" />
    <meta-data android:name="XG_V2_ACCESS_KEY" android:value="ALE4G778GF6D" />

插件代码:

java
package com.ai.ced.xgpush;

import android.util.Log;

import org.apache.cordova.CordovaPlugin;
import org.apache.cordova.CallbackContext;

import org.json.JSONArray;
import org.json.JSONException;
import android.app.Activity;

import com.tencent.android.tpush.XGIOperateCallback;
import com.tencent.android.tpush.XGPushConfig;
import com.tencent.android.tpush.XGPushManager;


/**
 * This class echoes a string called from JavaScript.
 */
public class xgPushPlugin extends CordovaPlugin {

    public static final String TAG = "xgPushPlugin";

    public static Activity activity;

    @Override
    public boolean execute(String action, JSONArray params, CallbackContext callbackContext) throws JSONException {
        Log.d(TAG,"execute");
        activity = this.cordova.getActivity();

        if (action.equals("startXgPushSDK")) {
            String message = params.getString(0);
            Log.d(TAG,"message" + message);
            this.startXgPushSDK(message, callbackContext);
            return true;
        } else if (action.equals("stopXgPushSDK")){
            
        }
        return false;
    }

    private void initConfig(){
        //开启信鸽的日志输出,线上版本不建议调用
        XGPushConfig.enableDebug(activity, true);

    }

    private void startXgPushSDK(String message, CallbackContext callbackContext) {
        Log.d(TAG,"enter startXgPushSDK");


        // 注册信鸽SDK
        /*
        注册信鸽服务的接口
        如果仅仅需要发推送消息调用这段代码即可
        */
        XGPushManager.registerPush(activity,
                new XGIOperateCallback() {
                    @Override
                    public void onSuccess(Object data, int flag) {
                        Log.d(TAG, "+++ register push sucess. token:" + data + "flag" + flag);
                    }

                    @Override
                    public void onFail(Object data, int errCode, String msg) {
                        Log.w(TAG,
                                "+++ register push fail. token:" + data
                                        + ", errCode:" + errCode + ",msg:"
                                        + msg);
                    }
                });

        String deviceToken = XGPushConfig.getToken(activity);
        Log.d(TAG,"enter getToken" + deviceToken);

    }

    private void stopXgPushSDK(String message, CallbackContext callbackContext) {
        Log.d(TAG,"enter stopXgPushSDK");    
    }
}

Released under the MIT License.