有没有用过极光推送的,救急下,那个自定义消息怎么能在通知栏显示
答案:2 悬赏:20
解决时间 2021-11-06 16:09
- 提问者网友:对着我说爱我
- 2021-11-05 21:22
有没有用过极光推送的,救急下,那个自定义消息怎么能在通知栏显示
最佳答案
- 二级知识专家网友:浪女动了心
- 2021-11-05 21:55
可以参考我最近写的博文50697301,主要是设置activity为单例模式,复写onnewintent方法,进行跳转。
全部回答
- 1楼网友:为你轻狂半世殇
- 2021-11-05 22:49
参考官方android sdk 教程完成激光推送的基本配置
区别通知和自定义消息
通知即指在手机的通知栏(状态栏)上会显示的一条通知信息。
自定义消息是极光推送自己的概念。
自定义消息不是通知,所以不会被sdk展示到通知栏上。其内容完全由开发者自己定义。
自定义消息主要用于应用的内部业务逻辑。一条自定义消息推送过来,有可能没有任何界面显示。
本篇博客介绍的就是使用自定义通知实现上图效果。
实现自己定义的receiver,并参考官方文档在androidmanifest.xml中配置。
package com.cn.cwvs.fruit;
import java.text.simpledateformat;
import java.util.calendar;
import java.util.hashmap;
import java.util.map;
import org.json.jsonexception;
import org.json.jsonobject;
import android.content.broadcastreceiver;
import android.content.context;
import android.content.intent;
import android.os.bundle;
import android.util.log;
import cn.jpush.android.api.jpushinterface;
public class myjpushreceiver extends broadcastreceiver {
private static string tag = "pushreceiver";
@override
public void onreceive(context context, intent intent) {
bundle bundle = intent.getextras();
log.d(tag, "onreceive - " + intent.getaction());
if (jpushinterface.action_registration_id.equals(intent.getaction())) {
} else if (jpushinterface.action_message_received.equals(intent
.getaction())) {
// 自定义消息不会展示在通知栏,完全要开发者写代码去处理
string content = bundle.getstring(jpushinterface.extra_message);
string extra = bundle.getstring(jpushinterface.extra_extra);
system.out.println("收到了自定义消息@@消息内容是:"+ content);
system.out.println("收到了自定义消息@@消息extra是:"+ extra);
//**************解析推送过来的json数据并存放到集合中 begin******************
map map = new hashmap();
jsonobject jsonobject;
try {
jsonobject = new jsonobject(extra);
string type = jsonobject.getstring("type");
map.put("type", type);
} catch (jsonexception e) {
// todo auto-generated catch block
e.printstacktrace();
}
map.put("content", content);
//获取接收到推送时的系统时间
calendar rightnow = calendar.getinstance();
simpledateformat fmt = new simpledateformat("-mm-dd");
string date = fmt.format(rightnow.gettime());
map.put("date", date);
myapp.data.add(map);
//**************解析推送过来的json数据并存放到集合中 end******************
} else if (jpushinterface.action_notification_received.equals(intent
.getaction())) {
system.out.println("收到了通知");
// 在这里可以做些统计,或者做些其他工作
} else if (jpushinterface.action_notification_opened.equals(intent
.getaction())) {
system.out.println("用户点击打开了通知");
// 在这里可以自己写代码去定义用户点击后的行为
intent i = new intent(context, mainactivity.class); // 自定义打开的界面
i.setflags(intent.flag_activity_new_task);
context.startactivity(i);
} else {
log.d(tag, "unhandled intent - " + intent.getaction());
}
}
}
我要举报
如以上问答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