mirror of
https://github.com/jpush/jpush-phonegap-plugin.git
synced 2025-01-18 21:12:56 +08:00
add new API & update doc
添加设置允许推送时间和设置通知静默时间的 API
This commit is contained in:
parent
8b481ddd92
commit
b02e3faef0
@ -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
|
||||
|
||||
当用户需要定制默认的通知栏样式时,则可调用此方法。
|
||||
|
@ -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<Integer> days = new HashSet<Integer>();
|
||||
Set<Integer> 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<Integer>();
|
||||
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.");
|
||||
|
@ -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) {
|
||||
|
Loading…
Reference in New Issue
Block a user