4

I integrated Firebase Cloud Messaging in an Android app. App collects the FCM token and sends it to a remote server where tokens are stored in order to (eventually) send push notifications to users using FCM endpoint

https://fcm.googleapis.com/fcm/send

App gets the token in this way:

String refreshedToken = FirebaseInstanceId.getInstance().getToken();

I noticed tokens come in two different formats.

The first format is a 152 characters string starting with xxxxxxxxxxx:APA91b

The second one is 140 characters string starting with APA91b

As far as I understood from this question Firebase Topic Message Received Status using Google API the first format is ‘new’ and the second one is ‘old’. But so far I couldn't find any correlation between token format and app version (and Firebase SDK Version) or Android API level.

The problem is that I can’t send a notification to the client with old format push token.

If I try to get token details using Instance ID endpoint https://iid.googleapis.com/iid/info I receive “InvalidTokenVersion” error.

What I would like to know is:

  • why do clients with the same app version generate different token format?
  • is there a way to use old format tokens or convert them to the new one?

Thanks

akhilesh0707
  • 6,709
  • 5
  • 44
  • 51
frafork
  • 81
  • 4
  • Did the app previously use GCM? You can force regeneration of the token by resetting the instance ID: [FirebaseInstanceId.getInstance().deleteInstanceId()](https://firebase.google.com/docs/reference/android/com/google/firebase/iid/FirebaseInstanceId). A brute force fix would be to deploy a version of the app that tests for the 140 char token and resets IID if found. – Bob Snyder Aug 01 '17 at 16:16
  • @BobSnyder no it didn't. Anyway forcing regeneration could be a way, although I'll get new tokens only from clients that will open the app after the update. – frafork Aug 01 '17 at 16:40
  • 1
    You can configure a `BroadcastReceiver` to run when the app is updated using [Intent.ACTION_MY_PACKAGE_REPLACED](https://developer.android.com/reference/android/content/Intent.html#ACTION_MY_PACKAGE_REPLACED). I think you could use that to trigger the IID/token regeneration. Odd that you are seeing the 140-char tokens if the app has never used GCM or another service (such as Parse) that was based on GCM. – Bob Snyder Aug 01 '17 at 16:51
  • @BobSnyder interesting, I didn't know that Intent. I'll give it a try. I will also double check for a previous GCM implementation, maybe I missed something. Thank you. – frafork Aug 02 '17 at 08:16
  • Agreeing with @BobSnyder The token that starts without the InstanceID prefix (`:`) is odd. If this behavior continues, I would suggest reaching out to Firebase support directly. Cheers! – AL. Aug 02 '17 at 14:59

0 Answers0