Skip to content
This repository was archived by the owner on Jan 14, 2025. It is now read-only.

Commit acac514

Browse files
authored
Merge pull request #1589 from ToneItUp/master
Add support for specifying a delegate FirebaseMessagingService
2 parents 7840574 + e89f75c commit acac514

File tree

2 files changed

+18
-5
lines changed

2 files changed

+18
-5
lines changed

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,6 @@ PushNotification.localNotification({
326326
priority: "high", // (optional) set notification priority, default: high
327327
visibility: "private", // (optional) set notification visibility, default: private
328328
importance: "high", // (optional) set notification importance, default: high
329-
allowWhileIdle: false, // (optional) set notification to work while on doze, default: false
330329
ignoreInForeground: false, // (optional) if true, the notification will not be visible when the app is in the foreground (useful for parity with how iOS notifications appear)
331330
shortcutId: "shortcut-id", // (optional) If this notification is duplicative of a Launcher shortcut, sets the id of the shortcut, in case the Launcher wants to hide the shortcut, default undefined
332331
channelId: "your-custom-channel-id", // (optional) custom channelId, if the channel doesn't exist, it will be created with options passed above (importance, vibration, sound). Once the channel is created, the channel will not be update. Make sure your channelId is different if you change these options. If you have created a custom channel, it will apply options of the channel.
@@ -364,6 +363,7 @@ PushNotification.localNotificationSchedule({
364363
//... You can use all the options from localNotifications
365364
message: "My Notification Message", // (required)
366365
date: new Date(Date.now() + 60 * 1000), // in 60 secs
366+
allowWhileIdle: false, // (optional) set notification to work while on doze, default: false
367367
});
368368
```
369369

@@ -489,9 +489,9 @@ PushNotification.channelBlocked(channel_id, function (blocked) {
489489
});
490490
```
491491

492-
### List channels
492+
### Delete channel
493493

494-
You can list available channels with:
494+
You can delete a channel with:
495495

496496
```js
497497
PushNotification.deleteChannel(channel_id);

android/src/main/java/com/dieam/reactnativepushnotification/modules/RNPushNotificationListenerService.java

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,18 +18,31 @@
1818

1919
public class RNPushNotificationListenerService extends FirebaseMessagingService {
2020

21-
private RNReceivedMessageHandler mMessageReceivedHandler = new RNReceivedMessageHandler(this);
21+
private RNReceivedMessageHandler mMessageReceivedHandler;
22+
private FirebaseMessagingService mFirebaseServiceDelegate;
23+
24+
public RNPushNotificationListenerService() {
25+
super();
26+
this.mMessageReceivedHandler = new RNReceivedMessageHandler(this);
27+
}
28+
29+
public RNPushNotificationListenerService(FirebaseMessagingService delegate) {
30+
super();
31+
this.mFirebaseServiceDelegate = delegate;
32+
this.mMessageReceivedHandler = new RNReceivedMessageHandler(delegate);
33+
}
2234

2335
@Override
2436
public void onNewToken(String token) {
2537
final String deviceToken = token;
38+
final FirebaseMessagingService serviceRef = (this.mFirebaseServiceDelegate == null) ? this : this.mFirebaseServiceDelegate;
2639
Log.d(LOG_TAG, "Refreshed token: " + deviceToken);
2740

2841
Handler handler = new Handler(Looper.getMainLooper());
2942
handler.post(new Runnable() {
3043
public void run() {
3144
// Construct and load our normal React JS code bundle
32-
final ReactInstanceManager mReactInstanceManager = ((ReactApplication) getApplication()).getReactNativeHost().getReactInstanceManager();
45+
final ReactInstanceManager mReactInstanceManager = ((ReactApplication)serviceRef.getApplication()).getReactNativeHost().getReactInstanceManager();
3346
ReactContext context = mReactInstanceManager.getCurrentReactContext();
3447
// If it's constructed, send a notification
3548
if (context != null) {

0 commit comments

Comments
 (0)