androidaccountsmultiple-accountsgoogle-cloud-messaging

Multiple custom accounts in combination with GCMIntentService


I encountered a problem with having multiple accounts of my own custom type.
I use GCM (Google Cloud Messaging) to recieve messages from our application server. Now since you need to make your own implementation of GCMIntentService extending GCMBaseIntentService, you need to override onRegistered(Context context, String regId) , the problem here lies in that I want to send saved data on the account (an auth token) to our application server in that method. So that the application server knows which device/registration id belongs to a certain account in our own database.

How am I going to find out for which account I just registered to GCM with inside the onRegistered() method? (I couldn't find any similar question =( )


Solution

  • You will have to do that manually. GCM doesn't care about user accounts. It only cares about the device itself. In your case I would register device with GCM once and then reuse the same registration ID for all your users, meaning that when sending GCM notification you will have to include some identification data to know for which user you are sending that particular notification.

    So in a nutshell: register your device with GCM once and then send registration ID you receive + all custom user accounts IDs to your application server. When sending notification, add user ID into notification message and then use it to determine to which custom account user it is intended.