From d60b36d5e65573dce6ac5a0374e36d2c8feca119 Mon Sep 17 00:00:00 2001 From: Libin Lu Date: Mon, 5 Dec 2016 13:09:25 -0500 Subject: [PATCH] custom_notification --- android/react-native-fcm.iml | 24 ++++++++++++------- .../evollu/react/fcm/MessagingService.java | 23 +++++++++++++++++- 2 files changed, 38 insertions(+), 9 deletions(-) diff --git a/android/react-native-fcm.iml b/android/react-native-fcm.iml index aa83db1..e7a577a 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 80cb74f..c85deff 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 -- 2.26.2