2

I used device information to create unique ID for android device but after i read Security Tips of google, want to change it somehow.

Quote from Google:

If it's possible to design your application in a way that does not require any permissions, that is preferable. For example, rather than requesting access to device information to create a unique identifier, create a GUID for your application.

How can i have a Unique ID for a Device that doesn't change next time app runs or device reboot?

Mehran Zamani
  • 831
  • 9
  • 31

2 Answers2

2

You can use below method:

Settings.Secure.getString(getContentResolver(), Settings.Secure.ANDROID_ID)

that returns unique android id. and don't need any permissions.

Also you can check this link.

Community
  • 1
  • 1
Ahmad Vatani
  • 1,630
  • 4
  • 21
  • 34
  • Settings.Secure.ANDROID_ID is indeed device info! – Mehran Zamani Apr 09 '17 at 07:05
  • oh, i see. you are right but i think it isn't unique and [there is a small chance that 2 android IDs be the same](http://stackoverflow.com/questions/4799394/is-secure-android-id-unique-for-each-device). [and also](https://developer.android.com/reference/android/provider/Settings.Secure.html#ANDROID_ID): When a device has multiple users (available on certain devices running Android 4.2 or higher), each user appears as a completely separate device, so the ANDROID_ID value is unique to each user. – Mehran Zamani Apr 09 '17 at 07:51
  • 1
    But during factory reset, this ID will get changed right ? – Firnaz May 29 '18 at 09:40
  • 1
    Maybe @Firnaz !!! Also it's known to be null sometimes and documented as "can change upon factory reset". Use at your own risk, and I should say it can be easily changed on a rooted phone – Ahmad Vatani Jun 01 '18 at 11:09
0

you can use IMEI number which is unique to every phone but you need to ask

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

during runtime above api 23 and above.

Frankenxtein
  • 483
  • 7
  • 18
  • so what do you think about google post? is it possible to have unique ID without problem and not using permissions? – Mehran Zamani Apr 09 '17 at 08:09
  • 1
    using Settings.Secure.getString(getContentResolver(), Settings.Secure.ANDROID_ID) can give you unique id without having to ask for permission but from what i know, this value may change upon factory reset. – Frankenxtein Apr 09 '17 at 08:14