简体   繁体   中英

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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM