user2957954
user2957954

Reputation: 1249

Several gcm users for one app

I have a question about client's registration for Google Cloud Messaging.

For example, a have a smartphone with an android app installed. The phone will be used by several users that have different app accounts (that are not equal to google, facebook etc. accounts).

I would like to bind somehow an app account and GCM registration token. Is it in principal possible -- without de- and re-installing the app -- that different app users receive different registration tokens and then -- only their messages?

Is GCM registration token in general attached to the device ID or to Google account?

Thank you in advance.

Upvotes: 0

Views: 910

Answers (3)

Shivam Chopra
Shivam Chopra

Reputation: 639

NOTE : Instance ID provides a unique ID per instance of your Android and iOS apps.

Let's figure out what are the important points when we register the device on GCM

  1. When you install the application, the application is only install (not anything else)
  2. When some user login to the app, then and only then register the application on GCM explicitly.
    Register Client Apps
  3. When you register the application on GCM , you'll get the registrationToken from GCM which you need to save in your server.

Now, lets find out how we can handle GCM for one application which is using by multiple users. When the user login to the application,

Step 1 : Register the app on GCM
Step 2 : Registration the app on GCM, will give you a registration token
Step 3 : Update the user's information with the registration token in your server
Step 4 : When the user logout, remove the registration token from the user's information in your server
Step 5 : When other user's login, refresh the token and follow Step 3

Upvotes: 0

Arthur Thompson
Arthur Thompson

Reputation: 9225

The InstanceID is tied to an installed instance of an app on a particular device. Getting a token is also affected by the sender (your app server). If you have the same app instance and the same sender then you will get the same token (till it is revoked for some reason).

To target different users within a single app instance, you would have to include user identifiers within the payload of the downstream message. Then decide what to do based on which user the message is addressed to. This will mean that you would send messages even if the addressed user is not currently logged in.

You could revoke and regenerate tokens when switching users but that is not the intended use of the API.

Upvotes: 2

Jitender Dev
Jitender Dev

Reputation: 6925

Yes, It is possible.

Remember how you generate a unique API key using Application's package. for each Application and a unique server key to identify incoming push messages.

Your application package is used to differentiate b/w the incoming notification from the cloud.

Upvotes: 0

Related Questions