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 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' } 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) {