极光厂商通道接入配置

接入配置

1.project下build.gradle增加以下配置

repositories {
        maven { url 'https://developer.huawei.com/repo/' }
    }
    dependencies {
        // HMS 服务插件 和 华为 的 Maven 代码库
        classpath 'com.huawei.agconnect:agcp:1.0.0.300'
    }
}
allprojects {
    repositories {
        maven { url 'https://developer.huawei.com/repo/' }
    }
}

2.app下build.gradle增加以下配置

//极光vip 华为
apply plugin: 'com.huawei.agconnect'

defaultConfig {
    manifestPlaceholders = [
                JPUSH_PKGNAME: rootProject.ext.versions.applicationId,
                 //JPush 上注册的包名 对应的 Appkey
                JPUSH_APPKEY : "xxxxxxxxxxxxxxxxxxxxxxxx",
                //暂时填写默认值即可.
                JPUSH_CHANNEL: "developer-default", 
                // 设置 manifest.xml 中的变量,不要忘记OP-的前缀
                // OPPO 平台注册的 appkey
                OPPO_APPKEY : "OP-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
                // OPPO 平台注册的 appid
                OPPO_APPID : "OP-xxxxxxx",
                //OPPO 平台注册的 appsecret
                OPPO_APPSECRET: "OP-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
                // 设置manifest.xml中的变量,不要忘记MI-的前缀
                // 小米平台注册的appkey
                XIAOMI_APPKEY : "MI-xxxxxxxxxxxxx", 
                // 小米平台注册的appid
                XIAOMI_APPID : "MI-xxxxxxxxxxxxxxxxxxx", 
                // 设置manifest.xml中的变量
                // VIVO平台注册的appkey 
                VIVO_APPKEY : "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx", 
                // VIVO平台注册的appid
                VIVO_APPID : "xxxxx", 
                // 华为 设置manifest.xml中的变量
                HUAWEI_APPID : "xxxxxxxxx",
                //不要忘记MZ-的前缀
                //魅族平台注册的appkey
                MEIZU_APPKEY:"MZ-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
                //魅族平台注册的appid
                MEIZU_APPID:"MZ-xxxxxx",
    ]
}
dependencies {
            implementation 'cn.jiguang.sdk:jpush:3.8.6'
            implementation 'cn.jiguang.sdk:jcore:2.5.5'
            implementation 'cn.jiguang.sdk.plugin:oppo:3.8.6'
            implementation 'cn.jiguang.sdk.plugin:xiaomi:3.8.6'
            implementation 'cn.jiguang.sdk.plugin:vivo:3.8.6'
            implementation 'cn.jiguang.sdk.plugin:meizu:3.8.6'
            implementation 'cn.jiguang.sdk.plugin:huawei:3.8.6'
            implementation 'com.huawei.hms:push:4.0.2.300'
    
}

3.app根目录下新增从华为平台获取的agconnect-services.json文件

更换app applicationId打包时此文件会报错,需要更改/client/package_name值

4.混淆配置

# 极光vivo厂商通道
-dontwarn com.vivo.push.**
-keep class com.vivo.push.**{*; }
-keep class com.vivo.vms.**{*; }
# 极光oppo厂商通道
-dontwarn com.coloros.mcsdk.**
-keep class com.coloros.mcsdk.** { *; }
-dontwarn com.heytap.**
-keep class com.heytap.** { *; }
-dontwarn com.mcs.**
-keep class com.mcs.** { *; }
# 极光小米厂商通道
-dontwarn com.xiaomi.push.**
-keep class com.xiaomi.push.** { *; }
# 极光华为厂商通道
-keepattributes *Annotation*
-keepattributes Exceptions
-keepattributes InnerClasses
-keepattributes Signature
-keepattributes SourceFile,LineNumberTable
-keep class com.hianalytics.android.**{*;}
-keep class com.huawei.updatesdk.**{*;}
-keep class com.huawei.hms.**{*;}
# 魅族厂商通道
-dontwarn com.meizu.cloud.**
-keep class com.meizu.cloud.** { *; }

通知栏点击事件处理

AndroidManifest.xml中配置点击通知要打开的 activity示例:

<activity
    android:name=".activity.LaunchActivity"
    android:exported="true">
    <intent-filter>
        <!--oppo平台要求-->
        <action android:name="com.smxxy.sc.activity.LaunchActivity"/>
        <!--华为、小米、vivo平台要求-->
        <action android:name="android.intent.action.VIEW" />
        <category android:name="android.intent.category.DEFAULT" />
    </intent-filter>
</activity>

备注:华为要求该activity不能为app的主页面。

获取通知相关数据

魅族厂商通道数据和极光通道处理一致,其它厂商通过配置的activity传递数据。

目前启动配置的 activity 都是使用 Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK 方式启动,只需要在配置的activity中的onCreate方法中进行处理,获取通知信息。

