diff --git a/android/react-native-fcm.iml b/android/react-native-fcm.iml index aa83db1bad837e6c92195a8d05712d763dcdd393..e7a577aebae92325eff60958753b25ae98f6bc09 100644 --- a/android/react-native-fcm.iml +++ b/android/react-native-fcm.iml @@ -67,14 +67,6 @@ - - - - - - - - @@ -83,8 +75,19 @@ + + + + + + + + + + + @@ -107,13 +110,18 @@ + + + + + diff --git a/android/src/main/java/com/evollu/react/fcm/MessagingService.java b/android/src/main/java/com/evollu/react/fcm/MessagingService.java index 80cb74f468719801c7176994aa444dac7549d081..c85deff110c9392a5e17a0d4d2e4763539c7608b 100644 --- a/android/src/main/java/com/evollu/react/fcm/MessagingService.java +++ b/android/src/main/java/com/evollu/react/fcm/MessagingService.java @@ -2,11 +2,13 @@ package com.evollu.react.fcm; import java.util.Map; import android.content.Intent; +import android.os.Bundle; import android.util.Log; -import me.leolin.shortcutbadger.ShortcutBadger; import com.google.firebase.messaging.FirebaseMessagingService; import com.google.firebase.messaging.RemoteMessage; + +import org.json.JSONException; import org.json.JSONObject; public class MessagingService extends FirebaseMessagingService { @@ -19,6 +21,7 @@ public class MessagingService extends FirebaseMessagingService { Intent i = new Intent("com.evollu.react.fcm.ReceiveNotification"); i.putExtra("data", remoteMessage); handleBadge(remoteMessage); + buildLocalNotification(remoteMessage); sendOrderedBroadcast(i, null); } @@ -40,4 +43,22 @@ public class MessagingService extends FirebaseMessagingService { Log.e(TAG, "Badge count needs to be an integer", e); } } + + public void buildLocalNotification(RemoteMessage remoteMessage) { + if(remoteMessage.getData() == null){ + return; + } + Map data = remoteMessage.getData(); + String customNotification = data.get("custom_notification"); + if(customNotification != null){ + try { + Bundle bundle = BundleJSONConverter.convertToBundle(new JSONObject(customNotification)); + FIRLocalMessagingHelper helper = new FIRLocalMessagingHelper(this.getApplication()); + helper.sendNotification(bundle); + } catch (JSONException e) { + e.printStackTrace(); + } + + } + } } \ No newline at end of file