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.
How to get unique device hardware id in Android?
Update: 19 -11-2019
The below answer is no more relevant to present day.
So for any one looking for answers you should look at the documentation linked below
https://developer.android.com/training/articles/user-data-ids
Old Answer - Not relevant now.
You check this blog in the link below
http://android-developers.blogspot.in/2011/03/identifying-app-installations.html
ANDROID_ID
import android.provider.Settings.Secure;
private String android_id = Secure.getString(getContext().getContentResolver(),
Secure.ANDROID_ID);
The above is from the link @ Is there a unique Android device ID?
More specifically, Settings.Secure.ANDROID_ID. This is a 64-bit quantity that is generated and stored when the device first boots. It is reset when the device is wiped.
ANDROID_ID seems a good choice for a unique device identifier. There are downsides: First, it is not 100% reliable on releases of Android prior to 2.2 (“Froyo”). Also, there has been at least one widely-observed bug in a popular handset from a major manufacturer, where every instance has the same ANDROID_ID.
The below solution is not a good one coz the value survives device wipes (“Factory resets”) and thus you could end up making a nasty mistake when one of your customers wipes their device and passes it on to another person.
You get the imei number of the device using the below
TelephonyManager telephonyManager = (TelephonyManager)getSystemService(Context.TELEPHONY_SERVICE);
telephonyManager.getDeviceId();
http://developer.android.com/reference/android/telephony/TelephonyManager.html#getDeviceId%28%29
Add this is manifest
<uses-permission android:name="android.permission.READ_PHONE_STATE"/>
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
Android - unique and constant device ID
I found that Secure.ANDROID_ID is the best choice. This is a 64-bit quantity that is generated and stored when the device first boots. But it resets on device factory reset.
there are some reports that shows some devices has same Secure.ANDROID_ID on all instances.
we can add extra items (like sim serial, GCM instance id or ...) to the Secure.ANDROID_ID and generate new unique fingerprint.
Related Topics
Android Force Gpu Rendering How to Enable and Disable
Imageview of Png Doesn't Appear (Maybe It's Too Big)
How to Control Navigationview Margin Between Menu Items
Notification Disappears After Showing
How to Close the Current Fragment by Using Button Like the Back Button
How to Get Context in Android Mvvm Viewmodel
How to Open Draw Overlay Permission Popup in Miui
How to Keep a Bottom Nav Bar from Being Pushed Up on Keyboard Shown
Adb.Exe Not Found After Installing Android Studio
How to Use Python to Execute Adb Commands
How to Check If a Value Exists Already in a Firebase Data Class Android
How to Display a Loading Spinner While Getting Data from Firestore
How to Receive Fcm Push Notifications When App Is Killed
How to Remove Unnecessary Margins from Toolbar
Retrofit Body Giving Null Values But Coming Perfect in Postman