FCM getInstance().getToken() in Android is now deprecated. How to fix it?
Edit 2019–11–04
For current versions of the FCM library, FirebaseInstanceId class is no longer available, then I wrote how to fix it and still work with FCM just changing a couple of things.
The way in which we were getting the device registration token to use a Firebase Cloud Messaging client App on Android has changed and now is deprecated, thus we need to do a simple fix to avoid some headaches in the near future when the getToken() method is not longer supported.
So, in the older version we can get the token in this way:
FirebaseInstanceId.getInstance().getToken()
But as mentioned before getInstance().getToken is deprecated and now we need to replace it with a listener as follows:
The previous code was taken from the sample app and you can take a look there, but that is all. Is a simple fix and an easy way to ensure the support of the new capabilities of FCM.
If you want to set up a FCM client app on Android, the documentation is clear and concise.
See you all on a next Android code pill article :)
Edit 2019–11–04
For current versions of the FCM library, FirebaseInstanceId class is no longer available, then I wrote how to fix it and still work with FCM just changing a couple of things.