2

I am trying to get the serial number of my Lenovo Idea Tab running Android. I tried all the options available in Google search, which are:

Class<?> c = Class.forName("android.os.SystemProperties");
Method get = c.getMethod("get", String.class);  
String serial = (String) get.invoke(c, "ril.serialnumber" );
String serial_no = (String) get.invoke(c, "ro.serialno");
String serial_no1 = (String) get.invoke(c, "sys.serialnumber");

ro.serialno is giving a value as 8TYDE67HYLUOZPOZ, but the serial number shown in "Status -> About Tablet" is HGC2TKH4, and the printed serial number in the back side of the tab is also HGC2TKH4.

ril.serialnumber and sys.serialnumber are empty.

In some other tabs also, the ril.serialnumber is empty, but it is supposed to have the serial number, I hope.

Please, how can I find the real serial number of my device on Android?

Remy Lebeau
  • 555,201
  • 31
  • 458
  • 770
user3659154
  • 21
  • 1
  • 3

3 Answers3

6

I recently had to also get the SN for a lenovo tablet. You can use the following methods

public static String getIMEI(Context context) {
    TelephonyManager telephonyManager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
    return telephonyManager != null ? (telephonyManager.getDeviceId() != null ? telephonyManager.getDeviceId() : "N/A") : "N/A";
}

public static String getSN() {
    String deviceSN = "N/A";
    try {
        Class<?> propClass = Class.forName("android.os.SystemProperties");
        Method getProp = propClass.getMethod("get", String.class, String.class);
        deviceSN = (String) getProp.invoke(propClass, "gsm.sn1", "N/A");
    } catch (Exception ignored) {
    }
    return deviceSN;
}

public static String getPN() {
    String devicePN = "N/A";
    try {
        Class<?> propClass = Class.forName("android.os.SystemProperties");
        Method getProp = propClass.getMethod("get", String.class, String.class);
        devicePN = (String) getProp.invoke(propClass, "ro.lenovosn2", "N/A");
    } catch (Exception ignored) {
    }
    return devicePN;
}

Lenovo has custom property names, you can use the following adb command to see all available props:

adb shell getprop
EmcLIFT
  • 276
  • 3
  • 6
1

I used this code to get the serial number from the Lenovo tab 7 Essential (2017 model running Android 7.0). I was also using it to get Samsung serial numbers (Galaxy Camera 1/2 running Android 4 and a Tab A running 6, then updated to 7.1.1).

private static String UNKNOWN = "unknown";
static String GetDeviceSerialNumber() {
    String serial;
    if (Build.MANUFACTURER.toLowerCase().contains("lenovo")) {
        serial = GetLenovoManufacturerSerialNumber();
    } else {
        serial = GetSamsungManufacturerSerialNumber();
    }
    if (serial == null || serial.equals(UNKNOWN)) {
        serial = Build.SERIAL; // this is NOT usually the serial displayed on the device, but it returns something
    }
    return serial;
}
// http://stackoverflow.com/questions/14161282/serial-number-from-samsung-device-running-android
private static String GetSamsungManufacturerSerialNumber() {
    String serial = GetSystemPropertyString("ril.serialnumber"); // older Samsung devices - works on Galaxy Camera 1
    if (serial == null || serial.equals(UNKNOWN)) {
        serial = GetSystemPropertyString("sys.serialnumber"); // newer Samsung devices
    }
    return serial;
}
// https://stackoverflow.com/questions/23773975/how-to-get-real-serial-number-of-lenovo-tab-in-android
private static String GetLenovoManufacturerSerialNumber() {
    return GetSystemPropertyString("ro.lenovosn2");
}
private static String GetSystemPropertyString(String prop) {
    try {
        Class<?> c = Class.forName("android.os.SystemProperties");
        Method get = c.getMethod("get", String.class, String.class);
        return (String)get.invoke(c, prop, UNKNOWN);
    } catch (Exception ignored) {
        ignored.printStackTrace();
        return null;
    }
}

Hopefully that's helpful to someone.

Simurr
  • 672
  • 1
  • 4
  • 19
-1

HI you can get everything about your device hardware by using the following code.

Build.BRAND  //Brand Name

Build.DEVICE   //Device Name

Build.MODEL   //Model No

Build.SERIAL  //Serial No

import this namespace :: import android.os.Build;

Let me know if my answer is right or not.

Sivakumar
  • 633
  • 4
  • 9
  • Thanks for the support. But in my SDK version Build.Serial is not available. But everything else is there like Brand, Model, Device, ID etc. How do we resolve this? – user3659154 May 21 '14 at 10:17
  • Build.Serial was added in API 9. SO it will be available based on your API Version. It will be available above API 9 – Sivakumar May 21 '14 at 10:22