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 .
-
go to http://stackoverflow.com/questions/2785485/is-there-a-unique-android-device-id?rq=1 – M D Jun 17 '14 at 11:42
-
This library provides a unique ID per device with Identity.getDeviceId(context) and an identifier for your app installation via Identity.getInstallationId(context). – caw Mar 8 '15 at 22:38
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.
-
1This is not exact. This ID might change upon rooting phone, and also upon doing a "factory reset". So, this could be used - but do not count on it. – gilonm Jun 17 '14 at 11:48
-
-
-
1@user3736827 : There is no specific deviceId concept, you need to check the unique string that identifies your phone like the one mentioned in the answer or you can use IMEI number. – Siddharth_Vyas Jun 17 '14 at 11:53
-
@Siddharth Oh, just saw this link now.. I simply had this problem a couple weeks ago... – gilonm Jun 17 '14 at 11:54
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.
-
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 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. – Y.S 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 ? – Y.S Mar 18 '15 at 19:07
-
1
Try this:
Secure.getString(getContext().getContentResolver(), Secure.ANDROID_ID);