求教大佬们,排查了其他问题,程序可以正常运行,给SN写死也能跑下去,但是无法动态获取当前设备的SN(SerialNo),
感觉是可能缺少某些权限啥的?
下面是获取SN的代码:
// #ifdef APP-PLUS
var Build = plus.android.importClass("android.os.Build");
var Manifest = plus.android.importClass("android.Manifest");
var MainActivity = plus.android.runtimeMainActivity();
var SystemProperties = plus.android.importClass("android.os.SystemProperties")
var serial = ''
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) { //9.0+
var ArrPermissions = [
Manifest.permission.READ_PHONE_STATE,
];
function PermissionCheck(permission) {
if (Build.VERSION.SDK_INT >= 23) {
if (MainActivity.checkSelfPermission(permission) == -1) {
return false;
}
}
return true;
}
function PermissionChecks(Arr) {
var HasPermission = true;
for (var index in Arr) {
var permission = Arr[index];
//如果此处没有权限,则是用户拒绝了
if (!PermissionCheck(permission)) {
HasPermission = false;
break;
}
}
return HasPermission;
}
function PermissionRequest(Arr) {
var REQUEST_CODE_CONTACT = 101;
if (Build.VERSION.SDK_INT >= 23) {
MainActivity.requestPermissions(Arr, REQUEST_CODE_CONTACT);
}
}
//如果没有权限,则申请权限
if (!PermissionChecks(ArrPermissions)) {
PermissionRequest(ArrPermissions); //此处申请权限,会弹出一个让你授权可获取设备号信息权限框
} else { //如果拥有权限
serial = Build.getSerial()
}
} else if (Build.VERSION.SDK_INT > Build.VERSION_CODES.N) { //8.0+
if (Build.SERIAL) {
serial = Build.SERIAL;
}
} else {
if (SystemProperties.get('ro.serialno')) {
serial = SystemProperties.get('ro.serialno')
}
}
this.sn = serial
// #endif
Diligent_UI
可以的
2023-06-19 17:53