Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how can we get device token for android for push notification?

Tags:

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??

like image 364
Tarique Shamsi Avatar asked Nov 06 '15 06:11

Tarique Shamsi


People also ask

What is device token in push notification?

The push notification networks identify each device by device token. A device token is not a device IMEI but an ID to identify a certain mobile app on a certain device. It is issued by calling libraries of FCM, JPush, or APNs.


1 Answers

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); } 
like image 61
Nikunj Avatar answered Dec 08 '22 06:12

Nikunj