I need to use a unique ID for an Android app and I thought the serial number for the device would be a good candidate. How do I retrieve the serial number of an Android device in my app ?
+3
A:
String deviceId = Settings.System.getString(getContentResolver(),
Settings.System.ANDROID_ID);
Although, it is not guaranteed that the Android ID will be an unique identifier.
Anthony Forloney
2010-02-23 22:29:12
@Anthony its returns me null
PM - Paresh Mayani
2010-08-26 11:56:02
@Paresh Mayani, It's hard to tell what may be the issue without looking at the code. My only assumption is that `getContentResolver` is returning `null`. However, it may be worth while opening a question and posting your code.
Anthony Forloney
2010-08-26 12:40:00
The emulator returns a null value, but I get a reasonable result when I run this code on my nexus one
Mike
2010-09-01 21:36:30
+7
A:
TelephonyManager tManager = (TelephonyManager)myActivity.getSystemService(Context.TELEPHONY_SERVICE);
String uid = tManager.getDeviceId();
getSystemService is a method from the Activity class. getDeviceID() will return the MDN or MEID of the device depending on which radio the phone uses (GSM or CDMA).
Each device MUST return a unique value here (assuming it's a phone). This should work for any Android device with a sim slot or CDMA radio. You're on your own with that Android powered microwave ;-)
haseman
2010-02-23 23:10:38
@Hasemam This is not working for me, giving "Force Close" error
PM - Paresh Mayani
2010-08-26 11:51:42
@Hasemam its running fine now after adding <uses-permission android:name="android.permission.READ_PHONE_STATE"></uses-permission> permission in androidManifest.xml file.
PM - Paresh Mayani
2010-08-26 11:54:08
+2
A:
Don't forget to add
android:name="android.permission.READ_PHONE_STATE"
to your manifest
Michael SIlveus
2010-09-30 16:57:13