Is there a unique Android device ID?
Settings.Secure#ANDROID_ID
returns the Android ID as an unique for each user 64-bit hex string.
import android.provider.Settings.Secure;
private String android_id = Secure.getString(getContext().getContentResolver(),
Secure.ANDROID_ID);
Also read Best practices for unique identifiers: https://developer.android.com/training/articles/user-data-ids
Best possible way to get device Id in Android
ANDROID ID:
On a device first boot, a random value is generated and stored. This value is available via Settings.Secure.ANDROID_ID. It’s a 64-bit number that should remain constant for the lifetime of a device. ANDROID_ID seems a good choice for a unique device identifier because it’s available for smartphones and tablets.
Issues:
However, the value may change if a factory reset is performed on the device. There is also a known bug with a popular handset from a manufacturer where every instance has the same ANDROID_ID. Clearly, the solution is not 100% reliable.
UUID:
As the requirement for most applications is to identify a particular installation and not a physical device, a good solution to get a unique id for a user if to use the UUID class.
Issues:
UUID.randomUUID() method generates a unique identifier for a specific installation. You have just to store that value and your user will be identified at the next launch of your application. You can also try to associate this solution with the Android Backup service to keep the information available for the user even if he installs your application on another device.
CONCLUSION:
Identify a particular device on Android is not an easy thing. There are many good reasons to avoid that. The best solution is probably to identify a particular installation by using the UUID solution. However, if you want absolutely identify a particular device physically, you can try to use the ANDROID_ID solution. Not 100% reliable but better than another solution.
Unique ID of Android device
Look at the constant
ANDROID_ID in android.provider.Secure.Settings
to see if that helps.
I am adding a few useful links from official docs;
- Best Practices for Unique Identifiers
- Changes to Device Identifiers in Android O
Related Topics
Drawerlayout Double Drawer (Left and Right Drawers Simultaneously)
Android: How to Get a Radiogroup with Togglebuttons
Android Facebook Sdk 3.0 Gives "Remote_App_Id Does Not Match Stored Id" While Logging In
Firebase Overwrites Signin with Google Account
Add a Background Image to Shape in Xml Android
Redraw a Single Row in a Listview
Retaining Position in Listview After Calling Notifydatasetchanged
Rotating Image on a Canvas in Android
How to Achieve Gapless Audio Looping So Far on Android
A Way to Get Unlock Event in Android
How to Change a Layer-List Drawable
Android: Programmatically Detect If Device Has Hardware Menu Button
Adding an Onclicklistener to Listview (Android)
Android Facebook 4.0 Sdk How to Get Email, Date of Birth and Gender of User
The Android Emulator Is Not Starting, Showing "Invalid Command-Line Parameter"
Converting Yuv->Rgb(Image Processing)->Yuv During Onpreviewframe in Android