always duplicate notification GCM after update new version app android - android

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

Related

Changed gcm sender id in iOS plist, return error registering with GCM 401

Created two projects one for Android and another for iOS. Works total fine if using separated project number and api key. But my problem is that I want to use one pair project number and api key on my Server side, so if I change the sender id in iOS plist, it returns that the operation couldn't be completed with an error 401 when asking for a registration_id to GCM.
Anyone has ideas?
Thanks
Hmm sounds like maybe you generated the sender ID from the wrong developer console. It has to be a sender ID generated from the same project.

How to use GCM Registration ID to send notifications

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).

Get GCM canonical registration ID without sending a message

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.

Gcm device registration issue in android

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.

Registration confusion Android GCM

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.

Categories

Resources