Skip to content

Commit c2087fa

Browse files
AkashDhimangnprice
authored andcommitted
android notif [nfc]: Remove InstanceIDListenerService.java.
This is deprecated [1][2] in favor of overriding `FirebaseMessagingService#onNewToken`. While not causing any noticable bugs, its good to have up to date code. One benefit of this specific commit is that it removes some code. Something related but not done in this commit is to update firebase-messaging itself, which as of now stands at 22.0.0 . [1] https://firebase.google.com/docs/reference/android/com/google/firebase/iid/FirebaseInstanceIdService [2] https://firebase.google.com/support/release-notes/android#firebase_instance_id_version_1620
1 parent 470ad57 commit c2087fa

File tree

4 files changed

+14
-33
lines changed

4 files changed

+14
-33
lines changed

android/app/src/main/AndroidManifest.xml

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -87,13 +87,5 @@
8787
<action android:name="com.google.firebase.MESSAGING_EVENT" />
8888
</intent-filter>
8989
</service>
90-
91-
<service
92-
android:name=".notifications.InstanceIDListenerService"
93-
android:exported="false">
94-
<intent-filter>
95-
<action android:name="com.google.firebase.INSTANCE_ID_EVENT" />
96-
</intent-filter>
97-
</service>
9890
</application>
9991
</manifest>

android/app/src/main/java/com/zulipmobile/notifications/FcmListenerService.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package com.zulipmobile.notifications;
22

33
import android.content.Context;
4+
import com.facebook.react.ReactApplication;
5+
import com.facebook.react.bridge.ReactContext;
46
import com.google.firebase.messaging.FirebaseMessagingService;
57
import com.google.firebase.messaging.RemoteMessage;
68

@@ -17,4 +19,15 @@ public void onMessageReceived(RemoteMessage message) {
1719
((MainApplication) applicationContext).getConversations();
1820
FCMPushNotifications.onReceived(this, conversations, message.getData());
1921
}
22+
23+
@Override
24+
public void onNewToken(String token) {
25+
super.onNewToken(token);
26+
final ReactContext reactContext =
27+
((ReactApplication) getApplication())
28+
.getReactNativeHost()
29+
.getReactInstanceManager()
30+
.getCurrentReactContext();
31+
NotificationsModule.emitToken(reactContext, token);
32+
}
2033
}

android/app/src/main/java/com/zulipmobile/notifications/InstanceIDListenerService.java

Lines changed: 0 additions & 23 deletions
This file was deleted.

android/app/src/main/java/com/zulipmobile/notifications/NotificationsModule.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,7 @@ public String getName() {
2121
return "Notifications";
2222
}
2323

24-
static void emitToken(@Nullable ReactContext reactContext) {
25-
final String token = FirebaseInstanceId.getInstance().getToken();
24+
static void emitToken(@Nullable ReactContext reactContext, String token) {
2625
if (reactContext == null) {
2726
// Perhaps this is possible if InstanceIDListenerService gets invoked?
2827
return;

0 commit comments

Comments
 (0)