Currently i am working with push notification in android.its working fine.but my issues is am getting multiple notification instead of a single notification.then i check my device registration table and find a strange fact ,after each 30 minutes my device id is changing,so multiple device are resisted for same user_id and getting number of notification together .i don't know why this happen.i am using Samsung galaxy s2 for testing. please help me .
I'm not sure why your registration id changes every 30 minutes. Perhaps if you post your registration code I'll be able to tell.
Regardless to that issue, your server should be able to handle multiple registrations for the same device. When you send the registration id to your server, send with it another unique id created by your app or by your server, and that would allow you to identify when you get a new registration id for an existing device, in which case you'll replace the old registration id with the new one.
Another thing you should do at the server is handle the case where gcm server returns a canonical registration id, in which case you should replace the id you used for sending the message with the canonical one.
Related
I'm using Firebase Messaging's device groups to send messages right now, and I've run into an issue where device group notification keys will still successfully send a message to devices even if their device ID has been updated.
An example would be like this:
Install app on Device A and get Device_A: device_registration_ID = "25".
We create a device group with Device A device_group_1: registration_key = "group1".
Sending a message to device_group_A will result in a success.
We delete and reinstall the app
The old device_registation_ID = "25" is now invalid, and a new one is created by Firebase Device_A: device_registration_ID = "100"
I create a new device group with Device A device_group_2: registration_key = "group2"
Sending a message to device_group_2 is a Success
Sending a message to device_registration_ID = "100" is a Success
Sending a message to the old device_registration_id = "25" is a Failure as we expect
However, sending a message to old device_group_1 is still a Success
Why does the old device_group_1 still work? The old device_registration_ID doesn't work anymore, so how does the device_group_1 even send a message to my device?
I want to maintain Device Groups such that when an app is deleted or a device_registration_ID is replaced the respective Device Group can be updated as well. I wanted to do this on the server side (Ie. check for failures when sending messages and comb through the failures to update my device_registraiton_IDs) because relying on the client code can result in some misses (Ie. if the client uninstalls the app while offline, there's no way to update the server). However, right now there's never any failures for device group messaging because even with defunct IDs they still somehow work!
Is there any other way I update my device_registration_IDs on the server side, preferably through messaging failures?
EXTRA. Creating a device group with a defunct device_registration_ID results in a no valid registration id
My team has been developing an app using GCM for the last 4 months, and today we discovered that with the recent update of Google Play Services GCM changed significantly. Until now we've been sending notifications from our backend server to our users using this format of Registration ID:
APA91bF7h6vQkqIaF9ECQ_V............w
That was generated with the classic GoogleCloudMessaging.getInstance(context).register(SENDER_ID) method.
But now, with the new update, you generate the registration ID doing InstanceID.getInstance(this)getToken(SENDER_ID, GoogleCloudMessaging.INSTANCE_ID_SCOPE, null);
and by doing so the generated Registration IDs have the next format:
c3wlROAji5d:APA91bF_iz3Muub6Mu...a6n-ClpQ
Notice how there is first a section of 11 characters followed by a colon and then a long sequence starting with APA91b
So my question is, when sending notifications from my server to my clients should I use the new format as it is or strip the fragment before the colon and use the segment starting with APA91b as before.
Thanks for the attention
You should always use the full registration id to send messages to your users: it is best to think of the registration id as a totally opaque string (i.e., internal structure does not necessarily mean anything).
I am experiencing a problem with getting duplicate notifications using GCM push notifications on the Android client side.
I install the app and register with GCM like so: regid = gcm.register(SENDER_ID);
This gives me a registration ID (for example: "ABC"). If I try and re-register I get the same ID ("ABC"). If I clear the app data (in Androids app settings) and reload the app I get the same ID ("ABC"), however if I uninstall the app and reinstall, I get a new ID (for example: "DEF").
This is fine, however after registering the second time, my app will now receive notifications sent to both "ABC" and "DEF". This results in some in my app.
Is there a way to ignore all messages sent to any reg ID except the last one that was registered (in my example: "DEF")?
The example I am using to test is the official GCM-Client (https://developer.android.com/google/gcm/client.html).
There's no way to ignore the messages sent to the old reg id.
The best you can do:
In the client side, try to store some app data on the external storage. This would allow you to identify if the app was previously installed on the device, and to tell your server to replace the old reg id with the new one.
In the server side, handle canonical reg id responses from GCM. This won't prevent the sending of a message to an old reg id, but once you send a message to such reg id, you'll immediately remove the old reg id from your DB, and won't send any more messages to it.
i get issue gcm notification. I get always duplicate(2,3,4) notification GCM after once update new version app android from eclipse. Where in the server, id gcm just one registered, how to fix it ? sorry for my english
the solution of this issue is sending a unique ID for each device (likes : Device ID in android), and making it a primary key
so any update of the token for this unique id it will be updated instead of adding new one
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.