Monday 29 November 2021

Unique device ID of Android

 On every android device Settings.Secure.ANDROID_ID will returns the Android ID as an unique for each user 64-bit hex string. This id should be unique to devices, but how it is set depends on the implementation of the device manufacturer.

Here is the code how we can get this ID,


import android.provider.Settings.Secure;

private String android_id = Secure.getString(getContext().getContentResolver(), Secure.ANDROID_ID);


The Android Id may change on factory reset of the phone and the user is also able to change it on rooted phones. But if you need an id to identify your user it should be fine.


Also read Best practices for unique identifiers: https://developer.android.com/training/articles/user-data-ids





No comments:

Post a Comment