Should I generate an Android GCM registration identifier for a specific application or a specific user?

I am developing an application that has a login function. I only generate one gcm registration id for each application. If another user enters the application, he will begin to receive notifications intended for the previous user. How to cope with this situation so that each user receives a notification designed for him / her? Should I generate a gcm reg id for each user? What is the standard way to deal with this situation?

+5
source share
4 answers

You can try the following things:

  • When the user logs out, send a request to delete the token on your server and delete it in your application;
  • Once the user logs out, you can simply remove the association of “User ID” with “Current GCM” (or login ID) on your server. And when someone logs in again, you will create a new association with this token.

GCM current is application specific, but the association you create on your server is completely up to you.

And I cannot stress this enough, the token created by GCM, APP SPECIFIC . If your user is registering on multiple devices, your server should handle this by associating the user ID with multiple Registration ID tokens.

An identifier issued by GCM servers in an Android application that allows you to receive messages. When an Android application has a registration ID, it sends it to a third-party application server, which uses it to identify each registered message device for this Android application. In other words, the Registration ID is tied to a specific Android application running on a specific device.

And from the documents, your server should also:

Before you can write client applications using GCM, you must have an application server that meets the following criteria:

  • Ability to communicate with your client.
  • Ability to send correctly formatted requests to the GCM connection server.
  • Ability to process requests and resend them using exponential backup.
  • Ability to store API key keys and client tokens.
  • Ability to generate message identifiers to uniquely identify each sent message. Message identifiers must be unique to the sender identifier.

EDIT: More on GCM here .

For further reading, you can also read “Device Group Messages” .

You can also download sample code here .

+7
source

You must store the regID according to the user.

This is because there are test cases from which user1 exits and user2 logs in. In this case, if you saved a specific regID application and are not tied to the user, then user2 will also receive a notification.

Thus, you need to store regID according to the user, application, and also with a specific device.

+5
source

Of course, every time someone downloads your application, your application must register them with GCM and receive a registry, this needs to be sent to your application server, on your application server you need to figure out who you are by sending a notification too. you probably should send some login information and a reg token when they log in so that you can identify each person, and then write some php or jquery to send to individual users or everyone. You must also send a reg token every time they log in, as they may change without warning.

Your application server should be able to handle remote unused reg tokens and add new ones.

+1
source

Each Android device generates a unique GCM registry identifier. A push notification from the server will be sent according to the device identifier. Thus, during login, you can send the GCM reg identifier to your server. Therefore, from the server side, a push notification will be sent to the device .., that is, the actual functionality.

Hope this helps

0
source

Source: https://habr.com/ru/post/1232185/


All Articles