Skip to content

Commit 510fe90

Browse files
Firebase messaging dependency updated to v22.0.0 (#68)
* Firebase messaging updated to v22.0.0 Replace deprecated method of with new methods of firebase messaging. * Changelog updated * Update CHANGELOG.md Co-authored-by: ArtursKadikis <[email protected]>
1 parent 07ff3ff commit 510fe90

File tree

4 files changed

+28
-23
lines changed

4 files changed

+28
-23
lines changed

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
## 20.11.12
2-
* Bintray dependency removed
2+
* ! Minor breaking change ! Firebase dependency updated to version '22.0.0', replaced deprecated method to retrieve push token. This change now makes AndroidX mandatory.
3+
* Bintray respository inclusion removed.
34
* Underlying android SDK is 20.11.11
45
* Underlying iOS SDK version is 20.11.3
56

android/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,5 +44,5 @@ dependencies {
4444
implementation 'ly.count.android:sdk:20.11.11'
4545

4646
//if any version higher than 18.0.0 is used then it forces AndroidX
47-
implementation 'com.google.firebase:firebase-messaging:18.0.0'
47+
implementation 'com.google.firebase:firebase-messaging:22.0.0'
4848
}

android/src/main/java/ly/count/android/sdk/react/CountlyMessagingService.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,11 @@ public void onMessageReceived(RemoteMessage remoteMessage) {
4242
// decode message data and extract meaningful information from it: title, body, badge, etc.
4343
CountlyPush.Message message = CountlyPush.decodeMessage(remoteMessage.getData());
4444

45-
if (message != null && message.has("typ")) {
46-
// custom handling only for messages with specific "typ" keys
47-
message.recordAction(getApplicationContext());
48-
return;
49-
}
45+
// if (message != null && message.message().contains("typ")) {
46+
// // custom handling only for messages with specific "typ" keys
47+
// message.recordAction(getApplicationContext());
48+
// return;
49+
// }
5050

5151
Boolean result = CountlyPush.displayNotification(getApplicationContext(), message, getApplicationContext().getApplicationInfo().icon, null);
5252
if(Countly.sharedInstance().isLoggingEnabled()) {

android/src/main/java/ly/count/android/sdk/react/CountlyReactNative.java

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@
3838
import android.app.NotificationManager;
3939
import android.app.NotificationChannel;
4040

41+
import androidx.annotation.NonNull;
42+
4143
import ly.count.android.sdk.StarRatingCallback;
4244
import ly.count.android.sdk.messaging.CountlyPush;
4345

@@ -50,11 +52,10 @@
5052
import com.facebook.react.bridge.WritableNativeArray;
5153
import com.facebook.react.bridge.WritableNativeMap;
5254
import com.facebook.react.modules.core.DeviceEventManagerModule;
53-
import com.google.firebase.iid.FirebaseInstanceId;
54-
import com.google.firebase.iid.InstanceIdResult;
5555
import com.google.android.gms.tasks.Task;
5656
import com.google.android.gms.tasks.OnCompleteListener;
5757
import com.google.firebase.FirebaseApp;
58+
import com.google.firebase.messaging.FirebaseMessaging;
5859

5960

6061
class CountlyReactException extends Exception {
@@ -548,25 +549,28 @@ public void askForNotificationPermission(ReadableArray args){
548549
CountlyPush.init(activity.getApplication(), messagingMode);
549550
try{
550551
FirebaseApp.initializeApp(context);
551-
FirebaseInstanceId firebaseInstanceId = FirebaseInstanceId.getInstance();
552-
if(firebaseInstanceId == null) {
553-
log("askForNotificationPermission, firebaseInstanceId is null", LogLevel.WARNING);
552+
FirebaseMessaging firebaseMessagingInstance = FirebaseMessaging.getInstance();
553+
if(firebaseMessagingInstance == null) {
554+
log("askForNotificationPermission, firebaseMessagingInstance is null", LogLevel.WARNING);
554555
return;
555556
}
556-
Task<InstanceIdResult> instanceIdResultTask = firebaseInstanceId.getInstanceId();
557-
if(instanceIdResultTask == null) {
558-
log("askForNotificationPermission, instanceIdResultTask is null", LogLevel.WARNING);
557+
Task<String> firebaseMessagingTokenTask = firebaseMessagingInstance.getToken();
558+
if(firebaseMessagingTokenTask == null) {
559+
log("askForNotificationPermission, firebaseMessagingTokenTask is null", LogLevel.WARNING);
559560
return;
560561
}
561-
instanceIdResultTask.addOnCompleteListener(new OnCompleteListener<InstanceIdResult>() {
562+
563+
firebaseMessagingTokenTask.addOnCompleteListener(new OnCompleteListener<String>() {
562564
@Override
563-
public void onComplete(Task<InstanceIdResult> task) {
564-
if (!task.isSuccessful()) {
565-
log("askForNotificationPermission, getInstanceId failed", task.getException(), LogLevel.WARNING);
566-
return;
567-
}
568-
String token = task.getResult().getToken();
569-
CountlyPush.onTokenRefresh(token);
565+
public void onComplete(@NonNull Task<String> task) {
566+
if (!task.isSuccessful()) {
567+
log("askForNotificationPermission, Fetching FCM registration token failed", task.getException(), LogLevel.WARNING);
568+
return;
569+
}
570+
571+
// Get new FCM registration token
572+
String token = task.getResult();
573+
CountlyPush.onTokenRefresh(token);
570574
}
571575
});
572576
}catch(Exception exception){

0 commit comments

Comments
 (0)