{   
    "msg_id":"123456", 
    "n_content":"this is content",  
    "n_extras":{"key1":"value1","key2":"value2"}, 
    "n_title":"this is title",  
    "rom_type":2
}
字段取值类型描述
msg_idString通过此key获取到通知的msgid
n_titleString通过此key获取到通知标题
n_contentString通过此key获取到通知内容
n_extrasString通过此key获取到通知附加字段
rom_typebyte通过此key获取到下发通知的平台。得到值说明:byte类型的整数, 0为极光,1为小米,2为华为,3为魅族,4为oppo,5为vivo,8为FCM。

rom_type 用于点击事件的上报,一般情况下开发者只需要取到该字段的值用于上报,不需要关心具体取值。

魅族厂商通道通知数据处理
public class MyReceiver extends BroadcastReceiver{
 @Override
    public void onReceive(Context context, Intent intent) {
        try {
            String action = intent.getAction();
            Bundle bundle = intent.getExtras();
            if (action == null) return;
            switch (action) {
                case JPushInterface.ACTION_NOTIFICATION_OPENED:
                    String extra = "";
                    if (bundle != null) {
                        extra = bundle.getString(JPushInterface.EXTRA_EXTRA);
                    }
                    //app未启动,按小米、oppo、vivo数据格式传递
                    if (ActivityStack.activityList.isEmpty()) {
                        ARouter.getInstance().build(RouterURLS.GO_LAUNCH_ACTIVITY).withString("JMessageExtra", extra).navigation();
                    } else {
                        //推送消息统一处理方法
                        ActionNotificationOpenedManager.getInstance(context).jumpActivity(bundle);
                    }
                default:
                    break;
            }
        } catch (Exception e) {

        }

    }
}
通知数据统一处理
LaunchActivity跳转处理
//当前栈中有MainActivity
boolean isMainExists = ActivityStack.isActivityExist(MainActivity.class);
//从厂商通道启动
boolean isFromThirdPush = checkIsFromThirdPush();
if (isMainExists && isFromThirdPush) {
    //直接启动MainActivity
}else{
    //启动闪屏页,有推送数据传给闪屏页,再由闪屏页传给主页
}
MainActivity数据处理
// 此方法在onCreate和onNewIntent方法中调用
private void handleThirdPushResult() {
        Intent intent = getIntent();
        if (intent == null) {
            return;
        }
        //华为
        String dataString = intent.getDataString();
        Bundle extraBundle = intent.getExtras();
        //小米、OPPO、VIVO
        if (TextUtils.isEmpty(dataString) && extraBundle != null) {
            dataString = extraBundle.getString("JMessageExtra");
        }
        if (TextUtils.isEmpty(dataString)) return;
        ThirdPushBean thirdPushBean = GsonUtil.parseJsonToBean(dataString, ThirdPushBean.class);
        if (thirdPushBean != null) {
            Bundle bundle = new Bundle();
            //魅族推送消息
            if (TextUtils.isEmpty(thirdPushBean.getMsg_id())) {
                bundle.putString(JPushInterface.EXTRA_EXTRA, dataString);
                ActionNotificationOpenedManager.getInstance(this).jumpActivity(bundle);
            } else {
                //厂商通道推送消息
                Object extras = thirdPushBean.getN_extras();
                if (extras instanceof LinkedTreeMap) {
                    LinkedTreeMap n_extras = (LinkedTreeMap) extras;
                    bundle.putString(JPushInterface.EXTRA_EXTRA, GsonUtil.parseObjectToJson(n_extras));
                    //推送消息统一处理方法
                    ActionNotificationOpenedManager.getInstance(this).jumpActivity(bundle);
                }
                //通知点击上报
                JPushInterface.reportNotificationOpened(this, thirdPushBean.getMsg_id(), (byte) thirdPushBean.getRom_type());
            }
        }
    }

厂商通道检测方法开启

极光setdebugmode方法,极光init之前调用;

//设置开启日志,发布时请关闭日志
JPushInterface.setDebugMode(true);
JPushInterface.init(this);  

从AS的控制台获取卸载重装并打开app的完整日志,可筛选关键字:jiguang;

检查logcat日志中是否有厂商token信息生成,例:[ThirdPushManager] uploadRegID regid:0860192030393833300002294200CN01

如果有厂商注册信息生成,将App退到后台,并且杀掉所有App进程,进行通知消息推送;

如果能够收到推送,则表明厂商通道集成成功。

其它

后端配置

uri_activity字段 该字段用于指定开发者想要打开的 activity,值为 activity 节点的 “android:name”属性值;
适配华为、小米、vivo厂商通道跳转;

uri_action字段 该字段用于指定开发者想要打开的 activity,值为 “activity”-“intent-filter”-“action” 节点的 “android:name” 属性值;适配 oppo、fcm跳转;

third_party_channel distribution字段 值为 secondary_push 表示推送优先走极光,极光不在线再走厂商,厂商作为辅助;

送达回执

华为和魅族需要配置送达回执,否则通知统计不到

  • 3
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值