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.
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 ;-)
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.
Related Topics
How to Measure Distance to Object With Camera
How to Center the Elements in Constraintlayout
Getting Simple Json Object Response Using Retrofit Library
How to Convert Image to Zpl Code for Printing Using Zebra Printer
How to Start Android Application on Device Boot
How to Remove Bottom Navigation View and Toolbar in Some Fragments If Using Navigation Controller
Edittext Background Base Line Color Changing Based on Its Focus in Android
How to Retry Retrofit Call on Http Errors (401) When Using Rxjava
Not Opening Specific Activity on Notification Click When the App Is in Background/Not Running
How Listview'S Recycling Mechanism Works
How to Start an Activity from Background in Android 10
Android Volley - Basicnetwork.Performrequest: Unexpected Response Code 400
Full Screen Without Navigation & Status Bars
Android Studio - Textview Not Showing in Design View Layout
Missing Android Platform(S) Detected
How to Center Items of a Recyclerview