Android: How to Programmatically Access the Device Serial Number Shown in the Avd Manager (Api Version 8)

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 the READ_PHONE_STATE permission suffices.

  • Android 8 and later (>= SDK 26) use android.os.Build.getSerial() which requires the dangerous permission READ_PHONE_STATE. Using android.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



Leave a reply



Submit