4

To get the Unique Device ID on Android phones/tablets, we use the following:

((TelephonyManager) ctx.getSystemService(Context.TELEPHONY_SERVICE)).getDeviceId()

But for Kindle Fire, we can't get one.

starball
  • 20,030
  • 7
  • 43
  • 238
Shane Oliver
  • 944
  • 1
  • 8
  • 17

2 Answers2

4

You should try using the following line:

deviceId = Secure.getString(context.getContentResolver(), Secure.ANDROID_ID);

This will get the device ID from tablets, the code you're using only works on phones (it will return null on tablets)

Lars
  • 4,082
  • 2
  • 20
  • 20
0

put

<uses-permission android:name="android.permission.READ_PHONE_STATE" />

then

try this:

public String deviceId;

then:

// ------------- get UNIQUE device ID
        deviceId = String.valueOf(System.currentTimeMillis()); // --------
                                                                // backup for
                                                                // tablets etc
        try {
            final TelephonyManager tm = (TelephonyManager) getBaseContext()
                    .getSystemService(Main.TELEPHONY_SERVICE);
            final String tmDevice, tmSerial, tmPhone, androidId;
            tmDevice = "" + tm.getDeviceId();
            tmSerial = "" + tm.getSimSerialNumber();
            androidId = ""
                    + android.provider.Settings.Secure.getString(
                            getContentResolver(),
                            android.provider.Settings.Secure.ANDROID_ID);
            UUID deviceUuid = new UUID(androidId.hashCode(),
                    ((long) tmDevice.hashCode() << 32) | tmSerial.hashCode());
            deviceId = deviceUuid.toString();
        } catch (Exception e) {
            Log.v("Attention", "Nu am putut sa iau deviceid-ul !?");
        }
        // ------------- END get UNIQUE device ID

from here -> Is there a unique Android device ID?

Community
  • 1
  • 1
OWADVL
  • 10,704
  • 7
  • 55
  • 67