New Way to Implement Firebase Push Notification — FirebaseInstanceIdService Deprecated (Android)

New versions + New Implementation = Easiness

Image for post
Image for post

As we already know that to Implement the push notifications with firebase we always need to define the two services.

com.google.firebase.INSTANCE_ID_EVENTcom.google.firebase.MESSAGING_EVENT

Now, In the new version of firebase-messaging, the firebaseInstanceIdService is Deprecated. In the new version we don’t need to use INSTANCE_ID_EVENT, just extend your MyInstanceIDListenerService service with FirebaseMessagingService like below:

Next Step is to @Override some methods:

@Override
public void onNewToken(String s) {
super.onNewToken(s);
}
@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
}

Visit my website at

onNewToken will give you the token and onMessageReceived will received the message. Now no need to call onMessageReceived in another service. After all this, we also need to update the Manifest file as well and now Only one service needs to be defined like below:

<service
android:name=".service.firebase.MyInstanceIDListenerService"
android:permission="false">
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT"/>
</intent-filter>
</service>

If you want to get the token in your activity so in the older version we have:

FirebaseInstanceId.getInstance().getToken()

The above method getInstance().getToken is also deprecated. The new way to get the token in your activity like below:

FirebaseInstanceId.getInstance().getInstanceId().addOnSuccessListenr(Activity.this,new OnSuccessListener<InstanceIdResult>() {
@Override
public void onSuccess(InstanceIdResult instanceIdResult) {
String newToken = instanceIdResult.getToken();
}
});

So, now you have the latest Implementation of Firebase push :-)

Sharing the knowledge is Caring 😊

If you want to learn some other topic then check it out the below link:

If you want to learn more about it then check it out the official link below:

Thanks for reading this article. Be sure to clap to recommend this article if you found it helpful. It means a lot to me.

If you need any help then Join me on , , , and Subscribe to my .

Senior Software Engineer(Android). Open Source Contributor, Technical Writer, Email: check my website at

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store