I am using FCM in my android app for push notifications. I have the below class to get the fcm token.
public class MyFirebaseInstanceIdService extends Fireba
The registration token may change when:
The app deletes Instance ID
The app is restored on a new device
The user uninstalls/reinstall the app
The user clears app data.
You can find more info from this http://prntscr.com/dnzq9l
https://firebase.google.com/docs/cloud-messaging/android/client
Install/Clear Data - New Token is generated.
Update from Play Store - Token remains same.
If you want to call onTokenRefreshed() you should do it manually.
Click here to read more about it.
As pointed out in the post by @Dharmitabhatt in the comments section, a registration token is not refereshed when an app is updated.
Whenever a token is refreshed in Android, it should call the onTokenRefresh() method:
Called when the system determines that the tokens need to be refreshed. The application should call getToken() and send the tokens to all application servers.
This will not be called very frequently, it is needed for key rotation and to handle Instance ID changes due to:
- App deletes Instance ID
- App is restored on a new device
- User uninstalls/reinstall the app
- User clears app data
The system will throttle the refresh event across all devices to avoid overloading application servers with token updates.
So you are right to say that updating the app doesn't necessarily refresh the token.