how can we get device token for android for push notification?
61,362
try {
InstanceID instanceID = InstanceID.getInstance(this);
String token = instanceID.getToken(getString(R.string.gcm_defaultSenderId),
GoogleCloudMessaging.INSTANCE_ID_SCOPE, null);
Log.i(TAG, "GCM Registration Token: " + token);
}catch (Exception e) {
Log.d(TAG, "Failed to complete token refresh", e);
}
Related videos on Youtube
![Tarique Shamsi](https://lh6.googleusercontent.com/-hv2kdqhra50/AAAAAAAAAAI/AAAAAAAAAAA/q92Zr7h-X0c/photo.jpg?sz=256)
Comments
-
Tarique Shamsi almost 2 years
i want to implement push notification in my application.i want to know,how we get the device token for push notification in android after enabling the google cloud messaging API.How can we get a device token for a particular device??
-
Rajesh over 8 yearsDid you check developers.google.com/cloud-messaging/android/client?
-
Tarique Shamsi over 8 yearsRajesh,these documentation provided by you based on about registration token id.actually i want to know about particular device token id for push notification
-
-
Tarique Shamsi over 8 yearsin which part of project,we add these codes,and how we get the device token?
-
Nikunj over 8 yearsyou can add above code in any Activity or Service. It's better to get token in Launcher Activity.And put your "SenderId" in R.string.gcm_defaultSenderId
-
Tarique Shamsi over 8 yearsbut this code is working for registration token,actually i want the device token for particular android device.how can we get particular device token for android device
-
Nikunj over 8 yearsto integrate GCM in Android you only need "device token" which you get from above code and you have to send it to server.
-
Louis over 6 yearsInstanceID should be retrieved using
InstanceID.getInstance(context).getId();