forked from github/jpush-phonegap-plugin
optimize code & update doc
rename some functions name. format doc & make some instructions more clearer.
This commit is contained in:
parent
46b2a5ab1a
commit
b515caf1e4
@ -118,6 +118,8 @@ iOS:
|
|||||||
window.plugins.jPushPlugin.setTags(tags)
|
window.plugins.jPushPlugin.setTags(tags)
|
||||||
window.plugins.jPushPlugin.setAlias(alias)
|
window.plugins.jPushPlugin.setAlias(alias)
|
||||||
|
|
||||||
|
event - jpush.setTagsWithAlias //三个方法都是触发该回调事件
|
||||||
|
|
||||||
+ 获取点击通知内容
|
+ 获取点击通知内容
|
||||||
|
|
||||||
event - jpush.openNotification
|
event - jpush.openNotification
|
||||||
@ -137,10 +139,11 @@ iOS:
|
|||||||
|
|
||||||
+ 获取自定义消息推送内容
|
+ 获取自定义消息推送内容
|
||||||
|
|
||||||
event - jpush.receiveMessage
|
|
||||||
//推荐使用事件的方式传递,但同时保留了 receiveMessageIniOSCallback 的回调函数,兼容以前的代码
|
//推荐使用事件的方式传递,但同时保留了 receiveMessageIniOSCallback 的回调函数,兼容以前的代码
|
||||||
window.plugins.jPushPlugin.receiveMessageIniOSCallback(data)
|
window.plugins.jPushPlugin.receiveMessageIniOSCallback(data)
|
||||||
|
|
||||||
|
event - jpush.receiveMessage
|
||||||
|
|
||||||
+ 页面的统计
|
+ 页面的统计
|
||||||
|
|
||||||
window.plugins.jPushPlugin.startLogPageView(pageName)
|
window.plugins.jPushPlugin.startLogPageView(pageName)
|
||||||
@ -156,7 +159,8 @@ iOS:
|
|||||||
|
|
||||||
+ 本地通知
|
+ 本地通知
|
||||||
|
|
||||||
window.plugins.JPushPlugin.addLocalNotificationForIOS(delayTime, content, badge, notificationID, extras)
|
window.plugins.JPushPlugin.addLocalNotificationForIOS(delayTime, content,
|
||||||
|
badge, notificationID, extras)
|
||||||
window.plugins.JPushPlugin.deleteLocalNotificationWithIdentifierKeyInIOS()
|
window.plugins.JPushPlugin.deleteLocalNotificationWithIdentifierKeyInIOS()
|
||||||
window.plugins.JPushPlugin.clearAllLocalNotifications()
|
window.plugins.JPushPlugin.clearAllLocalNotifications()
|
||||||
|
|
||||||
@ -231,6 +235,5 @@ iOS:
|
|||||||
IsProduction: 是否生产环境(暂未启用)
|
IsProduction: 是否生产环境(暂未启用)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
###更多
|
###更多
|
||||||
[JPush 官网文档](http://docs.jpush.io/)
|
[JPush 官网文档](http://docs.jpush.io/)
|
||||||
|
@ -1,12 +1,36 @@
|
|||||||
## Android API简介
|
## Android API简介
|
||||||
|
|
||||||
|
|
||||||
|
### 接收通知时获得通知的信息
|
||||||
|
|
||||||
|
- 内容
|
||||||
|
window.plugins.jPushPlugin.receiveNotification.alert;
|
||||||
|
- 标题
|
||||||
|
window.plugins.jPushPlugin.receiveNotification.title;
|
||||||
|
- 附加字段
|
||||||
|
window.plugins.jPushPlugin.receiveNotification.extras.yourKey;
|
||||||
|
|
||||||
|
### 打开通知时获得通知的信息
|
||||||
|
|
||||||
|
- 内容
|
||||||
|
window.plugins.jPushPlugin.openNotification.alert;
|
||||||
|
- 标题
|
||||||
|
window.plugins.jPushPlugin.openNotification.title;
|
||||||
|
- 附加字段
|
||||||
|
window.plugins.jPushPlugin.openNotification.extras.yourKey;
|
||||||
|
|
||||||
|
### 收到自定义消息时获得通知的信息
|
||||||
|
|
||||||
|
- 内容
|
||||||
|
window.plugins.jPushPlugin.openNotification.message;
|
||||||
|
- 附加字段
|
||||||
|
window.plugins.jPushPlugin.openNotification.extras.yourKey;
|
||||||
|
|
||||||
### 获取集成日志
|
### 获取集成日志
|
||||||
|
|
||||||
#### API - setDebugMode
|
#### API - setDebugMode
|
||||||
|
|
||||||
用于开启调试模式,可以查看集成 JPush 过程中的 Log,如果集成失败,可方便定位问题所在
|
用于开启调试模式,可以查看集成 JPush 过程中的 Log,如果集成失败,可方便定位问题所在。
|
||||||
|
|
||||||
##### 接口定义
|
##### 接口定义
|
||||||
|
|
||||||
@ -23,27 +47,28 @@
|
|||||||
### 接收消息和点击通知事件
|
### 接收消息和点击通知事件
|
||||||
#### API - receiveMessageInAndroidCallback
|
#### API - receiveMessageInAndroidCallback
|
||||||
|
|
||||||
用于 Android 收到应用内消息的回调函数(请注意和通知的区别),该函数不需要主动调用
|
用于 Android 收到应用内消息的回调函数(请注意和通知的区别),该函数不需要主动调用。
|
||||||
|
|
||||||
##### 接口定义
|
##### 接口定义
|
||||||
|
|
||||||
window.plugins.jPushPlugin.receiveMessageInAndroidCallback = function(data)
|
window.plugins.jPushPlugin.receiveMessageInAndroidCallback = function(data)
|
||||||
|
|
||||||
##### 参数说明
|
##### 参数说明
|
||||||
- data 接收到的 js 字符串,包含的 key:value 请进入该函数体查看
|
|
||||||
|
- data 接收到的 js 字符串,包含的 key:value 请进入该函数体查看。
|
||||||
|
|
||||||
##### 代码示例
|
##### 代码示例
|
||||||
|
|
||||||
#### API - openNotificationInAndroidCallback
|
#### API - openNotificationInAndroidCallback
|
||||||
|
|
||||||
当点击 Android 手机的通知栏进入应用程序时,会调用这个函数,这个函数不需要主动调用,是作为回调函数来用的
|
当点击 Android 手机的通知栏进入应用程序时,会调用这个函数,这个函数不需要主动调用,是作为回调函数来用的。
|
||||||
|
|
||||||
|
|
||||||
##### 接口定义
|
##### 接口定义
|
||||||
|
|
||||||
window.plugins.jPushPlugin.openNotificationInAndroidCallback = function(data)
|
window.plugins.jPushPlugin.openNotificationInAndroidCallback = function(data)
|
||||||
|
|
||||||
##### 参数说明
|
##### 参数说明
|
||||||
|
|
||||||
- data js字符串
|
- data js字符串
|
||||||
|
|
||||||
##### 代码示例
|
##### 代码示例
|
||||||
@ -51,18 +76,20 @@
|
|||||||
### 统计分析 API
|
### 统计分析 API
|
||||||
|
|
||||||
#### API - onResume / onPause
|
#### API - onResume / onPause
|
||||||
这是一个 android local api,不是 js 的 API,请注意
|
|
||||||
本 API 用于“用户使用时长”,“活跃用户”,“用户打开次数”的统计,并上报到服务器,在 Portal 上展示给开发者。
|
|
||||||
|
|
||||||
|
这是一个 Android Local API,不是 js 的 API,请注意
|
||||||
|
本 API 用于“用户使用时长”,“活跃用户”,“用户打开次数”的统计,并上报到服务器,在 Portal 上展示给开发者。
|
||||||
|
|
||||||
|
|
||||||
####接口定义
|
####接口定义
|
||||||
|
|
||||||
public static void onResume(final Activity activity)
|
public static void onResume(final Activity activity)
|
||||||
public static void onPause(final Activity activity)
|
public static void onPause(final Activity activity)
|
||||||
|
|
||||||
####参数说明
|
####参数说明
|
||||||
|
|
||||||
+ Activity activity 当前所在的 Activity。
|
+ Activity 当前所在的 Activity。
|
||||||
|
|
||||||
####调用说明
|
####调用说明
|
||||||
|
|
||||||
应在所有的 Activity 的 onResume / onPause 方法里调用。
|
应在所有的 Activity 的 onResume / onPause 方法里调用。
|
||||||
@ -74,6 +101,7 @@
|
|||||||
super.onResume();
|
super.onResume();
|
||||||
JPushInterface.onResume(this);
|
JPushInterface.onResume(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onPause() {
|
protected void onPause() {
|
||||||
super.onPause();
|
super.onPause();
|
||||||
@ -90,6 +118,7 @@
|
|||||||
window.plugins.jPushPlugin.setStatisticsOpen(boolean)
|
window.plugins.jPushPlugin.setStatisticsOpen(boolean)
|
||||||
|
|
||||||
#### 参数说明
|
#### 参数说明
|
||||||
|
|
||||||
- boolean
|
- boolean
|
||||||
- true : 打开统计分析功能
|
- true : 打开统计分析功能
|
||||||
- false: 关闭统计分析功能
|
- false: 关闭统计分析功能
|
||||||
@ -98,7 +127,6 @@
|
|||||||
|
|
||||||
用于上报用户的通知栏被打开,或者用于上报用户自定义消息被展示等客户端需要统计的事件。
|
用于上报用户的通知栏被打开,或者用于上报用户自定义消息被展示等客户端需要统计的事件。
|
||||||
|
|
||||||
|
|
||||||
##### 接口定义
|
##### 接口定义
|
||||||
|
|
||||||
window.plugins.jPushPlugin.reportNotificationOpened(msgID)
|
window.plugins.jPushPlugin.reportNotificationOpened(msgID)
|
||||||
@ -114,7 +142,7 @@
|
|||||||
|
|
||||||
推送通知到客户端时,由 JPush SDK 展现通知到通知栏上。
|
推送通知到客户端时,由 JPush SDK 展现通知到通知栏上。
|
||||||
|
|
||||||
此 API 提供清除通知的功能,包括:清除所有 JPush 展现的通知(不包括非 JPush SDK 展现的)
|
此 API 提供清除通知的功能,包括:清除所有 JPush 展现的通知(不包括非 JPush SDK 展现的)。
|
||||||
|
|
||||||
|
|
||||||
##### 接口定义
|
##### 接口定义
|
||||||
@ -131,9 +159,9 @@
|
|||||||
极光 Push SDK 提供了 2 个用于定制通知栏样式的构建类:
|
极光 Push SDK 提供了 2 个用于定制通知栏样式的构建类:
|
||||||
|
|
||||||
- setBasicPushNotificationBuilder
|
- setBasicPushNotificationBuilder
|
||||||
- Basic 用于定制 Android Notification 里的 defaults / flags / icon 等基础样式(行为)
|
- Basic 用于定制 Android Notification 里的 defaults / flags / icon 等基础样式(行为)。
|
||||||
- setCustomPushNotificationBuilder
|
- setCustomPushNotificationBuilder
|
||||||
- 继承 Basic 进一步让开发者定制 Notification Layout
|
- 继承 Basic 进一步让开发者定制 Notification Layout。
|
||||||
|
|
||||||
如果不调用此方法定制,则极光 Push SDK 默认的通知栏样式是:Android 标准的通知栏提示。
|
如果不调用此方法定制,则极光 Push SDK 默认的通知栏样式是:Android 标准的通知栏提示。
|
||||||
|
|
||||||
@ -166,14 +194,14 @@
|
|||||||
#### API - addLocalNotification,removeLocalNotification,clearLocalNotifications
|
#### API - addLocalNotification,removeLocalNotification,clearLocalNotifications
|
||||||
|
|
||||||
|
|
||||||
本地通知 API 不依赖于网络,无网条件下依旧可以触发
|
本地通知 API 不依赖于网络,无网条件下依旧可以触发。
|
||||||
|
|
||||||
本地通知与网络推送的通知是相互独立的,不受保留最近通知条数上限的限制
|
本地通知与网络推送的通知是相互独立的,不受保留最近通知条数上限的限制。
|
||||||
|
|
||||||
本地通知的定时时间是自发送时算起的,不受中间关机等操作的影响
|
本地通知的定时时间是自发送时算起的,不受中间关机等操作的影响。
|
||||||
|
|
||||||
|
|
||||||
三个接口的功能分别为:添加一个本地通知,删除一个本地通知,删除所有的本地通知
|
三个接口的功能分别为:添加一个本地通知,删除一个本地通知,删除所有的本地通知。
|
||||||
|
|
||||||
#####接口定义
|
#####接口定义
|
||||||
|
|
||||||
@ -184,9 +212,9 @@
|
|||||||
|
|
||||||
##### 参数说明
|
##### 参数说明
|
||||||
|
|
||||||
- builderId 设置本地通知样式
|
- builderId 设置本地通知样式。
|
||||||
- content 设置本地通知的 content
|
- content 设置本地通知的 content。
|
||||||
- title 设置本地通知的 title
|
- title 设置本地通知的 title。
|
||||||
- notificaitonID 设置本地通知的 ID
|
- notificaitonID 设置本地通知的 ID。
|
||||||
- broadcastTime 设置本地通知触发时间,为距离当前时间的数值,单位是毫秒
|
- broadcastTime 设置本地通知触发时间,为距离当前时间的数值,单位是毫秒。
|
||||||
- extras 设置额外的数据信息 extras 为 json 字符串
|
- extras 设置额外的数据信息 extras 为 json 字符串。
|
||||||
|
@ -14,9 +14,9 @@
|
|||||||
initiateUI();
|
initiateUI();
|
||||||
};
|
};
|
||||||
|
|
||||||
function getRegistrationID() {
|
var getRegistrationID = function() {
|
||||||
window.plugins.jPushPlugin.getRegistrationID(onGetRegistradionID);
|
window.plugins.jPushPlugin.getRegistrationID(onGetRegistrationID);
|
||||||
}
|
};
|
||||||
|
|
||||||
var onGetRegistrationID = function(data) {
|
var onGetRegistrationID = function(data) {
|
||||||
try {
|
try {
|
||||||
@ -25,7 +25,7 @@
|
|||||||
if (data.length == 0) {
|
if (data.length == 0) {
|
||||||
var t1 = window.setTimeout(getRegistrationID, 1000);
|
var t1 = window.setTimeout(getRegistrationID, 1000);
|
||||||
}
|
}
|
||||||
$("#registrationid").html(data);
|
$("#registrationId").html(data);
|
||||||
} catch (exception) {
|
} catch (exception) {
|
||||||
console.log(exception);
|
console.log(exception);
|
||||||
}
|
}
|
||||||
@ -105,18 +105,18 @@
|
|||||||
var tag2 = $("#tagText2").attr("value");
|
var tag2 = $("#tagText2").attr("value");
|
||||||
var tag3 = $("#tagText3").attr("value");
|
var tag3 = $("#tagText3").attr("value");
|
||||||
var alias = $("#aliasText").attr("value");
|
var alias = $("#aliasText").attr("value");
|
||||||
var dd = [];
|
var tags = [];
|
||||||
|
|
||||||
if (tag1 != "") {
|
if (tag1 != "") {
|
||||||
dd.push(tag1);
|
tags.push(tag1);
|
||||||
}
|
}
|
||||||
if (tag2 != "") {
|
if (tag2 != "") {
|
||||||
dd.push(tag2);
|
tags.push(tag2);
|
||||||
}
|
}
|
||||||
if (tag3 != "") {
|
if (tag3 != "") {
|
||||||
dd.push(tag3);
|
tags.push(tag3);
|
||||||
}
|
}
|
||||||
window.plugins.jPushPlugin.setTagsWithAlias(dd, alias);
|
window.plugins.jPushPlugin.setTagsWithAlias(tags, alias);
|
||||||
} catch (exception) {
|
} catch (exception) {
|
||||||
console.log(exception);
|
console.log(exception);
|
||||||
}
|
}
|
||||||
@ -143,7 +143,7 @@
|
|||||||
<span name="alias" id="alias"></span>
|
<span name="alias" id="alias"></span>
|
||||||
<hr/>
|
<hr/>
|
||||||
<label>RegistrationID: </label>
|
<label>RegistrationID: </label>
|
||||||
<label id="registrationid">null</label>
|
<label id="registrationId">null</label>
|
||||||
</div>
|
</div>
|
||||||
<div data-role="fieldcontain">
|
<div data-role="fieldcontain">
|
||||||
<label>Tags: </label>
|
<label>Tags: </label>
|
||||||
@ -174,7 +174,8 @@
|
|||||||
</table>
|
</table>
|
||||||
</div>
|
</div>
|
||||||
<div data-role="fieldcontain">
|
<div data-role="fieldcontain">
|
||||||
<input type="button" id="setTagWithAliasButton" value="Add tag and alias" />
|
<input type="button" id="setTagWithAliasButton"
|
||||||
|
value="Add tag and alias" />
|
||||||
</div>
|
</div>
|
||||||
<div data-role="fieldcontain">
|
<div data-role="fieldcontain">
|
||||||
<label id="tagAliasPrompt">设置tag/alias结果:</label>
|
<label id="tagAliasPrompt">设置tag/alias结果:</label>
|
||||||
|
@ -86,26 +86,22 @@ public class JPushPlugin extends CordovaPlugin {
|
|||||||
public void initialize(CordovaInterface cordova, CordovaWebView webView) {
|
public void initialize(CordovaInterface cordova, CordovaWebView webView) {
|
||||||
super.initialize(cordova, webView);
|
super.initialize(cordova, webView);
|
||||||
|
|
||||||
Log.i(TAG, "---------------- initialize" + "-"
|
Log.i(TAG, "---------------- initialize" + "-" + openNotificationAlert
|
||||||
+ JPushPlugin.openNotificationAlert + "-"
|
+ "-" + notificationAlert);
|
||||||
+ JPushPlugin.notificationAlert);
|
|
||||||
|
|
||||||
cordovaActivity = this.cordova.getActivity();
|
cordovaActivity = this.cordova.getActivity();
|
||||||
|
|
||||||
//如果同时缓存了打开事件 openNotificationAlert 和 消息事件 notificationAlert,只向 UI 发打开事件。
|
//如果同时缓存了打开事件 openNotificationAlert 和 消息事件 notificationAlert,只向 UI 发打开事件。
|
||||||
//这样做是为了和iOS 统一
|
//这样做是为了和 iOS 统一。
|
||||||
if (JPushPlugin.openNotificationAlert != null) {
|
if (openNotificationAlert != null) {
|
||||||
JPushPlugin.notificationAlert = null;
|
notificationAlert = null;
|
||||||
JPushPlugin.transmitOpen(JPushPlugin.notificationTitle,
|
transmitNotificationOpen(notificationTitle, openNotificationAlert,
|
||||||
JPushPlugin.openNotificationAlert,
|
openNotificationExtras);
|
||||||
JPushPlugin.openNotificationExtras);
|
|
||||||
}
|
}
|
||||||
if (JPushPlugin.notificationAlert != null) {
|
if (notificationAlert != null) {
|
||||||
JPushPlugin.transmitReceive(JPushPlugin.notificationTitle,
|
transmitNotificationReceive(notificationTitle, notificationAlert,
|
||||||
JPushPlugin.notificationAlert,
|
notificationExtras);
|
||||||
JPushPlugin.notificationExtras);
|
|
||||||
}
|
}
|
||||||
//JPushInterface.init(cordova.getActivity().getApplicationContext());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onPause(boolean multitasking) {
|
public void onPause(boolean multitasking) {
|
||||||
@ -118,26 +114,23 @@ public class JPushPlugin extends CordovaPlugin {
|
|||||||
|
|
||||||
public void onResume(boolean multitasking) {
|
public void onResume(boolean multitasking) {
|
||||||
shouldCacheMsg = false;
|
shouldCacheMsg = false;
|
||||||
Log.i(TAG, "---------------- onResume" + "-"
|
Log.i(TAG, "---------------- onResume" + "-" + openNotificationAlert
|
||||||
+ JPushPlugin.openNotificationAlert + "-"
|
+ "-" + notificationAlert);
|
||||||
+ JPushPlugin.notificationAlert);
|
|
||||||
if (isStatisticsOpened && multitasking) {
|
if (isStatisticsOpened && multitasking) {
|
||||||
JPushInterface.onResume(cordovaActivity);
|
JPushInterface.onResume(cordovaActivity);
|
||||||
}
|
}
|
||||||
if (JPushPlugin.openNotificationAlert != null) {
|
if (openNotificationAlert != null) {
|
||||||
JPushPlugin.notificationAlert = null;
|
notificationAlert = null;
|
||||||
JPushPlugin.transmitOpen(JPushPlugin.notificationTitle,
|
transmitNotificationOpen(notificationTitle, openNotificationAlert,
|
||||||
JPushPlugin.openNotificationAlert,
|
openNotificationExtras);
|
||||||
JPushPlugin.openNotificationExtras);
|
|
||||||
}
|
}
|
||||||
if (JPushPlugin.notificationAlert != null) {
|
if (notificationAlert != null) {
|
||||||
JPushPlugin.transmitReceive(JPushPlugin.notificationTitle,
|
transmitNotificationReceive(notificationTitle, notificationAlert,
|
||||||
JPushPlugin.notificationAlert,
|
notificationExtras);
|
||||||
JPushPlugin.notificationExtras);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static JSONObject notificationObject(String message,
|
private static JSONObject getMessageObject(String message,
|
||||||
Map<String, Object> extras) {
|
Map<String, Object> extras) {
|
||||||
JSONObject data = new JSONObject();
|
JSONObject data = new JSONObject();
|
||||||
try {
|
try {
|
||||||
@ -150,7 +143,6 @@ public class JPushPlugin extends CordovaPlugin {
|
|||||||
Iterator keys = jo.keys();
|
Iterator keys = jo.keys();
|
||||||
while(keys.hasNext()) {
|
while(keys.hasNext()) {
|
||||||
key = keys.next().toString();
|
key = keys.next().toString();
|
||||||
Log.i(TAG, key);
|
|
||||||
jExtras.put(key, jo.getString(key));
|
jExtras.put(key, jo.getString(key));
|
||||||
}
|
}
|
||||||
jExtras.put("cn.jpush.android.EXTRA", jo);
|
jExtras.put("cn.jpush.android.EXTRA", jo);
|
||||||
@ -167,7 +159,7 @@ public class JPushPlugin extends CordovaPlugin {
|
|||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static JSONObject openNotificationObject(String title,
|
private static JSONObject getNotificationObject(String title,
|
||||||
String alert, Map<String, Object> extras) {
|
String alert, Map<String, Object> extras) {
|
||||||
JSONObject data = new JSONObject();
|
JSONObject data = new JSONObject();
|
||||||
try {
|
try {
|
||||||
@ -197,11 +189,11 @@ public class JPushPlugin extends CordovaPlugin {
|
|||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void transmitPush(String message, Map<String, Object> extras) {
|
static void transmitMessageReceive(String message, Map<String, Object> extras) {
|
||||||
if (instance == null) {
|
if (instance == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
JSONObject data = notificationObject(message, extras);
|
JSONObject data = getMessageObject(message, extras);
|
||||||
String format = "window.plugins.jPushPlugin.receiveMessageInAndroidCallback(%s);";
|
String format = "window.plugins.jPushPlugin.receiveMessageInAndroidCallback(%s);";
|
||||||
final String js = String.format(format, data.toString());
|
final String js = String.format(format, data.toString());
|
||||||
cordovaActivity.runOnUiThread(new Runnable() {
|
cordovaActivity.runOnUiThread(new Runnable() {
|
||||||
@ -212,14 +204,15 @@ public class JPushPlugin extends CordovaPlugin {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
static void transmitOpen(String title, String alert, Map<String, Object> extras) {
|
static void transmitNotificationOpen(String title, String alert,
|
||||||
|
Map<String, Object> extras) {
|
||||||
if (instance == null) {
|
if (instance == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (JPushPlugin.shouldCacheMsg) {
|
if (JPushPlugin.shouldCacheMsg) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
JSONObject data = openNotificationObject(title, alert, extras);
|
JSONObject data = getNotificationObject(title, alert, extras);
|
||||||
String format = "window.plugins.jPushPlugin.openNotificationInAndroidCallback(%s);";
|
String format = "window.plugins.jPushPlugin.openNotificationInAndroidCallback(%s);";
|
||||||
final String js = String.format(format, data.toString());
|
final String js = String.format(format, data.toString());
|
||||||
cordovaActivity.runOnUiThread(new Runnable() {
|
cordovaActivity.runOnUiThread(new Runnable() {
|
||||||
@ -232,11 +225,12 @@ public class JPushPlugin extends CordovaPlugin {
|
|||||||
JPushPlugin.openNotificationAlert = null;
|
JPushPlugin.openNotificationAlert = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void transmitReceive(String title, String alert, Map<String, Object> extras) {
|
static void transmitNotificationReceive(String title, String alert,
|
||||||
|
Map<String, Object> extras) {
|
||||||
if (instance == null) {
|
if (instance == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
JSONObject data = openNotificationObject(title, alert, extras);
|
JSONObject data = getNotificationObject(title, alert, extras);
|
||||||
String format = "window.plugins.jPushPlugin.receiveNotificationInAndroidCallback(%s);";
|
String format = "window.plugins.jPushPlugin.receiveNotificationInAndroidCallback(%s);";
|
||||||
final String js = String.format(format, data.toString());
|
final String js = String.format(format, data.toString());
|
||||||
cordovaActivity.runOnUiThread(new Runnable() {
|
cordovaActivity.runOnUiThread(new Runnable() {
|
||||||
@ -272,7 +266,6 @@ public class JPushPlugin extends CordovaPlugin {
|
|||||||
|
|
||||||
void init(JSONArray data, CallbackContext callbackContext) {
|
void init(JSONArray data, CallbackContext callbackContext) {
|
||||||
JPushInterface.init(cordovaActivity.getApplicationContext());
|
JPushInterface.init(cordovaActivity.getApplicationContext());
|
||||||
//callbackContext.success();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void setDebugMode(JSONArray data, CallbackContext callbackContext) {
|
void setDebugMode(JSONArray data, CallbackContext callbackContext) {
|
||||||
@ -416,24 +409,6 @@ public class JPushPlugin extends CordovaPlugin {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// void getNotification(JSONArray data, CallbackContext callBackContext) {
|
|
||||||
// String alert = JPushPlugin.notificationAlert;
|
|
||||||
// Map<String, String> extras = JPushPlugin.notificationExtras;
|
|
||||||
//
|
|
||||||
// JSONObject jsonData = new JSONObject();
|
|
||||||
// try {
|
|
||||||
// jsonData.put("message", alert);
|
|
||||||
// jsonData.put("extras", new JSONObject(extras));
|
|
||||||
// } catch (JSONException e) {
|
|
||||||
// e.printStackTrace();
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// callBackContext.success(jsonData);
|
|
||||||
//
|
|
||||||
// JPushPlugin.notificationAlert = "";
|
|
||||||
// JPushPlugin.notificationExtras = new HashMap<String, Obl>();
|
|
||||||
// }
|
|
||||||
|
|
||||||
void setBasicPushNotificationBuilder(JSONArray data,
|
void setBasicPushNotificationBuilder(JSONArray data,
|
||||||
CallbackContext callbackContext) {
|
CallbackContext callbackContext) {
|
||||||
BasicPushNotificationBuilder builder = new BasicPushNotificationBuilder(
|
BasicPushNotificationBuilder builder = new BasicPushNotificationBuilder(
|
||||||
@ -446,7 +421,6 @@ public class JPushPlugin extends CordovaPlugin {
|
|||||||
} catch (JSONException e) {
|
} catch (JSONException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
//callbackContext.success(obj);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void setCustomPushNotificationBuilder(JSONArray data,
|
void setCustomPushNotificationBuilder(JSONArray data,
|
||||||
@ -463,12 +437,10 @@ public class JPushPlugin extends CordovaPlugin {
|
|||||||
} catch (JSONException e) {
|
} catch (JSONException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
//callbackContext.success(obj);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void clearAllNotification(JSONArray data, CallbackContext callbackContext) {
|
void clearAllNotification(JSONArray data, CallbackContext callbackContext) {
|
||||||
JPushInterface.clearAllNotifications(cordovaActivity);
|
JPushInterface.clearAllNotifications(cordovaActivity);
|
||||||
//callbackContext.success();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void clearNotificationById(JSONArray data, CallbackContext callbackContext) {
|
void clearNotificationById(JSONArray data, CallbackContext callbackContext) {
|
||||||
@ -488,7 +460,6 @@ public class JPushPlugin extends CordovaPlugin {
|
|||||||
|
|
||||||
void addLocalNotification(JSONArray data, CallbackContext callbackContext)
|
void addLocalNotification(JSONArray data, CallbackContext callbackContext)
|
||||||
throws JSONException {
|
throws JSONException {
|
||||||
//builderId,content,title,notificaitonID,broadcastTime,extras
|
|
||||||
int builderId = data.getInt(0);
|
int builderId = data.getInt(0);
|
||||||
String content = data.getString(1);
|
String content = data.getString(1);
|
||||||
String title = data.getString(2);
|
String title = data.getString(2);
|
||||||
@ -519,8 +490,6 @@ public class JPushPlugin extends CordovaPlugin {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 决定是否启用统计分析功能。
|
* 决定是否启用统计分析功能。
|
||||||
* @param data
|
|
||||||
* @param callbackContext
|
|
||||||
*/
|
*/
|
||||||
void setStatisticsOpen(JSONArray data, CallbackContext callbackContext) {
|
void setStatisticsOpen(JSONArray data, CallbackContext callbackContext) {
|
||||||
try {
|
try {
|
||||||
|
@ -38,7 +38,7 @@ public class MyReceiver extends BroadcastReceiver {
|
|||||||
private void handlingReceivedMessage(Intent intent) {
|
private void handlingReceivedMessage(Intent intent) {
|
||||||
String msg = intent.getStringExtra(JPushInterface.EXTRA_MESSAGE);
|
String msg = intent.getStringExtra(JPushInterface.EXTRA_MESSAGE);
|
||||||
Map<String, Object> extras = getNotificationExtras(intent);
|
Map<String, Object> extras = getNotificationExtras(intent);
|
||||||
JPushPlugin.transmitPush(msg, extras);
|
JPushPlugin.transmitMessageReceive(msg, extras);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void handlingNotificationOpen(Context context, Intent intent) {
|
private void handlingNotificationOpen(Context context, Intent intent) {
|
||||||
@ -53,7 +53,7 @@ public class MyReceiver extends BroadcastReceiver {
|
|||||||
Map<String, Object> extras = getNotificationExtras(intent);
|
Map<String, Object> extras = getNotificationExtras(intent);
|
||||||
JPushPlugin.openNotificationExtras = extras;
|
JPushPlugin.openNotificationExtras = extras;
|
||||||
|
|
||||||
JPushPlugin.transmitOpen(title, alert, extras);
|
JPushPlugin.transmitNotificationOpen(title, alert, extras);
|
||||||
|
|
||||||
Intent launch = context.getPackageManager().getLaunchIntentForPackage(
|
Intent launch = context.getPackageManager().getLaunchIntentForPackage(
|
||||||
context.getPackageName());
|
context.getPackageName());
|
||||||
@ -79,14 +79,13 @@ public class MyReceiver extends BroadcastReceiver {
|
|||||||
Map<String, Object> extras = getNotificationExtras(intent);
|
Map<String, Object> extras = getNotificationExtras(intent);
|
||||||
JPushPlugin.notificationExtras = extras;
|
JPushPlugin.notificationExtras = extras;
|
||||||
|
|
||||||
JPushPlugin.transmitReceive(title, alert, extras);
|
JPushPlugin.transmitNotificationReceive(title, alert, extras);
|
||||||
}
|
}
|
||||||
|
|
||||||
private Map<String, Object> getNotificationExtras(Intent intent) {
|
private Map<String, Object> getNotificationExtras(Intent intent) {
|
||||||
Map<String, Object> extrasMap = new HashMap<String, Object>();
|
Map<String, Object> extrasMap = new HashMap<String, Object>();
|
||||||
for (String key : intent.getExtras().keySet()) {
|
for (String key : intent.getExtras().keySet()) {
|
||||||
if (!IGNORED_EXTRAS_KEYS.contains(key)) {
|
if (!IGNORED_EXTRAS_KEYS.contains(key)) {
|
||||||
Log.e("key", "key:" + key);
|
|
||||||
if (key.equals(JPushInterface.EXTRA_NOTIFICATION_ID)) {
|
if (key.equals(JPushInterface.EXTRA_NOTIFICATION_ID)) {
|
||||||
extrasMap.put(key, intent.getIntExtra(key, 0));
|
extrasMap.put(key, intent.getIntExtra(key, 0));
|
||||||
} else {
|
} else {
|
||||||
|
@ -295,9 +295,9 @@ JPushPlugin.prototype.setDebugMode = function(mode) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
JPushPlugin.prototype.addLocalNotification = function(builderId, content, title,
|
JPushPlugin.prototype.addLocalNotification = function(builderId, content, title,
|
||||||
notificaitonID, broadcastTime, extras) {
|
notificationID, broadcastTime, extras) {
|
||||||
if(device.platform == "Android") {
|
if(device.platform == "Android") {
|
||||||
data = [builderId, content, title, notificaitonID, broadcastTime, extras];
|
data = [builderId, content, title, notificationID, broadcastTime, extras];
|
||||||
this.call_native("addLocalNotification", data, null);
|
this.call_native("addLocalNotification", data, null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user