How can i get my registration ID device

abdel picture abdel · May 30, 2012 · Viewed 11.5k times · Source

What do I need to send a push notification for android (like iOS I need a device udid to send a simple push)?

And if I need to get the registration id of my device how can i get it?

Thank you.

Answer

Bobs picture Bobs · May 30, 2012

Do you need this?

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