2014-03-28 152 views
2

我试图获取我的设备的令牌。想到这个:获取设备令牌?

ParseInstallation parseInstallation = new ParseInstallation(); 
    String deviceToken = (String) parseInstallation.get("deviceToken"); 

会做的伎俩,但它does not,它返回null。 为什么?

+0

ü要设备令牌或ID? –

+0

设备令牌,我想将它保存在数据库中,以便其他设备可以读取它并向它们发送内容。 – Philip

+1

根据[类似的问题]('https://www.parse.com/questions/android-how-do-i-get-the-devicetoken),''get'-call应该在'Parse.initialize'之后进行。在parse.com – Peterino

回答

0

Android设备没有稳定的唯一ID。你也许可以使用ANDROID_ID,但它会在操作系统升级/系统重置时更改

+0

那么我如何获得设备令牌来发送推送通过从设备到设备的解析? – Philip

+0

您为每个注册设备获得一个唯一的推送ID。只需查看文档https://developer.android.com/google/gcm/index.html – meredrica

-1

我使用这个代码,它为我的作品! 设备令牌是未定义在解析控制台某些设备(我不知道为什么!)

String token = (String) ParseInstallation.getCurrentInstallation().get("deviceToken");