How to get unique device hardware id in Android?

Android

Android Problem Overview


How to get the unique device ID in Android which cannot be changed when performing a phone reset or OS update?

Android Solutions


Solution 1 - 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 @ https://stackoverflow.com/questions/2785485/is-there-a-unique-android-device-id/2853253#2853253

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"/>

Solution 2 - Android

I use following code to get Android id.

String android_id = Secure.getString(this.getContentResolver(),
            Secure.ANDROID_ID);
   
Log.d("Android","Android ID : "+android_id);

enter image description here

Solution 3 - Android

Please read this official blog entry on Google developer blog: http://android-developers.blogspot.be/2011/03/identifying-app-installations.html

> Conclusion For the vast majority of applications, the requirement is > to identify a particular installation, not a physical device. > Fortunately, doing so is straightforward. > > There are many good reasons for avoiding the attempt to identify a > particular device. For those who want to try, the best approach is > probably the use of ANDROID_ID on anything reasonably modern, with > some fallback heuristics for legacy devices

.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionPrvNView Question on Stackoverflow
Solution 1 - AndroidRaghunandanView Answer on Stackoverflow
Solution 2 - AndroidChintan RathodView Answer on Stackoverflow
Solution 3 - AndroidWaza_BeView Answer on Stackoverflow