android获取手机序列号

/**
 * 获取手机序列号
 *
 * @return 手机序列号
 */
@SuppressLint({"NewApi", "MissingPermission"})
public static String getSerialNumber() {
    String serial = "";
    try {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {//9.0+
            serial = Build.getSerial();
        } else if (Build.VERSION.SDK_INT > Build.VERSION_CODES.N) {//8.0+
            serial = Build.SERIAL;
        } else {//8.0-
            Class c = Class.forName("android.os.SystemProperties");
            Method get = c.getMethod("get", String.class);
            serial = (String) get.invoke(c, "ro.serialno");
        }
    } catch (Exception e) {
        e.printStackTrace();
        Log.e("e", "读取设备序列号异常:" + e.toString());
    }
    return serial;
}

你可能感兴趣的:(Android)