如何获取我的注册 ID 设备

Posted

技术标签:

【中文标题】如何获取我的注册 ID 设备【英文标题】:How can i get my registration ID device 【发布时间】:2012-05-30 08:14:00 【问题描述】:

我需要为 android 发送什么推送通知(像 ios 我需要一个设备 udid 来发送一个简单的推送)?

如果我需要获取设备的注册 ID,我该如何获取?

谢谢。

【问题讨论】:

只能发送设备ID,不能发送注册ID。 我尝试使用注册 ID 并且它可以工作,但我没有找到如何发送带有设备 ID 的推送通知。那么你有链接吗? 【参考方案1】:

你需要这个吗?

public static String getDeviceID(Context context) 
    final TelephonyManager tm = (TelephonyManager) context
            .getSystemService(Context.TELEPHONY_SERVICE);

    final String tmDevice, tmSerial, tmPhone, androidId;
    tmDevice = "" + tm.getDeviceId();
    tmSerial = "";// + tm.getSimSerialNumber();
    androidId = ""
            + android.provider.Settings.Secure.getString(
                    context.getContentResolver(),
                    android.provider.Settings.Secure.ANDROID_ID);

    UUID deviceUuid = new UUID(androidId.hashCode(),
            ((long) tmDevice.hashCode() << 32) | tmSerial.hashCode());
    String deviceId = deviceUuid.toString();

    return deviceId;

【讨论】:

以上是关于如何获取我的注册 ID 设备的主要内容,如果未能解决你的问题,请参考以下文章