Android推送通知 - 如何获取设备ID [英] Android push notifications - how to get the device id

查看:1116
本文介绍了Android推送通知 - 如何获取设备ID的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我正在努力的是我应该获得设备的部分当我需要发送推送通知时,我可以使用该设备ID。



所以我有这样的代码:

  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);
}

我认为这一行

  final String regId = GCMRegistrar.getRegistrationId(this); 

准备让我使用设备ID,这样我就可以将它存储在某个地方。但是我认为我不知道如何实际工作。有人可以向我解释我如何获得设备的唯一ID,以便我可以将其存储以供进一步推送通知?

设备的唯一ID实际上是基于设备和应用程序安装的唯一ID。 GCMRegistrar.getRegistrationId(context)会为您提供唯一的ID。如果您希望在注册后获取它,它将被传递到GCMIntentService的onRegistered方法中,您必须重写该方法才能使其正常工作。


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.

这篇关于Android推送通知 - 如何获取设备ID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