Android集成友盟推送踩坑页面崩溃

  1. 问题:退出应用,点击跳转Activity,根据推送的消息id有个网络请求,会出现页面崩溃;
  2. 问题:彻底杀死应用,使用手机系统通道,无法获得推送消息;

点击通知栏跳转接收推送消息使用

    UmengMessageHandler messageHandler = new UmengMessageHandler() {

        @Override
        public Notification getNotification(Context context, UMessage msg) {
            Log.i("DEBUG","messageHandler通知栏:"+msg.custom);
            Log.i("DEBUG","messageHandler通知栏:"+msg.title);
            Log.i("DEBUG","messageHandler通知栏:"+msg.text);
            return super.getNotification(context, msg);
        }
    };
    mPushAgent.setMessageHandler(messageHandler);

点击通知跳转

/**
     *  点击"通知"的后续行为,默认为打开app。
     *         "after_open": "xx" // 必填 值可以为:
     *                                    "go_app": 打开应用
     *                                    "go_url": 跳转到URL
     *                                    "go_activity": 打开特定的activity
     *                                    "go_custom": 用户自定义内容。
     *         "url": "xx",       // 可选 当"after_open"为"go_url"时,必填。
     *                                    通知栏点击后跳转的URL,要求以http或者https开头
     *         "activity":"xx",   // 可选 当"after_open"为"go_activity"时,必填。
     *                                    通知栏点击后打开的Activity
     *         "custom":"xx"/{}   // 可选 display_type=message, 或者
     *                                    display_type=notification且
     *                                    "after_open"为"go_custom"时,
     *                                    该字段必填。用户自定义内容, 可以为字符串或者JSON格式。
     */
    UmengNotificationClickHandler notificationClickHandler = new UmengNotificationClickHandler() {
        @Override
        public void launchApp(Context context, UMessage uMessage) {
            super.launchApp(context, uMessage);
            ToastUtil.show(context,"launchApp推送custom:"+uMessage.custom);
            ToastUtil.show(context,"launchApp推送:"+uMessage.extra);
            Log.i("DEBUG","launchApp推送:"+uMessage.extra);
            Map<String, String> extra = uMessage.extra;
            String id = extra.get("Id");
            Intent intent = new Intent(context, MessageDetailActivity.class);         intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK|Intent.FLAG_ACTIVITY_CLEAR_TOP);
            intent.putExtra("Id", Integer.valueOf(id));
            intent.putExtra("Push",true);
            context.startActivity(intent);
        }


        @Override
        public void dealWithCustomAction(Context context, UMessage msg) {
            super.dealWithCustomAction(context, msg);
            Log.i("DEBUG","dealWithCustomAction推送:"+msg.custom);
            Log.i("DEBUG","dealWithCustomAction推送:"+msg.title);
            Log.i("DEBUG","dealWithCustomAction推送:"+msg.text);
            Gson gson = new Gson();
            PushReceiveBean pushReceiveBean = gson.fromJson(msg.custom, PushReceiveBean.class);
            Intent data = new Intent();
            data.putExtra("Id",pushReceiveBean.getExtra().getId());
            data.putExtra("Push",true);
            data.setClass(context, MessageDetailActivity.class);
            data.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            context.startActivity(data);
        }
    };
mPushAgent.setNotificationClickHandler(notificationClickHandler);

解决问题1:launchApp()方法是用于打开应用方法,dealWithCustomAction()用于自定义行为。需要后端开发者配合设置参数,其中"after_open":"go_app",就是点击进入的行为类型。

友盟发送策略

{"policy":{"expire_time":"2019-08-21 17:40:25"},"description":"用户消息通知","production_mode":true,"appkey":"aaaaaa","alias":"bbbbbbbbbb","alias_type":"Guid","type":"customizedcast","timestamp":1566294025,"mipush":true,"mi_activity":"com.air.activity.MessageDetailActivity","payload":{"body":{"title":"下单成功","ticker":"","text":"您的订单201908200050已下单,您的产品需要等待普莱克斯确认后排单、发货,我们会及时通知,请关注后续信息","after_open":"go_app","play_vibrate":true,"play_lights":true,"play_sound":true},"display_type":"notification","extra":{"CreatedOn":"2019-08-20 17:40","Read":false,"Id":19811}}}

解决问题2:应用被杀死,需要使用系统通道,指定打开路径,这里我在使用时,收到通知但是无法获取推送消息内容,只能指定打开首页,让后台开发者写入指定首页即可。如图(我注册了小米华为官方通道,但是取消了注册代码,离线也能收到推送)

设备离线时打开Activity路径

最后,锁屏导致收不到通知则由于系统回收引起。

以华为手机为例。系统在黑屏待机后自动清理后台运行的软件,这样影响了我们正常接收新的消息,需要将应用软件设置为非清理应用。

如何设置:1、关闭锁屏清理应用操作步骤:在“设置 - 电池 - 锁屏清理应用”,找到需要操作的应用,关闭锁屏清理开关。

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值