mirror of
https://github.com/jpush/jpush-phonegap-plugin.git
synced 2025-02-20 20:22:50 +08:00
Add jpush.receiveRegistrationId event.
This commit is contained in:
parent
20ab9319bc
commit
390fbb9fda
@ -14,6 +14,18 @@
|
||||
- [本地通知](#本地通知)
|
||||
- [富媒体页面 JavaScript 回调 API](#富媒体页面-javascript-回调-api)
|
||||
|
||||
## 注册成功事件
|
||||
### jpush.receiveRegistrationId
|
||||
集成了 JPush SDK 的应用程序在第一次成功注册到 JPush 服务器时,JPush 服务器会给客户端返回一个唯一的该设备的标识 - RegistrationID。
|
||||
就会触发这个事件(注意只有第一次会触发该事件,之后如果想要取到 registrationId,可以直接调用 *getRegistrationID* 方法)。
|
||||
|
||||
#### 代码示例
|
||||
```Javascript
|
||||
document.addEventListener('jpush.receiveRegistrationId', function (event) {
|
||||
console.log(event.registrationId)
|
||||
}, false)
|
||||
```
|
||||
|
||||
## 接收通知时获得通知的内容
|
||||
|
||||
- 内容:
|
||||
@ -55,7 +67,6 @@
|
||||
- true 显示集成日志。
|
||||
- false 不显示集成日志。
|
||||
|
||||
|
||||
## 接收消息和点击通知事件
|
||||
### API - receiveMessageInAndroidCallback
|
||||
|
||||
@ -82,7 +93,6 @@
|
||||
|
||||
- data: js 字符串。
|
||||
|
||||
|
||||
## 统计分析
|
||||
|
||||
### API - onResume / onPause
|
||||
|
@ -262,6 +262,26 @@ public class JPushPlugin extends CordovaPlugin {
|
||||
JPushPlugin.notificationAlert = null;
|
||||
}
|
||||
|
||||
static void transmitReceiveRegistrationId(String rId) {
|
||||
if (instance == null) {
|
||||
return;
|
||||
}
|
||||
JSONObject data = new JSONObject();
|
||||
try {
|
||||
data.put("registrationId", rId);
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
String format = "window.plugins.jPushPlugin.receiveRegistrationIdInAndroidCallback(%s);";
|
||||
final String js = String.format(format, data.toString());
|
||||
cordovaActivity.runOnUiThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
instance.webView.loadUrl("javascript:" + js);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(final String action, final JSONArray data,
|
||||
final CallbackContext callbackContext) throws JSONException {
|
||||
|
@ -1,18 +1,18 @@
|
||||
package cn.jpush.phonegap;
|
||||
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import cn.jpush.android.api.JPushInterface;
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.util.Log;
|
||||
|
||||
public class MyReceiver extends BroadcastReceiver {
|
||||
private static String TAG = "JPushPlugin";
|
||||
|
||||
private static final List<String> IGNORED_EXTRAS_KEYS =
|
||||
Arrays.asList(
|
||||
"cn.jpush.android.TITLE",
|
||||
@ -24,18 +24,15 @@ public class MyReceiver extends BroadcastReceiver {
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
String action = intent.getAction();
|
||||
if (JPushInterface.ACTION_MESSAGE_RECEIVED.equals(action)) {
|
||||
if (action.equals(JPushInterface.ACTION_REGISTRATION_ID)) {
|
||||
String rId = intent.getStringExtra(JPushInterface.EXTRA_REGISTRATION_ID);
|
||||
JPushPlugin.transmitReceiveRegistrationId(rId);
|
||||
} else if (action.equals(JPushInterface.ACTION_MESSAGE_RECEIVED)) {
|
||||
handlingMessageReceive(intent);
|
||||
} else if (JPushInterface.ACTION_NOTIFICATION_RECEIVED.equals(action)) {
|
||||
} else if (action.equals(JPushInterface.ACTION_NOTIFICATION_RECEIVED)) {
|
||||
handlingNotificationReceive(context, intent);
|
||||
} else if (JPushInterface.ACTION_NOTIFICATION_OPENED.equals(action)) {
|
||||
} else if (action.equals(JPushInterface.ACTION_NOTIFICATION_OPENED)) {
|
||||
handlingNotificationOpen(context, intent);
|
||||
} else if (JPushInterface.ACTION_RICHPUSH_CALLBACK.equals(action)) {
|
||||
// 当在 HTML 页面中调用 JPushWeb.triggerNativeAction(String params) 方法时触发此方法,
|
||||
// 再进行相关的操作。
|
||||
|
||||
} else {
|
||||
Log.d(TAG, "Unhandled intent - " + action);
|
||||
}
|
||||
}
|
||||
|
||||
@ -46,8 +43,6 @@ public class MyReceiver extends BroadcastReceiver {
|
||||
}
|
||||
|
||||
private void handlingNotificationOpen(Context context, Intent intent) {
|
||||
Log.i(TAG, "---------------- handlingNotificationOpen");
|
||||
|
||||
String title = intent.getStringExtra(JPushInterface.EXTRA_NOTIFICATION_TITLE);
|
||||
JPushPlugin.openNotificationTitle = title;
|
||||
|
||||
@ -60,15 +55,13 @@ public class MyReceiver extends BroadcastReceiver {
|
||||
JPushPlugin.transmitNotificationOpen(title, alert, extras);
|
||||
|
||||
Intent launch = context.getPackageManager().getLaunchIntentForPackage(
|
||||
context.getPackageName());
|
||||
context.getPackageName());
|
||||
launch.addCategory(Intent.CATEGORY_LAUNCHER);
|
||||
launch.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_SINGLE_TOP);
|
||||
context.startActivity(launch);
|
||||
}
|
||||
|
||||
private void handlingNotificationReceive(Context context, Intent intent) {
|
||||
Log.i(TAG, "---------------- handlingNotificationReceive");
|
||||
|
||||
Intent launch = context.getPackageManager().getLaunchIntentForPackage(
|
||||
context.getPackageName());
|
||||
launch.addCategory(Intent.CATEGORY_LAUNCHER);
|
||||
@ -99,5 +92,4 @@ public class MyReceiver extends BroadcastReceiver {
|
||||
}
|
||||
return extrasMap;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -217,6 +217,14 @@ JPushPlugin.prototype.setCustomPushNotificationBuilder = function () {
|
||||
}
|
||||
}
|
||||
|
||||
JPushPlugin.prototype.receiveRegistrationIdInAndroidCallback = function (data) {
|
||||
if (device.platform === 'Android') {
|
||||
data = JSON.stringify(data)
|
||||
var event = JSON.parse(data)
|
||||
cordova.fireDocumentEvent('jpush.receiveRegistrationId', event);
|
||||
}
|
||||
}
|
||||
|
||||
JPushPlugin.prototype.receiveMessageInAndroidCallback = function (data) {
|
||||
data = JSON.stringify(data)
|
||||
console.log('JPushPlugin:receiveMessageInAndroidCallback: ' + data)
|
||||
|
Loading…
Reference in New Issue
Block a user