|
@@ -44,8 +44,10 @@ public final class DeviceUtils {
|
|
|
Method get = c.getMethod("get", String.class);
|
|
|
if (Build.VERSION.SDK_INT <= 28) {//28 is andoird 9.0 24-7.0 22-5.1
|
|
|
serial = (String) get.invoke(c, "ro.serialno");
|
|
|
+ AppLogUtils.e("SDK_INT <= 28--serial:"+serial);
|
|
|
} else {
|
|
|
serial = (String) get.invoke(c, "persist.sys.hrSerial");//vendor.gsm.serial
|
|
|
+ AppLogUtils.e("SDK_INT > 28--serial:"+serial);
|
|
|
}
|
|
|
} catch (Exception e) {
|
|
|
e.printStackTrace();
|
|
@@ -54,12 +56,44 @@ public final class DeviceUtils {
|
|
|
|
|
|
// 兼容版本11的紫鹏
|
|
|
if (TextUtils.isEmpty(serial)) {
|
|
|
- if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
|
|
- // 注意清单文件加上READ_PHONE_STATE权限,不然还是会获取失败
|
|
|
- serial = Build.getSerial();
|
|
|
- }else{
|
|
|
+// if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
|
|
+// // 注意清单文件加上READ_PHONE_STATE权限,不然还是会获取失败
|
|
|
+// serial = Build.getSerial();
|
|
|
+// }else{
|
|
|
+// serial = Build.SERIAL;
|
|
|
+// }
|
|
|
+
|
|
|
+
|
|
|
+ if(TextUtils.isEmpty(serial)) {
|
|
|
serial = Build.SERIAL;
|
|
|
+ AppLogUtils.e("SDK_INT < O--serial:"+serial);
|
|
|
+ if(!TextUtils.isEmpty(serial)&&!serial.equals("unknown")) {
|
|
|
+ // 判断非空和非unknown,则返回
|
|
|
+ return serial;
|
|
|
+ }else{
|
|
|
+ serial = "";
|
|
|
+ }
|
|
|
}
|
|
|
+
|
|
|
+
|
|
|
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
|
|
+ try {
|
|
|
+ // 高版本走到这里,又没有权限,会报错。建议targetSdkVersion为22,避免后续降版本提示应用未安装
|
|
|
+ serial = Build.getSerial();
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ AppLogUtils.e("SDK_INT >= O--serial:"+serial);
|
|
|
+ if(!TextUtils.isEmpty(serial)&&!serial.equals("unknown")) {
|
|
|
+ // 判断非空和非unknown,则返回
|
|
|
+ return serial;
|
|
|
+ }else{
|
|
|
+ serial = "";
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
}
|
|
|
|
|
|
if (TextUtils.isEmpty(serial)) {
|