77

I'm trying to create a push service for my Android app, and I follow Google GCM's documentation and example for this matter:

I can register/unregister my Android app. From my server side, I can see that I have one subscription registered, but when I try to send a message from server to my Android app I always get following error:

Error sending message to device #0: MismatchSenderId

For my Android app, I use SENDER_ID = 200000000001.

And for my server side as Google says I use API_KEY = AIzxxxxxxxxxxxxxxxxXxxXxxXxxxXXXXXxxxxs

I followed this document:

http://developer.android.com/guide/google/gcm/demo.html

I've enabled GCM in my Google API panel too, yet I'll get that annoying error message.

How can I fix this problem?

Matt
  • 70,063
  • 26
  • 142
  • 172
Seyed Vahid Hashemi
  • 5,022
  • 9
  • 50
  • 86

11 Answers11

68

Did your server use the new registration ID returned by the GCM server to your app? I had this problem, if trying to send a message to registration IDs that are given out by the old C2DM server.

And also double check the Sender ID and API_KEY, they must match or else you will get that MismatchSenderId error. In the Google API Console, look at the URL of your project:

https://code.google.com/apis/console/#project:xxxxxxxxxxx

The xxxxxxxxx is the project ID, which is the sender ID.

And make sure the API Key belongs to 'Key for server apps (with IP locking)'

azgolfer
  • 14,494
  • 4
  • 46
  • 46
  • I have a huge doubt here.Is it possible to deploy my application to load of other cellphones with only one SERIALID? – Seyed Vahid Hashemi Jul 03 '12 at 15:13
  • 3
    Have you looked at the GCM architectural overview http://developer.android.com/guide/google/gcm/gcm.html? Every Android phones that is using your app will register with GCM with your app's Sender ID, and they will receive a unique GCM registration ID, that you have to store on your server. If you wish to send a message to all of your users, you need to go through all of those registration ids. – azgolfer Jul 03 '12 at 15:23
  • 7
    This is really silly, but it works. The Project ID listed in the page on the dashboard is a named id that I got to pick, however you must use the numeric ID from the url which is very confusing. – Redth Jul 03 '12 at 17:50
  • @azgolfer - do you mean "API_KEY" above rather than "APK_KEY"? – Richard Russell Dec 21 '12 at 16:56
  • 2
    Took me ages to find this answer @azgolfer you are a legend. Guys double check your new registration id! That fixed it for me. – SergioM Apr 01 '13 at 03:39
  • @SergioM Does signing the app with the SHA1 key, has an impact on the registrationid? – Kailas May 28 '14 at 07:25
  • Newly created projects now show both a project ID and number on the overview page: which should I take? – marcovtwout Jul 24 '14 at 10:14
  • 5
    This information may be out of date. Now you should use your project NUMBER – Ethan Fischer Dec 31 '15 at 06:11
  • http://stackoverflow.com/questions/35812304/pushnotification-not-working-properly i have same issue – albert Mar 05 '16 at 10:19
  • I have my URL ok but i still have this issue. Early it was working, but in my console there was many project. I dropped all and i create one only and inside it, i created two App. Done this, i don't get to send push notification. I try to send and fires this message: MismatchSenderId – pnet Oct 01 '17 at 19:20
24

Mismatch happens when you don't use the numeric ID. Project ID IS NOT SENDER ID!! It took me 9 hours to figure this out. For all the confusion created by google, check the following link to get numeric id.

https://console.cloud.google.com

instead of

https://console.developers.google.com

Hope it helps!!

Update:- Things have changed again. Now the sender id is with firebase.

Go to https://console.firebase.google.com and select your project. Under settings -> cloud messaging, you can find the sender id.

And it works!

Ajay Singh
  • 634
  • 6
  • 18
7

Please run below script in your terminal

curl -X POST \
-H "Authorization: key=  write here api_key" \
-H "Content-Type: application/json" \
-d '{ 
"registration_ids": [ 
"write here reg_id generated by gcm"
], 
"data": { 
"message": "Manual push notification from Rajkumar"
},
"priority": "high"
}' \
https://android.googleapis.com/gcm/send

it will give the message if it is succeeded or failed

Adil Soomro
  • 36,617
  • 9
  • 98
  • 146
Raj Kumar
  • 648
  • 7
  • 17
  • 6
    MismatchSenderId because with in same device you have logged with different keys. to solve this problem uninstall app and run it againg and update the registration key. and then run the CURL script in your teminal which i post above it will give success message and you will get notification to your device – Raj Kumar Dec 24 '15 at 06:05
4

I encountered the same issue recently and I tried different values for "gcm_sender_id" based on the project ID. However, the "gcm_sender_id" value must be set to the "Project Number".

You can find this value under: Menu > IAM & Admin > Settings.

See screenshot: GCM Project Number

mpavel
  • 801
  • 1
  • 6
  • 6
2
InstanceID.getInstance(getApplicationContext()).getToken(authorizedEntity,scope)

authorizedEntity is the project number of the server

Paul Roub
  • 35,100
  • 27
  • 72
  • 83
2

Your android app needs to correct 12-digit number id (aka GCM Project Number). If this 12-digit number is incorrect, then you will also get this error.

This 12-digit number is found in your Google Play Console under your specific app, 'Service & API' -> 'LINKED SENDER IDS'

Britc
  • 595
  • 4
  • 8
2

This happens when the Server key and Sender ID parameters HTTP request do not match each other. Basically both server ID and Server key must belong to the same firebase project. Please refer to the below image. In case of mixing these parameters from deferent Firebase projects will cause error MismatchSenderId enter image description here

Chamath Jeevan
  • 4,337
  • 1
  • 21
  • 25
0

Check google-services.json file in app folder of your Android project. Generate a new one from Firebase console if you are unsure. I got this error in two cases.

  1. I used a test Firebase project with test application (that contained right google-services.json file). Then I tried to send push notification to another application and got this error ('"error": "MismatchSenderId"'). I understood that the second application was bound to another Firebase project with different google-services.json. Because server keys are different, the request should be rewritten.

  2. I changed google-services.json in the application, because I wanted to replace test Firebase project with an actual. I generated right google-services.json file, changed request, but kept receiving this error. On the next day it fixed itself. I suspect Firebase doesn't update synchronously.

To get a server key for the request, open https://console.firebase.google.com and select an appropriate project.

enter image description here

Then paste it in the request.

enter image description here

CoolMind
  • 16,738
  • 10
  • 131
  • 165
0

With the deprecation of GCM and removal of its APIs, it appears that you could see MismatchSenderId if you try to use GCM after May 29, 2019. See the Google GCM and FCM FAQ for more details.

user3486184
  • 1,536
  • 2
  • 22
  • 24
-1

Use sender ID & API Key generated here: http://developers.google.com instead (browse for Google Cloud Messaging first and follow the instruction).

-1

If use for native Android, check your AndroidMaifest.xml file:

<meta-data
        android:name="onesignal_google_project_number"
        android:value="str:1234567890" />  
  <!--             its is correct. -->

instead

   <meta-data
        android:name="onesignal_google_project_number"
        android:value="@string/google_project_number" />

Hope it helps!!

Iman Marashi
  • 4,677
  • 33
  • 48