2

I have my client app with Android installed in several devices. I also have my Server app that send messages to those apps. The problem is that some devices receive the messages and other don't. I get the error "MismatchSenderId" when sending the message to those devices.

I divided the problem, so I open the firebase console and send notifications to my apps (I have the Token for each of them). So, using the console app, I get errors on the same devices that using my server. But as I said, every device is using the same app.

Any help of the reason?

AL.
  • 36,815
  • 10
  • 142
  • 281
Ton
  • 9,235
  • 15
  • 59
  • 103
  • Hi Ton. Was there any changes along the development of your app, where by chance, you had to change the sender project? If you're seeing this on specific tokens, have you checked maybe there's a pattern to them (e.g. app/os version)? It's hard to comment on anything with the current details. – AL. May 11 '17 at 02:36
  • Hi. Thanks. What do you mean "change the sender project"? – Ton May 11 '17 at 07:41
  • Hi. I meant used a different Firebase project (hence changing the sender project). – AL. May 11 '17 at 07:44
  • I can try that. Does my android app has to be changed in anything? – Ton May 11 '17 at 07:45
  • Sorry. I think I caused a confusion at some point. I was asking if you've changed/used a different project during your development? But to answer that part, if you changed your main project as the sender, you'll have to regenerate the google-services.json file for that project to use for your app. – AL. May 11 '17 at 07:48
  • Oh I see. Sorry. No, I didn't change it. I created a new project and started testing with my Android app. As I said some devices work. I don't have a pattern because it works in a Samsung S4 lollipop and several emulators, it doesn't work with Samsung S8 nougat and S3 Jellybean. – Ton May 11 '17 at 07:51
  • All if them worked when using Gcm instead of Fcm. – Ton May 11 '17 at 07:52
  • Now that's a clue. By using GCM instead of FCM, do you mean the endpoints? – AL. May 11 '17 at 07:59
  • Well yeah. I had my app and server working with gcm. Then I changed to fcm and getting these results. – Ton May 11 '17 at 08:00
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/143942/discussion-between-al-and-ton). – AL. May 11 '17 at 08:02

3 Answers3

11

So to start of, I'd point out the description for MismatchSenderId error:

A registration token is tied to a certain group of senders. When a client app registers for FCM, it must specify which senders are allowed to send messages. You should use one of those sender IDs when sending messages to the client app. If you switch to a different sender, the existing registration tokens won't work.

As per our discussion, it was pointed out that you created a new Firebase Project instead of importing your Google Project that you were using for GCM. From the new project, the google-services.json was generated and used for the app, which resulted for new tokens to be associated with the new Project's Sender ID. To visualize it properly:

  • GCM Registration Tokens > only receive messages from > Google Project (1st)

  • New Tokens > only receive messages from > Firebase Project (2nd)

As a solution, I advised for you to import the Google Project to the Firebase Console, generate a google-services.json from that Project and replace the one in your app with that, which associates the app to that (correct) project. This in turn created tokens that are now associated with your 1st Project.

  • GCM Registration Tokens > only receive messages > Google Project (1st)

  • New Tokens > now receive messages > Firebase Project (2nd) Imported Google Project (1st)

Hope that makes sense.


Good to mention from the discussion:

  • After applying the changes, you mentioned that the error persisted, but it was a different issue that was fixed by simply using the Server Key.

  • Linked a post during discussion.

Community
  • 1
  • 1
AL.
  • 36,815
  • 10
  • 142
  • 281
  • @Ton I think I covered pretty much what we discussed and explained (hopefully understandable) how things worked. Feel free to edit my answer if you have any other things you want to point out. Cheers! – AL. May 11 '17 at 10:26
  • 1
    Perfect. Your help was very important for me. I would never thought of importing my old GCM project. Cheers to you – Ton May 11 '17 at 10:37
0

Supporting @AL's answer, basically you need to uninstall the app on all the devices and install the app again so that all devices receive new tokens that correspond with the newly connected firebase project database.

0

Need to enable the following api in the Google Console (https://console.cloud.google.com/)

Firebase Cloud Messaging API Cloud Messaging

Then your senderId will be identified

Anand
  • 61
  • 1
  • 4