1. 信鸽动态加载厂商通道功能说明


概述

动态加载厂商通道版本可根据设备系统自动适配相应的厂商推送服务,无需另外手动集成厂商通道,大大减少了开发者接入时间和app的体量。

1.1. (AS集成)使用动态加载厂商通道方式:

  1. 在你app模块的build.gradle 文件里添加

    ndk {
                //根据需要 自行选择添加的对应cpu类型的.so库。
                abiFilters 'armeabi', 'armeabi-v7a', 'arm64-v8a'
                // 还可以添加 'x86', 'x86_64', 'mips', 'mips64'
            }
    manifestPlaceholders = [
                XG_ACCESS_ID:"注册应用的accessid",
                XG_ACCESS_KEY : "注册应用的accesskey",
                //如果需要华为通道,则加上华为的APPID 
                HW_APPID: "华为的APPID",
                //如果需要加入小米通道,则加上应用包名
                PACKAGE_NAME:"应用包名"
                 ]
    //增加以下依赖
    implementation  'com.tencent.xinge:xinge:4.3.2-xgotherpush-release'
    implementation  'com.tencent.wup:wup:1.0.0.E-Release'
    implementation 'com.tencent.jg:jg:1.1'
    implementation 'com.tencent.mid:mid:4.0.7-Release'
    //需要集成fcm增加以下依赖并将google-services.json放进你应用model的根路径下:
    implementation 'com.tencent.xinge:fcm:4.3.2-release'
    implementation 'com.google.firebase:firebase-messaging:17.3.1'
    apply plugin: 'com.google.gms.google-services'

2.代码上需要在你的ApplicationattachBaseContext函数里面增加

     StubAppUtils.attachBaseContext(context);

初始化页面添加

    XGPushConfig.enableOtherPush(getApplicationContext(), true);
    XGPushConfig.setMiPushAppId(getApplicationContext(), "APPID");
    XGPushConfig.setMiPushAppKey(getApplicationContext(), "APPKEY");
    XGPushConfig.setMzPushAppId(this, "APPID");
    XGPushConfig.setMzPushAppKey(this, "APPKEY");
    XGPushManager.registerPush(this, new XGIOperateCallback() {
    @Override
    public void onSuccess(Object data, int flag) {
    //token在设备卸载重装的时候有可能会变
    Log.d("TPush", "注册成功,设备token为:" + data);
    }
    @Override
    public void onFail(Object data, int errCode, String msg) {
    Log.d("TPush", "注册失败,错误码:" + errCode + ",错误信息:" + msg);
    }
    })

3.注册厂商通道token

启动应用并等待云控下载对应设备的厂商dex包 。 以小米为例,下载成功的日志如下:

10-25 15:16:31.067 16551-16551/? D/XINGE: [DownloadService] onCreate()
10-25 15:16:31.073 16551-16757/? D/XINGE: [DownloadService] action:onHandleIntent
10-25 15:16:31.083 16551-16757/? V/XINGE: [CloudCtrDownload] Create downloadControl
10-25 15:16:31.089 16551-16757/? I/XINGE: [CloudCtrDownload] action:download - url:https://pingjs.qq.com/xg/Xg-Xm-plug-1.0.2.pack, saveFilePath:/data/user/0/com.qq.xgdemo1122/app_dex/XG/5/, fileName:Xg-Xm-plug-1.0.2.pack
10-25 15:16:31.097 16551-16757/? V/XINGE: [CloudCtrDownload] Download file: Xg-Xm-plug-1.0.2.pack
10-25 15:16:31.641 16551-16757/? D/XINGE: [DownloadService] download file Succeed
10-25 15:16:31.650 16551-16757/? D/XINGE: [CloudCtrDownload] Download succeed.
10-25 15:16:31.653 16551-16551/? D/XINGE: [CloudControlDownloadReceiver] onReceive
10-25 15:16:31.673 16551-16738/? I/test: Download file SuccessXg-Xm-plug-1.0.2.pack to /data/user/0/com.qq.xgdemo1122/app_dex/XG/5/

4.观察到下载完成的日志后杀死应用进程,再次启动应用即可完成注册:

10-25 15:34:26.423 18700-18700/? D/TPush: +++ register push sucess. token:22dc455f79d36dec1065418e1d284639bac776b4
10-25 15:34:26.432 18700-18731/? I/XINGE: [XGOtherPush] other push token is : lYDvOWispXGoVADhRyiVdw3krLIolEd21JqdmjqBqDISK+gwl/PBm3tA9U43jxfH other push type: xiaomi

1.1.1. (AS集成)不使用动态加载厂商通道方式:

