我怎样才能获得我的注册ID设备

abd*_*del 9 android push-notification android-c2dm

我需要为Android发送推送通知(比如iOS我需要一个设备udid来发送一个简单的推送)?

如果我需要获取我的设备的注册ID,我怎么能得到它?

谢谢.

Bob*_*obs 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;
}
Run Code Online (Sandbox Code Playgroud)