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

Commit 8392bb2

Browse files
committed
[Android] Add hooks to intent handling and bundle parsing
Allows easier customization of intent handling and bundle parsing behaviour on Android. This can be used to send notifications sent by 3rd party messaging management platforms that have custom message formats the same onNotification() JS codepath.
1 parent 2682658 commit 8392bb2

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

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

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,15 @@ public class RNPushNotification extends ReactContextBaseJavaModule implements Ac
4242
public static final String LOG_TAG = "RNPushNotification";// all logging should use this tag
4343
public static final String KEY_TEXT_REPLY = "key_text_reply";
4444

45+
public interface RNIntentHandler {
46+
void onNewIntent(Intent intent);
47+
48+
@Nullable
49+
Bundle getBundleFromIntent(Intent intent);
50+
}
51+
52+
public static ArrayList<RNIntentHandler> IntentHandlers = new ArrayList();
53+
4554
private RNPushNotificationHelper mRNPushNotificationHelper;
4655
private final SecureRandom mRandomNumberGenerator = new SecureRandom();
4756
private RNPushNotificationJsDelivery mJsDelivery;
@@ -81,6 +90,12 @@ private Bundle getBundleFromIntent(Intent intent) {
8190
bundle.putBundle("data", intent.getExtras());
8291
}
8392

93+
if (bundle == null) {
94+
for (RNIntentHandler handler : IntentHandlers) {
95+
bundle = handler.getBundleFromIntent(intent);
96+
}
97+
}
98+
8499
if(null != bundle && !bundle.getBoolean("foreground", false) && !bundle.containsKey("userInteraction")) {
85100
bundle.putBoolean("userInteraction", true);
86101
}
@@ -90,6 +105,10 @@ private Bundle getBundleFromIntent(Intent intent) {
90105

91106
@Override
92107
public void onNewIntent(Intent intent) {
108+
for (RNIntentHandler handler : IntentHandlers) {
109+
handler.onNewIntent(intent);
110+
}
111+
93112
Bundle bundle = this.getBundleFromIntent(intent);
94113
if (bundle != null) {
95114
mJsDelivery.notifyNotification(bundle);

0 commit comments

Comments
 (0)