Manoj Patel
Manoj Patel

Reputation: 49

GCM Application ID, Instance

I want to clarify if the Application ID and the Instance ID are same ? Also how to use them in real time scenario. Is my understanding correct when we get the Registration token the Application ID is taken care and the registration token know which application the push notification is for? The document suggest to keep the Instance ID in the application server to track the applications but not sure what kind of tracking this means.

Upvotes: 2

Views: 854

Answers (2)

John
John

Reputation: 5297

Clients have to also register and when they do, they will receive their tokens.

Instance ids are used by the clients to generate and refresh tokens. They do so by providing the Sender id which identifies application that can push notification to client, that would be your server.

ApplicationID is the client app that is registering to receive message.

From the docs:

An Android application needs to register with GCM connection servers before it can receive messages. When an app registers, it receives a registration token and sends it to the app server. The client app should store a boolean value indicating whether the registration token has been sent to the server.

Google provides the Instance ID API to handle the creation and updating of registration tokens. To obtain a token, call instanceID.getToken, providing the app server's sender ID and setting the scope to GoogleCloudMessaging.INSTANCE_ID_SCOPE. Do not call this method in the main thread; instead, use a service that extends IntentService as shown:

InstanceID instanceID = InstanceID.getInstance(this);
String token = instanceID.getToken(getString(R.string.gcm_defaultSenderId),
        GoogleCloudMessaging.INSTANCE_ID_SCOPE, null);

Tracking of these tokens means that you should have registration procedure in which you will ask clients for their tokens. Once you obtain client token, it should be stored into database. This is responsibility of push application developer.

GCM requires payload you wish to send, together with token or list of tokens. GCM cannot know of tokens unless you provide them.

Here is a link to instance id explanation:

instaceID

Upvotes: 3

Rohit Heera
Rohit Heera

Reputation: 2737

* Yes there are two Id's here one application id which you get from Google console when you register your application for GCM service.At that time Google console provide a AppID which is used to register our application on GCM server. Now Second when you register your application on GCM server it will provide us a unique DeviceID which is unique though all devices which can use the same application.The purpose of DeviceID is to uniquely identify all the devices that can register with that particular application id.

Upvotes: 0

Related Questions