6

I have implemented FCM in version 6 of my Android application. onTokenRefresh() is getting called if my app is not previously installed. But when my app with a previous version (which did not have FCM implemeted) is already installed and I update it with version 6, then the onTokenRefresh() is not getting called.

Do I need to uninstall the previous app version from Play Store and then install new version?

AL.
  • 36,815
  • 10
  • 142
  • 281
Dharmita bhatt
  • 475
  • 4
  • 16

1 Answers1

2

I think that should still be the intended behavior. onTokenRefresh() will be called the first time the app is installed. Not every time it's updated. So maybe, you could manually force the onTokenRefresh() like what is mentioned in this post:

If you would like to manually force the onTokenRefresh(), you can create an IntentService and delete the token instance. Then, when you call getToken, the onTokenRefresh() method will be called again.

Community
  • 1
  • 1
AL.
  • 36,815
  • 10
  • 142
  • 281
  • 1
    Yes, I think onTokenRefresh() not getting called when app is updated :( – Dharmita bhatt Sep 22 '16 at 08:33
  • 2
    A token is generated when your first start an app that uses FCM. If you start your service later, you may have missed the `onTokenRefresh()` call. But the solution is simple: call `FirebaseInstanceID.getToken()` as described in the section [Retrieve the current registration token](https://firebase.google.com/docs/cloud-messaging/android/client#retrieve-the-current-registration-token) and handle the token how you'd normally do it in `onTokenRefresh()`. If the token hasn't been generated yet, it'll return `null`. But in that case, your `onTokenRefresh()` will be called once the token is ready. – Frank van Puffelen Sep 22 '16 at 11:35
  • Thanks for the inputs :) @FrankvanPuffelen – AL. Sep 22 '16 at 12:52