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

Commit 8161e1b

Browse files
author
Boris Tacyniak
authored
Update RNReceivedMessageHandler.java
1 parent 1101e84 commit 8161e1b

File tree

1 file changed

+20
-10
lines changed

1 file changed

+20
-10
lines changed

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

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import android.os.Bundle;
1010
import android.os.Handler;
1111
import android.os.Looper;
12+
import android.content.Context;
1213
import android.util.Log;
1314
import android.net.Uri;
1415
import androidx.annotation.NonNull;
@@ -46,10 +47,11 @@ public void handleReceivedMessage(RemoteMessage message) {
4647
// ^ It's null when message is from GCM
4748
RNPushNotificationConfig config = new RNPushNotificationConfig(mFirebaseMessagingService.getApplication());
4849

49-
bundle.putString("title", getLocalizedString(remoteNotification.getTitleLocalizationKey(),
50-
remoteNotification.getTitleLocalizationArgs(), remoteNotification.getTitle()));
51-
bundle.putString("message", getLocalizedString(remoteNotification.getBodyLocalizationKey(),
52-
remoteNotification.getBodyLocalizationArgs(), remoteNotification.getBody()));
50+
String title = getLocalizedString(remoteNotification.getTitle(), remoteNotification.getTitleLocalizationKey(), remoteNotification.getTitleLocalizationArgs());
51+
String body = getLocalizedString(remoteNotification.getBody(), remoteNotification.getBodyLocalizationKey(), remoteNotification.getBodyLocalizationArgs());
52+
53+
bundle.putString("title", title);
54+
bundle.putString("message", body);
5355
bundle.putString("sound", remoteNotification.getSound());
5456
bundle.putString("color", remoteNotification.getColor());
5557
bundle.putString("tag", remoteNotification.getTag());
@@ -181,19 +183,27 @@ private void handleRemotePushNotification(ReactApplicationContext context, Bundl
181183
}
182184
}
183185

184-
private String getLocalizedString(String locKey, String[] locArgs, String defaultText) {
185-
String packageName = getPackageName();
186-
String result = defaultText;
186+
private String getLocalizedString(String text, String locKey, String[] locArgs) {
187+
if(text != null) {
188+
return text;
189+
}
190+
191+
Context context = mFirebaseMessagingService.getApplicationContext();
192+
String packageName = context.getPackageName();
193+
194+
String result = null;
195+
187196
if (locKey != null) {
188-
int id = getResources().getIdentifier(locKey, "string", packageName);
197+
int id = context.getResources().getIdentifier(locKey, "string", packageName);
189198
if (id != 0) {
190199
if (locArgs != null) {
191-
result = res.getString(id, (Object[]) locArgs);
200+
result = context.getResources().getString(id, (Object[]) locArgs);
192201
} else {
193-
result = res.getString(id);
202+
result = context.getResources().getString(id);
194203
}
195204
}
196205
}
206+
197207
return result;
198208
}
199209
}

0 commit comments

Comments
 (0)