Android push notifications - how to get device id

I am stuck in the process of creating push notifications using Google cloud notifications.

I am working on where I should get the device identifier in order to subsequently use this device identifier when I need to send a push notification.

So, I have this code:

GCMRegistrar.checkDevice(this); GCMRegistrar.checkManifest(this); final String regId = GCMRegistrar.getRegistrationId(this); if (regId.equals("")) { GCMRegistrar.register(this, SENDER_ID); } else { //Log.v(TAG, "Already registered"); } 

and I thought this line

 final String regId = GCMRegistrar.getRegistrationId(this); 

I was going to get the device identifier so that I could save it somewhere. But I think that I am aloof from how it is actually intended to work. Can someone please explain to me how I can get a unique device identifier so that I can store it for future push notifications?

+4
source share
1 answer

The โ€œunique identifierโ€ of a device is a truly unique identifier based on the installation of the device and application. GCMRegistrar.getRegistrationId(context) will provide you with a unique identifier. If you want to receive it after registering it, it is passed to the onRegistered method from the GCMIntentService method, which you must override to make it work.

+4
source

Source: https://habr.com/ru/post/1440357/


All Articles