Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is GCM Registration ID?

Hello I want to add gcm to my application. My application is a news application. User can view news after registration. Application asks user interests (economy, sports, cars etc.) and saves them. I want to send news to user as notification from php and mysql. I must decide to send which news to which users. So i need registration ids.

Is it android device number? Or a combination of Android device google account and android device number?
Or a combination of Android device google account and android device number and My application user id?

Example

Android device id = a => GCM RegID=a
Android device id = a , google account id=b => GCM RegID=ab
Android device id = a , google account id=b, application x user id=c => GCM RegID=abc

If x user logs out from application and y user login in same device will GCM RegId change? If it does not change and i push economy news to y user (who does not interest about economy) device will show wrong notification to wrong user. So what is GCM registration id?

like image 927
sipdorus Avatar asked Aug 27 '14 11:08

sipdorus


People also ask

What is a GCM ID?

Google Cloud Messaging (GCM) is a free service that enables developers to send messages between servers and client apps. This includes downstream messages from servers to client apps and upstream messages from client apps to servers.

How to find GCM Sender ID?

Go to the Settings section to view your Project number, which is your GCM Sender ID.

What is GCM service on Android?

Google Cloud Messaging (GCM) is a service that allows you to send push notifications from your server to your users' Android devices, and also to receive messages from devices on the same connection.


2 Answers

A Registration ID is an identifier assigned by GCM to a single instance of a single application installed on an Android device. The device is assigned this identifier when it registers to Google Cloud Messaging. The GCM documentation doesn't specify what information is encoded in this identifier.

In some older Android versions (pre-4.0.4), a Google account is required to register to GCM.

If multiple users use the same app on the same device, they will be have the same registration ID, since GCM doesn't care about which user logs-in to the app. It's up to your server to determine which user is currently logged in to your app in a certain device, and based on that knowledge to deliver only relevant GCM messages to that device.

like image 153
Eran Avatar answered Oct 05 '22 23:10

Eran


Registration id is a unique identifier for particular package on a particular device. GCM identifies the target using this id.

In your case this id is not going to solve your problem.

Case 1:

If you unregister device from GCM on logout, and register again, this is not guaranty that registration id will be different (may be and may not be).

Case 2:

GCM refreshes registration id time to time.

So this id is not going to a solution to identify logged user.


Possible solution

Send only generic message from GCM to device, like "hey you have something new, go to server". Now device will request to server for new item. Here server will identify the logged user and give him the respective data.

like image 33
Pankaj Kumar Avatar answered Oct 06 '22 00:10

Pankaj Kumar