2
votes

I’m implementing Firebase Cloud Messaging (FCM) and am experiencing a problem that I’m unable to solve. I have implemented FirebaseMessagingService and FirebaseInstanceIdService according to the guide(s). When I go to Firebase Console for my app, and use the Notification function, I can successfully send a message to ALL my app instances (using the package name).

Now, in the code I have fetched the Firebase Instance Id (token) by use of the following code:

    String token = FirebaseInstanceId.getInstance().getToken();
    SendFirebaseTokenToServer(token);

(note that currently I’m using HTTP protocol, as my server does not yet have a cert). Anyway using the token I get from the call above, I go back to the Firebase Console and try to send a message to one (1) installed instance of my app. I grab the token from our server DB where it is stored as "varchar(max)". When I do that I get the following error message:

Invalid registration token. Check the token format.

I have googled that and found only one hit (having to do with Firebase and iOS):

http://stackoverflow.com/questions/41343520/ios-invalid-registration-token-check-the-token-format

That issue indicates that a cert was required (I think I’m reading it correctly). I’m not sure what I’m doing wrong. I need to get this to work using the Firebase Console first, then my server guy can start on his end knowing that it should work.

1
Ok, i decided to try the Firebase Console directly (no server interaction) using the registration_id (token) i got from the Firebase call (spit out to Logcat). It worked! so the problem exists either on the server or in my sending it to the server. should i Encode() the token? - David M
If the problem exists in the code in your app server, edit your question to include the minimal server code that reproduces the problem. Without seeing that code, it'll be hard to say what's wrong with it. - Frank van Puffelen
@FrankvanPuffelen I am facing the same issue for the past few days. Could you please read my question? stackoverflow.com/questions/50359010 - bibscy

1 Answers

1
votes

Turns out i was programatically encoding all POST or PUT parameters prior to sending to our server. the FCM token had a semicolon in it, which got encoded to a "%3A", seemingly causing the problem.

do NOT encode the FCM token.