1.在你app模块的build.gradle文件里添加

    ndk {
                //根据需要 自行选择添加的对应cpu类型的.so库。
                abiFilters 'armeabi', 'armeabi-v7a', 'arm64-v8a'
                // 还可以添加 'x86', 'x86_64', 'mips', 'mips64'
            }
     manifestPlaceholders = [
                XG_ACCESS_ID:"注册应用的accessid",
                XG_ACCESS_KEY : "注册应用的accesskey",
                //如果需要华为通道,则加上华为的APPID 
                HW_APPID: "华为的APPID",
                //如果需要加入小米通道,则加上应用包名
                PACKAGE_NAME:"应用包名"

                 ]
    //增加以下依赖

    implementation 'com.tencent.xinge:xinge:4.3.7-release'
    implementation  'com.tencent.wup:wup:1.0.0.E-Release'
    implementation 'com.tencent.jg:jg:1.1'
    implementation 'com.tencent.mid:mid:4.0.7-Release'
    implementation 'com.tencent.xinge:mipush:4.3.2-xiaomi-release'
    implementation 'com.tencent.xinge:xgmz:4.3.2-meizu-release'
    implementation 'com.tencent.xinge:xghw:4.3.2-huawei-release'
    //fcm通道需要增加以下依赖并将google-services.json放进你应用model的根路径下。
    implementation 'com.tencent.xinge:fcm:4.3.2-release'
    implementation 'com.google.firebase:firebase-messaging:17.3.1'
    apply plugin: 'com.google.gms.google-services'

2.初始化页面添加

    XGPushConfig.enableOtherPush(getApplicationContext(), true);
    XGPushConfig.setMiPushAppId(getApplicationContext(), "APPID");
    XGPushConfig.setMiPushAppKey(getApplicationContext(), "APPKEY");
    XGPushConfig.setMzPushAppId(this, "APPID");
    XGPushConfig.setMzPushAppKey(this, "APPKEY");
    XGPushManager.registerPush(this, new XGIOperateCallback() {
    @Override
    public void onSuccess(Object data, int flag) {
    //token在设备卸载重装的时候有可能会变
    Log.d("TPush", "注册成功,设备token为:" + data);
    }
    @Override
    public void onFail(Object data, int errCode, String msg) {
    Log.d("TPush", "注册失败,错误码:" + errCode + ",错误信息:" + msg);
    }
    })

1.1.2. 注意事项

  1. 动态下载插件目前只支持华为、小米、魅族通道,有可能在某些机型上出现未知异常,导致注册失败。
  2. 能否成功加载厂商通道的dex配置包依赖于终端网络环境和设备厂商系统的限制,如多次注册失败请使用(AS集成)不使用动态加载厂商通道方式
  3. 使用AS动态加载方式无需手动集成XG4HWPush.jar,XG4MZPush.jar,小米XG4XMPush.jar等对应通道的jar或者是gradle对应依赖。
  4. 如果Eclipse集成需使用动态加载方式,则需要增加XgOtherPush.jar包,否则不要增加此包。(注意:XgOtherPush.jar和手动导入的XG4XMPush.jar,XG4MZPush,XG4HWPush的jar或者是小米,华为,魅族的gradle对应依赖是互斥的。)
  5. Eclipse使用动态加载需增加XgOtherPush.jar,manifest必须要配上云控配置:

    <receiver
             android:name="com.tencent.android.tpush.cloudctr.network.CloudControlDownloadReceiver"
             android:exported="true">
             <intent-filter>
                 <action android:name="com.tencent.android.tpush.cloudcontrol.action.DOWNLOAD_FILE_FINISH" />
             </intent-filter>
         </receiver>
         <service
             android:name="com.tencent.android.tpush.cloudctr.network.CloudControlDownloadService"
             android:exported="true"
             android:persistent="true" />
    

    在代码接入上,需要在你的应用ApplicationattachBaseContext函数里面增加StubAppUtils.attachBaseContext(context);初始化动态加载框架。 如果不使用动态加载厂商第4点就无需添加

  6. 厂商通道如果需要通过点击回调获取参数或者跳转自定义页面,可以通过使用Intent来实现,点击查看教程

  7. 如遇到发布华为应用市场,发布应用时审核不通过显示“错误:28: 集成 HMS 需要将证书文件打包到 APK 中,请直接将 assets 目录拷贝到应用工程根目录”。
    解决办法:下载华为官方 HMS SDK,将 assets 目录下的所有文件及子目录拷贝到开发者 App 工程的同名目录下。如果目录不存在,请先创建.

results matching ""

    No results matching ""