Android 获取设备令牌?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/22713363/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-20 06:22:38  来源:igfitidea点击:

Get devices token?

androidgetdevicetoken

提问by Philip

I'm trying to get the token of my device. Thought this:

我正在尝试获取我设备的令牌。这么想的:

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

would do the trick, but it doesnt, it returns null. Why?

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

回答by Gene

Read this. Hope this helps.

读这个。希望这可以帮助。

http://android-developers.blogspot.be/2011/03/identifying-app-installations.html

http://android-developers.blogspot.be/2011/03/identifying-app-installations.html

OR

或者

String android_id = Settings.Secure.getString(getApplicationContext().getContentResolver(),
                Settings.Secure.ANDROID_ID);

OR

或者

You can try getting the UUID or IMEI.

您可以尝试获取 UUID 或 IMEI。

OR

或者

If you're on the Parse Developer Console: enter image description here

如果您在 Parse 开发者控制台上: 在此处输入图片说明

回答by meredrica

There exists no stable unique ID for an Android device. You can maybe work with the ANDROID_IDbut it will change on OS Upgrade/System reset

Android 设备不存在稳定的唯一 ID。您也许可以使用ANDROID_ID,但它会在操作系统升级/系统重置时发生变化

回答by Ali Sherafat

i'm using this code and it works for me! BUTdevice token is undefined for some devices in parse console (i don't know why!)

我正在使用此代码,它对我有用! 但是解析控制台中的某些设备未定义设备令牌(我不知道为什么!)

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