@@ -218,6 +218,12 @@ public void setStyleCustom() {
218
218
Logger .toast (mContext , "Custom Builder - 2" );
219
219
}
220
220
221
+ /**
222
+ * Get registration id, different from JPushModule.addGetRegistrationIdListener, this
223
+ * method has no calling limits.
224
+ *
225
+ * @param callback callback with registrationId
226
+ */
221
227
@ ReactMethod
222
228
public void getRegistrationID (Callback callback ) {
223
229
try {
@@ -229,11 +235,19 @@ public void getRegistrationID(Callback callback) {
229
235
}
230
236
}
231
237
238
+ /**
239
+ * Clear all notifications, suggest invoke this method while exiting app.
240
+ */
232
241
@ ReactMethod
233
242
public void clearAllNotifications () {
234
243
JPushInterface .clearAllNotifications (getReactApplicationContext ());
235
244
}
236
245
246
+ /**
247
+ * Clear specified notification
248
+ *
249
+ * @param id the notification id
250
+ */
237
251
@ ReactMethod
238
252
public void clearNotificationById (String id ) {
239
253
try {
@@ -295,45 +309,52 @@ public void onReceive(Context context, Intent data) {
295
309
} else if (JPushInterface .ACTION_NOTIFICATION_OPENED .equals (data .getAction ())) {
296
310
try {
297
311
Logger .d (TAG , "用户点击打开了通知" );
312
+ if (mRAC == null ) {
313
+ Log .e (TAG , "mRAC is null!" );
314
+ mModule = new JPushModule ((ReactApplicationContext ) context );
315
+ Log .d (TAG , "mRAC is null ? " + (mRAC == null ));
316
+ }
298
317
// 通知内容
299
318
String alertContent = bundle .getString (JPushInterface .EXTRA_ALERT );
300
319
// extra 字段的 json 字符串
301
320
String extras = bundle .getString (JPushInterface .EXTRA_EXTRA );
302
321
WritableMap map = Arguments .createMap ();
303
322
map .putString ("alertContent" , alertContent );
304
323
map .putString ("extras" , extras );
305
- mRAC .getJSModule (DeviceEventManagerModule .RCTDeviceEventEmitter .class )
306
- .emit ("openNotification" , map );
324
+ map .putString ("jumpTo" , "second" );
307
325
// judge if application is running in background, opening initial Activity.
308
326
// You can change here to open appointed Activity. All you need to do is create
309
327
// the appointed Activity, and use JS render the appointed Activity.
310
328
// Please reference examples' SecondActivity for detail,
311
329
// and JS files are in folder: example/react-native-android
312
- if (isApplicationRunningBackground (context )) {
313
- Intent intent = new Intent ();
314
- intent .setClass (context , mModule .mContext .getClass ());
315
- Logger .d (TAG , "context.getClass: " + mModule .mContext .getClass ());
316
- intent .putExtras (bundle );
317
- intent .setFlags (Intent .FLAG_ACTIVITY_NEW_TASK
318
- | Intent .FLAG_ACTIVITY_CLEAR_TOP );
319
- context .startActivity (intent );
320
- // application running in foreground, do nothing
330
+ Intent intent = new Intent ();
331
+ intent .setClassName (context .getPackageName (), context .getPackageName () + ".MainActivity" );
332
+ intent .putExtras (bundle );
333
+ intent .setFlags (Intent .FLAG_ACTIVITY_NEW_TASK | Intent .FLAG_ACTIVITY_CLEAR_TOP );
334
+ context .startActivity (intent );
335
+ // 如果需要跳转到指定的界面,那么需要同时启动 MainActivity 及指定界面:
336
+ // If you need to open appointed Activity, you need to start MainActivity and
337
+ // appointed Activity at the same time.
338
+ // Intent detailIntent = new Intent();
339
+ // detailIntent.setClassName(context.getPackageName(), context.getPackageName() + ".SecondActivity");
340
+ // detailIntent.putExtras(bundle);
341
+ // Intent[] intents = {intent, detailIntent};
342
+ // 同时启动 MainActivity 以及 SecondActivity
343
+ // context.startActivities(intents);
344
+ if (mRAC != null ) {
345
+ Log .e (TAG , "Passing openNotification event" );
346
+ mRAC .getJSModule (DeviceEventManagerModule .RCTDeviceEventEmitter .class )
347
+ .emit ("openNotification" , map );
348
+ } else {
349
+ Log .e (TAG , "mRAC still null!" );
321
350
}
322
351
} catch (Exception e ) {
323
352
e .printStackTrace ();
324
- Logger .i (TAG , "Try to start application" );
325
- try {
326
- Intent intent = new Intent ();
327
- intent .setClassName (context .getPackageName (), context .getPackageName () + ".MainActivity" );
328
- intent .putExtras (bundle );
329
- intent .setFlags (Intent .FLAG_ACTIVITY_NEW_TASK | Intent .FLAG_ACTIVITY_CLEAR_TOP );
330
- context .startActivity (intent );
331
- } catch (Exception e1 ) {
332
- e1 .printStackTrace ();
333
- Logger .i (TAG , "Cannot find MainActivity, will discard onClick event." );
334
- }
353
+ Logger .i (TAG , "Shouldn't access here" );
335
354
}
336
-
355
+ // 应用注册完成后会发送广播,在 JS 中 JPushModule.addGetRegistrationIdListener 接口可以第一时间得到 registrationId
356
+ // After JPush finished registering, will send this broadcast, use JPushModule.addGetRegistrationIdListener
357
+ // to get registrationId in the first instance.
337
358
} else if (JPushInterface .ACTION_REGISTRATION_ID .equals (data .getAction ())) {
338
359
String registrationId = data .getExtras ().getString (JPushInterface .EXTRA_REGISTRATION_ID );
339
360
Logger .d (TAG , "注册成功, registrationId: " + registrationId );
0 commit comments