From 05b7f4cf0fb337ebaaed827a341ad4244c58c2d8 Mon Sep 17 00:00:00 2001 From: vuletuan Date: Fri, 12 Mar 2021 13:37:15 +0700 Subject: [PATCH 1/3] feat: support for delegating --- .../fcm/VoiceFirebaseMessagingService.java | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/android/src/main/java/com/hoxfon/react/RNTwilioVoice/fcm/VoiceFirebaseMessagingService.java b/android/src/main/java/com/hoxfon/react/RNTwilioVoice/fcm/VoiceFirebaseMessagingService.java index 520b77f1..d326b179 100644 --- a/android/src/main/java/com/hoxfon/react/RNTwilioVoice/fcm/VoiceFirebaseMessagingService.java +++ b/android/src/main/java/com/hoxfon/react/RNTwilioVoice/fcm/VoiceFirebaseMessagingService.java @@ -37,6 +37,14 @@ public class VoiceFirebaseMessagingService extends FirebaseMessagingService { private CallNotificationManager callNotificationManager; + private FirebaseMessagingService mFirebaseServiceDelegate; + + public VoiceFirebaseMessagingService(FirebaseMessagingService delegate) { + super(); + this.mFirebaseServiceDelegate = delegate; + callNotificationManager = new CallNotificationManager(); + } + @Override public void onCreate() { super.onCreate(); @@ -66,7 +74,7 @@ public void onMessageReceived(RemoteMessage remoteMessage) { // Check if message contains a data payload. if (remoteMessage.getData().size() > 0) { Map data = remoteMessage.getData(); - + final FirebaseMessagingService serviceRef = (this.mFirebaseServiceDelegate == null) ? this : this.mFirebaseServiceDelegate; // If notification ID is not provided by the user for push notification, generate one at random Random randomNumberGenerator = new Random(System.currentTimeMillis()); final int notificationId = randomNumberGenerator.nextInt(); @@ -82,7 +90,7 @@ public void onCallInvite(final CallInvite callInvite) { handler.post(new Runnable() { public void run() { // Construct and load our normal React JS code bundle - ReactInstanceManager mReactInstanceManager = ((ReactApplication) getApplication()).getReactNativeHost().getReactInstanceManager(); + ReactInstanceManager mReactInstanceManager = ((ReactApplication)serviceRef.getApplication()).getReactNativeHost().getReactInstanceManager(); ReactContext context = mReactInstanceManager.getCurrentReactContext(); // If it's constructed, send a notification if (context != null) { From 10f9545c3552222e1920dff26e9c3ae65475a770 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=AA=20Tu=E1=BA=A5n=20V=C5=A9?= Date: Mon, 22 Mar 2021 17:53:08 +0700 Subject: [PATCH 2/3] chore: add missing docs --- README.md | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/README.md b/README.md index 812d239e..1146418c 100644 --- a/README.md +++ b/README.md @@ -137,6 +137,8 @@ Setup FCM You must download the file `google-services.json` from the Firebase console. It contains keys and settings for all your applications under Firebase. This library obtains the resource `senderID` for registering for remote GCM from that file. +Then follow these step by step https://firebase.google.com/docs/android/setup + #### `android/build.gradle` ```groovy @@ -152,6 +154,17 @@ buildscript { apply plugin: 'com.google.gms.google-services' ``` +#### `android/app/build.gradle` + +```groovy +dependencies { + implementation platform('com.google.firebase:firebase-bom:26.4.0') + implementation 'com.google.firebase:firebase-messaging' + implementation 'com.google.firebase:firebase-analytics' +} +``` + + #### `AndroidManifest.xml` ```xml From 84d607321d5d6dd713fc0284c07db7d69c730a58 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=AA=20Tu=E1=BA=A5n=20V=C5=A9?= Date: Mon, 22 Mar 2021 18:10:11 +0700 Subject: [PATCH 3/3] chore: update firebase-messaging dependencies version --- android/build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/android/build.gradle b/android/build.gradle index fe752fa4..0fc7d2e9 100644 --- a/android/build.gradle +++ b/android/build.gradle @@ -58,6 +58,6 @@ dependencies { implementation 'com.twilio:voice-android:4.5.0' implementation "com.android.support:appcompat-v7:$supportLibVersion" implementation 'com.facebook.react:react-native:+' - implementation 'com.google.firebase:firebase-messaging:17.6.+' + implementation 'com.google.firebase:firebase-messaging:21.0.+' testImplementation 'junit:junit:4.12' }