2

I need to generate a reliable device ID. I'm using Secure.getString(this.getContentResolver(), Secure.ANDROID_ID) at the moment, but it changes after factory reset or with flashing another ROM. Could you suggest a truly hardware ID that cannot be changed?

Upd: none of the solutions suggested so far help: the suggested IDs either can change, or not always available, or both. And I definitely need it to survive reinstallation, too.

Violet Giraffe
  • 31,078
  • 43
  • 182
  • 317

2 Answers2

0

You can get the IMEI number like this:

TelephonyManager tm = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
String imei = tm.getDeviceId();

In your AndroidManifest.xml:

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

The IMEI number is guaranteed to be unique and will never change on any device.

Adam Monos
  • 4,277
  • 1
  • 21
  • 25
0

I haven't found anything better than Secure.getString(this.getContentResolver(), Secure.ANDROID_ID) so have to continue using it, despite its shortcoming.

Violet Giraffe
  • 31,078
  • 43
  • 182
  • 317