Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android push notifications - how to get the device id

I am stucked with the process of creating a push notification using Google's cloud notifications.

What I am working on is the part where I am supposed to get the device id of the device so that I can use that device id later on, 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 that this line

final String regId = GCMRegistrar.getRegistrationId(this);

Was going to get me the device id so I can store that somewhere. But I think I am way off track in how this is actually meant to work. Could someone please explain to me how I can get the unique id of the device so I can store it for further push notifications?

like image 504
Genadinik Avatar asked Oct 07 '22 07:10

Genadinik


1 Answers

The 'unique id' of the device is actually a unique id based on device and app installation. The GCMRegistrar.getRegistrationId(context) will give you that unique ID. If you are looking to get it after it registers, it is passed into the onRegistered method of the GCMIntentService that you have to override to make it work.

like image 68
toadzky Avatar answered Oct 10 '22 02:10

toadzky