From b02e3faef0190b553923299fbfccbf1ccab5ce05 Mon Sep 17 00:00:00 2001 From: Hevin <328066446@qq.com> Date: Mon, 18 Apr 2016 21:35:43 +0800 Subject: [PATCH] add new API & update doc MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 添加设置允许推送时间和设置通知静默时间的 API --- API/Android_detail_api.md | 39 +++++++++++++++++++++++++--- src/android/JPushPlugin.java | 50 +++++++++++++++++------------------- www/JPushPlugin.js | 12 +++++++-- 3 files changed, 69 insertions(+), 32 deletions(-) diff --git a/API/Android_detail_api.md b/API/Android_detail_api.md index 8956404..01041b7 100644 --- a/API/Android_detail_api.md +++ b/API/Android_detail_api.md @@ -83,8 +83,8 @@ ####接口定义 - public static void onResume(final Activity activity) - public static void onPause(final Activity activity) + public static void onResume(final Activity activity) + public static void onPause(final Activity activity) ####参数说明 @@ -147,12 +147,45 @@ ##### 接口定义 - window.plugins.jPushPlugin.clearAllNotification = function() + window.plugins.jPushPlugin.clearAllNotification() ### 设置允许推送时间 API + +#### API - setPushTime +默认情况下用户在任何时间都允许推送。即任何时候有推送下来,客户端都会收到,并展示。 +开发者可以调用此 API 来设置允许推送的时间。 +如果不在该时间段内收到消息,当前的行为是:推送到的通知会被扔掉。 + +##### 接口定义 + + window.plugins.jPushPlugin.setPushTime(days, startHour, endHour) + +##### 参数说明 +- days: 数组 0表示星期天,1表示星期一,以此类推。 (7天制,数组中的int范围为0到6)set的值为null, 表示任何时间都可以收到消息和通知,set的size为0,则表示任何时间都收不到消息和通知. +- startHour: int 允许推送的开始时间 (24小时制:startHour的范围为0到23) +- endHour: int 允许推送的结束时间 (24小时制:endHour的范围为0到23) + ### 设置通知静默时间 API + +#### API - setSilenceTime +默认情况下用户在收到推送通知时,客户端可能会有震动,响铃等提示。但用户在睡觉、开会等时间点希望为 "免打扰" 模式,也是静音时段的概念。 +开发者可以调用此 API 来设置静音时段。如果在该时间段内收到消息,则:不会有铃声和震动。 + +##### 接口定义 + + window.plugins.jPushPlugin.setSilenceTime(startHour, startMinute, endHour, endMinute) + +##### 参数说明 + +- startHour: int 静音时段的开始时间 - 小时 (24小时制,范围:0~23 ) +- startMinute: int 静音时段的开始时间 - 分钟(范围:0~59 ) +- endHour: 静音时段的结束时间 - 小时 (24小时制,范围:0~23 ) +- endMinute: 静音时段的结束时间 - 分钟(范围:0~59 ) + + ### 通知栏样式定制 API + #### API - setBasicPushNotificationBuilder, setCustomPushNotificationBuilder 当用户需要定制默认的通知栏样式时,则可调用此方法。 diff --git a/src/android/JPushPlugin.java b/src/android/JPushPlugin.java index 72d46f7..6aeded7 100644 --- a/src/android/JPushPlugin.java +++ b/src/android/JPushPlugin.java @@ -1,9 +1,6 @@ package cn.jpush.phonegap; import android.app.Activity; -import android.app.Notification; -import android.content.ComponentName; -import android.content.Intent; import android.content.Context; import android.util.Log; @@ -316,24 +313,23 @@ public class JPushPlugin extends CordovaPlugin { } void setPushTime(JSONArray data, CallbackContext callbackContext) { - Set days = new HashSet(); + Set days = null; JSONArray dayArray; int startHour = -1; int endHour = -1; try { - dayArray = data.getJSONArray(0); - for (int i = 0; i < dayArray.length(); i++) { - days.add(dayArray.getInt(i)); + dayArray = data.isNull(0) ? null : data.getJSONArray(0); + if (dayArray != null) { + days = new HashSet(); + for (int i = 0; i < dayArray.length(); i++) { + days.add(dayArray.getInt(i)); + } } - } catch (JSONException e) { - e.printStackTrace(); - callbackContext.error("error reading days json"); - } - try { startHour = data.getInt(1); endHour = data.getInt(2); } catch (JSONException e) { - callbackContext.error("error reading hour json"); + e.printStackTrace(); + callbackContext.error("error reading data json"); } Context context = cordovaActivity.getApplicationContext(); JPushInterface.setPushTime(context, days, startHour, endHour); @@ -508,20 +504,20 @@ public class JPushPlugin extends CordovaPlugin { */ void setSilenceTime(JSONArray data, CallbackContext callbackContext) { try { - int startHour = data.getInt(0); - int startMinute = data.getInt(1); - int endHour = data.getInt(2); - int endMinute = data.getInt(3); - if (!isValidHour(startHour) || !isValidMinute(startMinute)) { - callbackContext.error("开始时间数值错误"); - return; - } - if(!isValidHour(endHour) || !isValidMinute(endMinute)) { - callbackContext.error("结束时间数值错误"); - return; - } - JPushInterface.setSilenceTime(cordovaActivity, startHour, startMinute, - endHour, endMinute); + int startHour = data.getInt(0); + int startMinute = data.getInt(1); + int endHour = data.getInt(2); + int endMinute = data.getInt(3); + if (!isValidHour(startHour) || !isValidMinute(startMinute)) { + callbackContext.error("开始时间数值错误"); + return; + } + if(!isValidHour(endHour) || !isValidMinute(endMinute)) { + callbackContext.error("结束时间数值错误"); + return; + } + JPushInterface.setSilenceTime(cordovaActivity, startHour, startMinute, + endHour, endMinute); } catch (JSONException e) { e.printStackTrace(); callbackContext.error("error: reading json data."); diff --git a/www/JPushPlugin.js b/www/JPushPlugin.js index 6fa846b..64d273c 100644 --- a/www/JPushPlugin.js +++ b/www/JPushPlugin.js @@ -340,8 +340,16 @@ JPushPlugin.prototype.requestPermission = function() { } } -JPushPlugin.prototype.setSilenceTime = function() { - +JPushPlugin.prototype.setSilenceTime = function(startHour, startMinute, endHour, endMinute) { + if (device.platform == "Android") { + this.call_native("setSilenceTime", [startHour, startMinute, endHour, endMinute], null); + } +} + +JPushPlugin.prototype.setPushTime = function(weekdays, startHour, endHour) { + if (device.platform == "Android") { + this.call_native("setPushTime", [weekdays, startHour, endHour], null); + } } if(!window.plugins) {