Android: How to programmatically access the device serial number shown in the AVD manager (API Version 8)
This is the hardware serial number. To access it on
Android Q (>= SDK 29)
android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE
is required. Only system apps can require this permission. If the calling package is the device or profile owner then theREAD_PHONE_STATE
permission suffices.Android 8 and later (>= SDK 26) use
android.os.Build.getSerial()
which requires the dangerous permission READ_PHONE_STATE. Usingandroid.os.Build.SERIAL
returns android.os.Build.UNKNOWN.Android 7.1 and earlier (<= SDK 25) and earlier
android.os.Build.SERIAL
does return a valid serial.
It's unique for any device. If you are looking for possibilities on how to get/use a unique device id you should read here.
For a solution involving reflection without requiring a permission see this answer.
Get hardware serial number of Android device
The solution is very simple:
Class<?> c = Class.forName("android.os.SystemProperties");
Method get = c.getMethod("get", String.class, String.class);
serialNumber = (String) get.invoke(c, "sys.serialnumber", "Error");
if(serialNumber.equals("Error")) {
serialNumber = (String) get.invoke(c, "ril.serialnumber", "Error");
}
This will get you the serial number of most samsung devices. I use the "sys.serialnumber" value to get the serial number of my SM-T210 (Galaxy Tab 3) and SM-T230 (Galaxy Tab 4) tablets, but probably works with a lot more Samsung tablets. The "ril.serialnumber" is to get the value on my Samsung GT-I8550L (Galaxy Win).
I hope this helps.
How to find serial number of Android device?
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 ;-)
Related Topics
Android: Move a View on Touch Move (Action_Move)
How to Add Calendar Events in Android
How to Send a File in Android from a Mobile Device to Server Using Http
API Key for Gcm Is Suddenly Invalid? Unauthorized (401) Error
How to Have Placeholders in Strings.Xml for Runtime Values
Classnotfoundexception After Adt Update
How to Control the Width and Height of the Default Alert Dialog in Android
How Are Android Touch Events Delivered
Getcolor(Int Id) Deprecated on Android 6.0 Marshmallow (API 23)
How to Return a Result (Startactivityforresult) from a Tabhost Activity
Android Create Shortcuts on the Home Screen
How to Send String from One Activity to Another
Failed to Resolve: Com.Google.Firebase:Firebase-Core:11.2.0
Android Update Activity UI from Service