16

I have htc one b model android phone. I want to know my device ID. I do not know how could I finding out my device ID .

user3736827
  • 185
  • 1
  • 1
  • 6
  • go to [http://stackoverflow.com/questions/2785485/is-there-a-unique-android-device-id?rq=1](http://stackoverflow.com/questions/2785485/is-there-a-unique-android-device-id?rq=1) – M D Jun 17 '14 at 11:42
  • [This library](https://github.com/delight-im/Android-BaseLib) provides a unique ID per device with [Identity.getDeviceId(context)](https://github.com/delight-im/Android-BaseLib/blob/master/Source/src/im/delight/android/baselib/Identity.java) and an identifier for your app installation via [Identity.getInstallationId(context)](https://github.com/delight-im/Android-BaseLib/blob/master/Source/src/im/delight/android/baselib/Identity.java). – caw Mar 08 '15 at 22:38

3 Answers3

18

Try this :

    String deviceId = Secure.getString(this.getContentResolver(),
            Secure.ANDROID_ID);
    Toast.makeText(this, deviceId, Toast.LENGTH_SHORT).show();

android.provider.Settings.Secure.ANDROID_ID

A 64-bit number (as a hex string) that is randomly generated on the device’s first boot and should remain constant for the lifetime of the device.

Source Link : http://blog.vogella.com/2011/04/11/android-unique-identifier/

Note : The value may change if a factory reset is performed on the device.

Ajeett
  • 814
  • 2
  • 7
  • 18
Siddharth_Vyas
  • 9,972
  • 10
  • 39
  • 69
9

Try this:

TelephonyManager TM = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);

// IMEI No.
String imeiNo = TM.getDeviceId();

// IMSI No.
String imsiNo = TM.getSubscriberId();

// SIM Serial No.
String simSerialNo  = TM.getSimSerialNumber();

// Android Unique ID
String androidId = Settings.Secure.getString(this.getContentResolver(),Settings.Secure.ANDROID_ID);

Don't forget to add

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

to your manifest file.

Prashant Gosai
  • 1,186
  • 1
  • 10
  • 18
Yash Sampat
  • 30,051
  • 12
  • 94
  • 120
  • hello sir I am confused by answer....I just want to check unique ID of my htc phone....but how could i do this...everybody give me link and code to check id......but i dont know how to implement this...please tell me in brief – user3736827 Jun 17 '14 at 12:04
  • Hi, the thing is, a "unique ID" could mean many different things depending on the context and on your specific situation. The [official Android blog](http://android-developers.blogspot.in/2011/03/identifying-app-installations.html) recommends that you use the ANDROID_ID, which is the fourth option above in my code and which is supposedly the least risk-prone option. Just keep in mind that the ANDROID_ID is reset each time the user performs a factory-reset, so you may want to take this into consideration for how it may impact your app. – Yash Sampat Jun 17 '14 at 12:09
  • doesn't work, error 'ANDROID_ID cannot be resolved or is not a field' – Shirish Herwade Mar 18 '15 at 16:00
  • 2
    @ShirishHerwade: apologies, its in the **Settings.Secure** package. I've edited the answer, can you please try it now ? – Yash Sampat Mar 18 '15 at 19:07
  • 1
    already tried that, :) it worked. But thanks for your time – Shirish Herwade Mar 19 '15 at 06:40
  • @ZygoteInit yes I would like to do that if my problem gets solved; but the issue is i'm using this device no to download apk using chrome extension, but its giving error... and i'm not able to download apk, so my problem still not fixed. By the way, thanks for your time and help. and so I have upvote the answer already. But hey... its not my question so can't accept – Shirish Herwade Mar 19 '15 at 10:37
  • @Y.S , Please help me on it, I want to get the ID of the device, which even not changed when device is rooted or wiped out. What could be possible solution of it? – Ravindra Kushwaha Oct 21 '20 at 07:55
  • I would like to, when you're using "READ_PHONE_STATE" permission make sure to ask this permission to user at runtime as this permission is categorized as "Dangerous permission" in official doc. – syed dastagir Jan 27 '21 at 08:02
1

Try this:

Secure.getString(getContext().getContentResolver(), Secure.ANDROID_ID);
Garg
  • 2,731
  • 2
  • 36
  • 47
dileep
  • 347
  • 4
  • 16