I am working with a messaging application using c2dm.. I get registered my app with c2dm..But the time am sending message to any particular id who is using my app, getting errors saying that "Sender Id mismatch".. What it will be ? can anyone help me ?
you need to set the sender_id in the client code with the email
address you registered to the c2dm servers (the one you use in the
http post to send messages).
usedintent.putExtra("sender","yourMail#gmail.com");
Related
So yes I have done my research and none of the resources I found had an answer that was correct.
I have enabled GCM in my api console on google. I have put the sender ID in my app and the server key in the server. When I run my server to send notifications through gcm I get an error 'Not Registered'. I get the device key with this plugin: https://github.com/phonegap/phonegap-plugin-push.
How come I keep getting the not registered error?
you have to use FCM it's now essay to use and better than GCM
https://firebase.google.com/docs/cloud-messaging/android/client
for node js coding this link should help https://www.npmjs.com/package/fcm
Closing this post. The answer for anyone using this plugin who keeps getting an error like me. Try using this inside your app folder: cordova plugin rm phonegap-plugin-push and then reinstall it with your sender_id again
Do you get token in your app(client)?
When server send push message, server need server_api_key and token.
Client register in GCM. (It get token)
Server send message (token and server_api_key)
If client do not register, you get message "Not registered"
I have a problem with an app using GCM, the scenario is this:
the app is installed
the app calls the GCM register method getting the registration id "RID-1"
the app is uninstalled
the app is installed again
the app calls the GCM register method again getting the registration id "RID-2"
In step 5, I need to get the previous registration id so I can update my model.
Limitations:
- I am trying to do this without using the external storage
- I can't update the model when the server sends a message, it should be done after the registration because a new profile is created in the app for each new device
I know that this information is in Google servers because it is sent to you when you send a message to the old registration id. For example, if I send a message to "RID-1", in the response I get that the new (canonical) registration id is "RID-2". What I need is a way to get this information without sending a message.
Let me know if you need more context.
I found several related questions but the answers doesn't apply to this scenario:
Registration ID duplication for GCM
gcm canonical id should be updated or not
Persistance of gcm registration id
Google Cloud Messaging - Registration ID status
Android GCM: How to detect registered canonical ids in my own server?
Handling registration ID changes in Google Cloud Messaging on Android
(all answered by #eran)
You can specify "dry_run": true option in /send request.
I found that devices do not receive any push notifications with "dry_run": true option, while a server get canonical_ids response.
Here is a sample code in Ruby. You may have to install gcm Gem beforehand.
$ gem install gcm
ask_canonical_ids.rb
require 'gcm'
require 'json'
API_KEY = "YourApiKey"
gcm = GCM.new(API_KEY)
registration_ids = [
'OldRegistrationId',
]
option = { data: { 'message' => 'Hello Gcm!' }, dry_run: true }
response = gcm.send_notification(registration_ids, option)
p response[:canonical_ids]
output of $ ruby ask_canonical_ids.rb (formatted)
[{
:old => "OldRegistrationId",
:new => "NewRegistrationId"
}]
Again, your device will not receive any push notifications.
We need to update registration id with Canonical Id( By finding index position of array). You may Follow this working Ready use Code
If all you need is that the user should not get a notification, send a message with parameters that your application is not looking for. You will get the canonical and your app will discard the notification if it does not have the mandatory text and message.
For example, my Cordova application plugin requires the key 'message' in the data received from the server. Otherwise it does not create a notification.
I know this is sort of a hack, but I think given the limitations, this will be the easiest to achieve.
I am trying to use the GCM service in my android app.
For that, I used the android documentation from http://developer.android.com/guide/google/gcm/gcm.html
I created the client side registration process with the sender id etc and the server side application where I am using the registration id and the sender id to send messages.
When I am installing the app in my phone through Eclipse, the push notifications works fine, so the sender id i have is right.
Then, when i export the apk file with Eclipse and install it in my phone, I am getting the error message that the SenderId is wrong
MissmatchedSenderId
Anyone has an idea whyI am getting this.
I have read those topics:
Why do I get "MismatchSenderId" from GCM server side?
When sending messages using GCM, I keep getting the response 'MismatchSenderId'
But the strange thing in my case is that everything works fine before exporting the app as apk and then I have this problem.
Any idea is mostly wellcome.
I actually had the same problem, and was researching more than 10 hours.
I finally found out the problem!
Nothing related to the Server API key or Browser API Key or SenderID.
The problem was the Google documentation:
final String regId = GCMRegistrar.getRegistrationId(this);
if (regId.equals("")) {
GCMRegistrar.register(this, SENDER_ID);
} else {
Log.v(TAG, "Already registered");
}
Google says that you have to call the getRegistrationId function and only if the id is empty call register!
Which did not work for me at all... when I did that I always got back MismatchSenderId when sending to this regId.
My solution was:
Always call
GCMRegistrar.register(this, SENDER_ID);
and when the function
protected void onRegistered( Context c, String regId )
is called save the regId in my server database.
if I do it this way, all works fine!
The combination of SenderID and API key provided by GCM is unique per application.
We faced the senderID mismatch issue, when we updated our senderID on the client side but still used the API key related to old senderID.
We were able to resolve the issue after we updated the server API key.
Also the answer by #schurtertom is very helpful
Actually,i have used ramachandru6#gmail.com as a "sender id" in my app and that same id and same password used for getting authentication tocken.but still am getting 401 error.
i have spent more than two days.please any one guide me.what i have to do?
IN GCM there is nothing like using id and password for authentication. When you set up your app in GCM it will give one server side token. Use that as a key
I am trying to migrate to GCM in Android, C2DM now being deprecated. The registration process described here is different from registration described here. Are both registration same? Can we see code for GCMRegistrar to know for sure?
I've successfully migrated my C2DM project to GCM. Tested, it works fine. The only changes were:
in the Android app - change the value of sender upon registration
on the server side - change the auth header and the URL
That was it, as far as the interaction with Google goes. There were more some changes dictated by the app's logic:
in the Android app, the registration ID was cached in its preferences. Upon upgrade, I remove reg ID from the preferences to force re-registration, this time with GCM.
the logic of passing the reg ID to the server got an extra boolean parameter - if this is a C2DM or GCM reg ID
the logic of sending messages became conditional upon the said parameter.
Throwing out the C2DM logic completely out of the server would be unwise - not everyone upgrades their Android apps. The old, C2DM-enabled versions will be out in the wild for some time. And Google pledged to keep C2DM running in the short term. So message sending is conditional - depending on reg ID type, it sends either to GCM or to C2DM.
EDIT re: conditional logic:
if($RegID_Is_GCM)
{
$Auth = GCM_Auth();
$URL = $GCM_URL;
}
else
{
$Auth = C2DM_AUTH();
$URL = $C2DM_URL;
}
They are actually the same thing. The second one encapsulates the first one in a static method and registers a broadcast receiver. You can attach the source to the gcm.jar and see for yourself. You can find source code in ~/android-sdks/extras/google/gcm/gcm-client/gcm-src.jar
The Thing I like most in GCM is the RegID we will get from GCM server,it is not only an ID its an Address of this application on this Device. So this time you don't need to send a device Id to server along with your Registration Id as per was in C2DM.
In C2DM every time you request a registration id you will get a new ID.
But in GCM RegId generated by using your application package along with some device id so if you will request for Registration Id again and again you will receive the same RegId.
And if you uninstall an application and will install it again still GCM server will give you the same Registration Id.
So one Registraion Id will do no need of any Device Id to send to server.
I have been successful at migrating from C2DM to GCM. I have also documented how to implement GCM at
http://android.amolgupta.in/2012/07/google-cloud-messaging-gcm-tutorial.html
GCMRegistrar is just a helper that does the leg work described in the first page.
You can see the class here. android-sdk\extras\google\gcm\gcmclient\src\com\google\android\gcm.