简体   繁体   English

Android推送通知 - 如何获取设备ID

[英]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. 我坚持使用Google的云通知创建推送通知的过程。

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. 我正在处理的是我应该获取设备的设备ID的部分,以便稍后我可以使用该设备ID,当我需要发送推送通知时。

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. 打算给我设备ID,以便我可以存储在某个地方。 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? 有人可以向我解释如何获取设备的唯一ID,以便我可以存储它以进一步推送通知吗?

The 'unique id' of the device is actually a unique id based on device and app installation. 设备的“唯一ID”实际上是基于设备和应用程序安装的唯一ID。 The GCMRegistrar.getRegistrationId(context) will give you that unique ID. GCMRegistrar.getRegistrationId(context)将为您提供该唯一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. 如果您希望在注册后获取它,则将其传递到GCMIntentService的onRegistered方法,您必须覆盖该方法才能使其正常工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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