Jpush使用总结 _ 客户端定义通知栏样式
来源:互联网 发布:云计算行业发展趋势 编辑:程序博客网 时间:2024/06/13 20:34
转载地址: http://www.tuicool.com/articles/vQR7Jf
http://www.itnpc.com/news/web/145577790442449.html
点击消息后,会跳转到一个Activity(此Activity需要在清单文件中注册过滤器
< activity android:name = "com.example.jpushdemo.TestActivity" >
< intent-filter >
< action android:name = "jpush.testAction" />
< category android:name = "jpush.testCategory" />
</ intent-filter >
</ activity >
)中,可以在此Activity中以获取传递Intent的方式获取到message的对象。并将其显示在Activity中。
tv_title = (TextView) findViewById(R.id. tv_title );
tv_content = (TextView) findViewById(R.id. content );
Intent intent = getIntent();
if ( null != intent) {
Bundle bundle = getIntent().getExtras();
String title = bundle.getString(JPushInterface. EXTRA_NOTIFICATION_TITLE );
String content = bundle.getString(JPushInterface. EXTRA_ALERT );
tv_title .setText(title);
tv_content .setText(content);
}△ 一般来说如果不需要太多复杂内容的话,可以直接使用此种方式,将数据封装成一个Json,将其推送,客户端收到后将json解析出来并展现到前台即可。
此种方式有缺陷 ,极光中对推送通知中文本的大小有限制,为72个汉字(或144个其它类型字符)。传输信息有限。
* 自定义接收器
* 如果不定义这个 Receiver,则:
* 1) 默认用户会打开主界面
* 2) 接收不到自定义消息
消息只能在此Receiver中获取,不会显示成通知,或者其他。在 onReceive(Context context, Intent intent)中获取方式为
if (JPushInterface. ACTION_MESSAGE_RECEIVED .equals(intent.getAction())) {
Bundle bundle = intent.getExtras();
Log. d ( TAG , "[MyReceiver] 接收到推送下来的自定义消息: " + bundle.getString(JPushInterface. EXTRA_MESSAGE ));
在此处也可获取推送通知中的内容
else if (JPushInterface. ACTION_NOTIFICATION_RECEIVED .equals(intent.getAction())) {
Log. d ( TAG , "[MyReceiver] 接收到推送下来的通知" );
int notifactionId = bundle.getInt(JPushInterface. EXTRA_NOTIFICATION_ID );
Log. d ( TAG , "[MyReceiver] 接收到推送下来的通知的ID: " + notifactionId);
此种方式明显比推送通知的方式好一点的是其发送的信息容量比较大,为 236 个汉字。
自定义的通知栏样式,是在客户端进行的。请参考 通知栏样式定制API 来看所支持的功能。
自定义通知栏样式设计
在收到推送消息的那一瞬间,推送图标被截取。在极光论坛大多数人的答案是图片适配,既在不同的drawble文件夹放推送的icon,然,极光推送默认调用应用的launcher_icon,我的手机分辨率是1920*1080,调用drawable-xhdpi文件夹里面的launcher_icon,大小为144*144,而在drawable-xhdpi中的通知的图标大小为48*48才会显示全,所以出现被截取的现象是很正常不过。
问题来了,既然极光默认调用应用的launcher_icon,难道我们要把应用的launcher_icon改为48*48吗?这样我们的应用图标在桌面上显示的肯定小,出现白边。问了极光的技术客服,不知道他们是没有懂我的意思还是上什么的,他们的答案依然是对图标做适配。呵呵,要把应用图标大小改为48*48?
当然极光也提供了对应的解决方案,只是官方文档只说了在客户端如何,却没有说要在服务端做对应的设置
有个 PushNotificationBuilder 概念,开发者使用 setPushNotificationBuilder 方法为某种类型的 PushNotificationBuilder 指定编号。
setPushNotificationBuilder 可以在 JPushInterface.init() 之后任何地方调用,可以是开发者应用的逻辑来触发调用,或者初始化时调用。
只需要设置一次,JPush SDK 会记住这个设置。在下次收到推送通知时,就根据通知里指定的编号来找到 PushNotificationBuilder 来展现、执行。
API - setDefaultPushNotificationBuilder 设置默认
此 API 改变默认的编号为 0 的通知栏样式。
API - setPushNotificationBuilder 指定编号
此 API 为开发者指定的编号,设置一个自定义的 PushNotificationBuilder(通知样式构建器)。
Example - 基础的 PushNotificationBuilder
定制声音、震动、闪灯等 Notification 样式。
int builderId =1;
BasicPushNotificationBuilder builder =
new
BasicPushNotificationBuilder(MainActivity.
this
);
builder.statusBarDrawable = R.drawable.jpush_notification_icon;
builder.notificationFlags = Notification.FLAG_AUTO_CANCEL;
//设置为自动消失
builder.notificationDefaults = Notification.DEFAULT_SOUND | Notification.DEFAULT_VIBRATE | Notification.DEFAULT_LIGHTS;
// 设置为铃声与震动都要
JPushInterface.setPushNotificationBuilder(
builderId
, builder);
客户端需设置消息的类型,即builderId ,当服务端发送对应的类型时,极光会先进行消息类型匹配,若匹配不上,则默认调用应用的图标,若匹配上,则调用客户端指定的图标builder.statusBarDrawable。
2、服务端配置,也是需要设置消息类型builderId,builderId 必须与客户端的一致 。我们使用java版sdk,其他语言的sdk也可以设置builderId 。
设置关键代码如下:
附:
通知的图标大小
drawable-xhdpi 48*48
drawable-hdpi 36*36
drawable-mdpi 24*24
- Jpush使用总结 _ 客户端定义通知栏样式
- [android]JPush自定义通知栏
- ionic+jpush通知栏事件
- [android]JPush自定义通知栏
- Jpush使用总结
- 使用RemoteViews自定义通知栏样式
- 使用RemoteViews自定义通知栏样式 Notification
- php使用JPush极光推送ios android通知消息
- Jpush 点对点通知测试
- 定义通知栏消息
- Android 通知栏Notification,NotificationManager,RemoteViews使用流程,自定义通知栏样式简介
- iOS 推送通知的样式总结
- 本地通知使用总结
- Swift - JPush极光推送的使用(发送自定义消息/通知/别名/tag)
- JPush推送整理总结
- JPush相关总结
- JPush 的一些总结
- 使用图片定义鼠标样式
- ConcurrentHashMap的实现原理和源码分析
- git&github常用命令
- 多选框的全选和反选
- eclipse最有用快捷键整理
- No tests found matching 【junit 异常】
- Jpush使用总结 _ 客户端定义通知栏样式
- 你不要太天真,招聘广告到底能信几成?
- 从PHP语法糖剖析Zend VM引擎
- 【Android 界面技巧】输入框不聚焦,以及首次点击清空输入框
- SpringMvc自定义拦截器
- 【Web】Jsp基础学习
- 全排列问题
- C# webservices 天气预报 VS2015版本
- Oracle数据库基本常用命令