如何获取HarmonyOS鸿蒙Next系统的指纹
如何获取HarmonyOS鸿蒙Next系统的指纹 在 Android 中,你可以使用 Build 类的 FINGERPRINT 常量来获取系统的指纹。系统指纹包含了设备制造商、Android版本、ROM版本等信息,可以用来唯一标识一个设备的系统镜像。在鸿蒙上可以如何获取呢?
可以获取系统的相关参数
参考:https://developer.huawei.com/consumer/cn/doc/harmonyos-references-V5/js-apis-device-info-V5
rom版本: deviceInfo.displayVersion// NOH-AN00 204.0.0.43(SP9C00E43R1P5)
设备id: deviceInfo.udid // 需要system_basic级权限ohos.permission.sec.ACCESS_UDID
设备类型(平板、手机): deviceInfo.deviceType // phone
build版本: deviceInfo.osFullName // OpenHarmony-4.0.8.5(beta1)
deviceInfo.buildVersion // 5
更多关于如何获取HarmonyOS鸿蒙Next系统的指纹的实战系列教程也可以访问 https://www.itying.com/category-93-b0.html
要获取HarmonyOS鸿蒙Next系统的指纹,可以使用@ohos.userIAM.userAuth
模块中的UserAuth
类。首先,需要在config.json
文件中声明ohos.permission.ACCESS_BIOMETRIC
权限。然后,通过UserAuth
类的getAuthInstance
方法获取UserAuth
实例,并调用auth
方法进行指纹认证。认证结果通过回调函数返回,包括成功、失败或取消等状态。具体代码示例如下:
import userIAM_userAuth from '@ohos.userIAM.userAuth';
// 获取UserAuth实例
let userAuth = userIAM_userAuth.getAuthInstance();
// 定义认证参数
let authParam = {
challenge: new Uint8Array([1, 2, 3, 4, 5, 6, 7, 8]),
authType: userIAM_userAuth.UserAuthType.FINGERPRINT,
authTrustLevel: userIAM_userAuth.AuthTrustLevel.ATL1
};
// 进行指纹认证
userAuth.auth(authParam, (err, result) => {
if (err) {
console.error('Authentication failed:', err);
return;
}
if (result.code === userIAM_userAuth.ResultCode.SUCCESS) {
console.log('Authentication successful');
} else {
console.log('Authentication failed with code:', result.code);
}
});
此代码展示了如何在HarmonyOS鸿蒙Next系统中进行指纹认证。