极光推送JPush相关设置
2016-08-05 16:24
477 查看
摘自:http://blog.csdn.net/i_lovefish/article/details/17336169
记录几点(摘自官方文档):
AndroidManifest.xml
libs/jpush-sdk-release 1.x.y.jar
libs/armeabi/libsys 1.x.y.so
init 初始化SDK
setDebugMode 设置调试模式
定制声音、震动、闪灯等 Notification 样式。
基于基础的 PushNotificationBuilder,可进一步地定制 Notification 的 Layout。
默认5条
参数说明
Context context 应用的ApplicationContext
Set days 0表示星期天,1表示星期一,以此类推。 (7天制,Set集合里面的int范围为0到6)
Sdk1.2.9 – 新功能:set的值为null,则任何时间都可以收到消息和通知,set的size为0,则表示任何时间都收不到消息和通知.
int startHour 允许推送的开始时间 (24小时制:startHour的范围为0到23)
int endHour 允许推送的结束时间 (24小时制:endHour的范围为0到23)
调用此 API 来同时设置别名与标签。
需要理解的是,**这个接口是覆盖逻辑,而不是增量逻辑。即新的调用会覆盖之前的设置。**
在之前调用过后,如果需要再次改变别名与标签,只需要重新调用此 API 即可。
Android 在调用此接口时,建议 Set 的实现使用LinkedHashSet,即会保证排序的 Set。这样,当你调用接口 tags 多于 100
个时,保证前 100 个被 JPush 成功地设置。
参数定义
alias
null 此次调用不设置此值。(注:不是指的字符串"null")
"" (空字符串)表示取消之前的设置。
每次调用设置有效的别名,覆盖之前的设置。
有效的别名组成:字母(区分大小写)、数字、下划线、汉字。
限制:alias 命名长度限制为 40 。
tags
null 此次调用不设置此值。(注:不是指的字符串"null")
空数组或列表表示取消之前的设置。
每次调用至少设置一个 tag,覆盖之前的设置,不是新增。
有效的标签组成:字母(区分大小写)、数字、下划线、汉字。
限制:每个 tag 命名长度限制为 40,最多支持设置 100 个 tag,但总长度不得超过1K字节。
通知
或者说 Push Notification,即指在手机的通知栏(状态栏)上会显示的一条通知信息。这是 Android / iOS 的基本功能。
一条通知,简单的填写纯文本的通知内容即可。
通知主要用于提示用户的目的。应用加上通知功能,有利于提高应用的活跃度。
自定义消息
是极光推送自己的概念。
自定义消息不是通知,所以不会被SDK展示到通知栏上。其内容完全由开发者自己定义。
自定义消息主要用于应用的内部业务逻辑。一条自定义消息推送过来,有可能没有任何界面显示。
记录几点(摘自官方文档):
1.设置
AndroidManifest.xmllibs/jpush-sdk-release 1.x.y.jar
libs/armeabi/libsys 1.x.y.so
2.基础API
init 初始化SDKsetDebugMode 设置调试模式
3.MyReceiver
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 | /** * 自定义接收器 * * 如果不定义这个 Receiver,则: * 1) 默认用户会打开主界面 * 2) 接收不到自定义消息 */ public class MyReceiver extends BroadcastReceiver { private static final String TAG = "MyReceiver"; @Override public void onReceive(Context context, Intent intent) { Bundle bundle = intent.getExtras(); Log.d(TAG, "onReceive - " + intent.getAction() + ", extras: " + printBundle(bundle)); if (JPushInterface.ACTION_REGISTRATION_ID.equals(intent.getAction())) { String regId = bundle.getString(JPushInterface.EXTRA_REGISTRATION_ID); Log.d(TAG, "接收Registration Id : " + regId); //send the Registration Id to your server... }else if (JPushInterface.ACTION_UNREGISTER.equals(intent.getAction())){ String regId = bundle.getString(JPushInterface.EXTRA_REGISTRATION_ID); Log.d(TAG, "接收UnRegistration Id : " + regId); //send the UnRegistration Id to your server... } else if (JPushInterface.ACTION_MESSAGE_RECEIVED.equals(intent.getAction())) { Log.d(TAG, "接收到推送下来的自定义消息: " + bundle.getString(JPushInterface.EXTRA_MESSAGE)); } else if (JPushInterface.ACTION_NOTIFICATION_RECEIVED.equals(intent.getAction())) { Log.d(TAG, "接收到推送下来的通知"); int notifactionId = bundle.getInt(JPushInterface.EXTRA_NOTIFICATION_ID); Log.d(TAG, "接收到推送下来的通知的ID: " + notifactionId); } else if (JPushInterface.ACTION_NOTIFICATION_OPENED.equals(intent.getAction())) { Log.d(TAG, "用户点击打开了通知"); //打开自定义的Activity Intent i = new Intent(context, TestActivity.class); i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); context.startActivity(i); } else { Log.d(TAG, "Unhandled intent - " + intent.getAction()); } } // 打印所有的 intent extra 数据 private static String printBundle(Bundle bundle) { StringBuilder sb = new StringBuilder(); for (String key : bundle.keySet()) { if (key.equals(JPushInterface.EXTRA_NOTIFICATION_ID)) { sb.append("nkey:" + key + ", value:" + bundle.getInt(key)); } else { sb.append("nkey:" + key + ", value:" + bundle.getString(key)); } } return sb.toString(); } } |
4.自定义通知样式
定制声音、震动、闪灯等 Notification 样式。1 2 3 4 5 | 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; // 设置为铃声与震动都要 JPushInterface.setPushNotificationBuilder(1, builder); |
5.高级自定义通知样式
基于基础的 PushNotificationBuilder,可进一步地定制 Notification 的 Layout。1 2 3 4 5 | CustomPushNotificationBuilder builder = new CustomPushNotificationBuilder(MainActivity.this, R.layout.customer_notitfication_layout, R.id.icon, R.id.title, R.id.text); // 指定定制的 Notification Layout builder.statusBarDrawable = R.drawable.your_notification_icon; // 指定最顶层状态栏小图标 builder.layoutIconDrawable = R.drawable.your_2_notification_icon; // 指定下拉状态栏时显示的通知图标 JPushInterface.setPushNotificationBuilder(2, builder); |
6.设置保留最近通知条数
默认5条1 | public static void setLatestNotifactionNumber(Context context, int maxNum) |
7.设置允许推送时间
1 | public static void setPushTime(Context context, Set<Integer> weekDays, int startHour, int int endHour) |
Context context 应用的ApplicationContext
Set days 0表示星期天,1表示星期一,以此类推。 (7天制,Set集合里面的int范围为0到6)
Sdk1.2.9 – 新功能:set的值为null,则任何时间都可以收到消息和通知,set的size为0,则表示任何时间都收不到消息和通知.
int startHour 允许推送的开始时间 (24小时制:startHour的范围为0到23)
int endHour 允许推送的结束时间 (24小时制:endHour的范围为0到23)
8.别名与标签
1 | public static void setAliasAndTags(Context context, String alias, Set<String> tags) |
需要理解的是,**这个接口是覆盖逻辑,而不是增量逻辑。即新的调用会覆盖之前的设置。**
在之前调用过后,如果需要再次改变别名与标签,只需要重新调用此 API 即可。
Android 在调用此接口时,建议 Set 的实现使用LinkedHashSet,即会保证排序的 Set。这样,当你调用接口 tags 多于 100
个时,保证前 100 个被 JPush 成功地设置。
参数定义
alias
null 此次调用不设置此值。(注:不是指的字符串"null")
"" (空字符串)表示取消之前的设置。
每次调用设置有效的别名,覆盖之前的设置。
有效的别名组成:字母(区分大小写)、数字、下划线、汉字。
限制:alias 命名长度限制为 40 。
tags
null 此次调用不设置此值。(注:不是指的字符串"null")
空数组或列表表示取消之前的设置。
每次调用至少设置一个 tag,覆盖之前的设置,不是新增。
有效的标签组成:字母(区分大小写)、数字、下划线、汉字。
限制:每个 tag 命名长度限制为 40,最多支持设置 100 个 tag,但总长度不得超过1K字节。
9.通知与自定义消息
通知或者说 Push Notification,即指在手机的通知栏(状态栏)上会显示的一条通知信息。这是 Android / iOS 的基本功能。
一条通知,简单的填写纯文本的通知内容即可。
通知主要用于提示用户的目的。应用加上通知功能,有利于提高应用的活跃度。
自定义消息
是极光推送自己的概念。
自定义消息不是通知,所以不会被SDK展示到通知栏上。其内容完全由开发者自己定义。
自定义消息主要用于应用的内部业务逻辑。一条自定义消息推送过来,有可能没有任何界面显示。
相关文章推荐
- ora-28001 the password has expired......oracle11g数据库密码过期
- ANDROID application详解与用法
- INSERT ... ON DUPLICATE KEY UPDATE
- sprig——jar包
- 《OD大数据实战》Flume环境搭建
- 梯度下降三种形式
- 超有爱的并查集
- 跳转到AppStore中应用页面
- FFmpeg移植Android编译生成单个库
- placehoder点击文字消失
- 【数据结构与算法学习笔记】PART3 线性结构(除向量外,数组、栈、队列、链表)
- Runtime系列(消息转发)
- Gym 100818F Irrational Roots
- 给定一个链表,链表的每一个节点包含三个属性:1、节点值;2、指向下一个结点的引用;3、随机指向链表内任意一个节点的引用,也能不指向任何节点。复制该链表
- Hive中小表与大表关联(join)的性能分析
- PTAM学习笔记(一)---PTAM在windows上的编译
- 趣味问题——提灯过桥问题
- 几个性能测试工具
- UDP广域网,局域网通信-原理分析,穿透技术
- iOS判断是否插入耳机