if
(canIUse(
'SystemCapability.AuthenticationServices.HuaweiID.MinorsProtection'
)) {
minorsProtection.getMinorsProtectionInfo()
.then((minorsProtectionInfo: minorsProtection.MinorsProtectionInfo)
=
> {
/
/
获取未成年人模式开启状态
const minorsProtectionMode: boolean
=
minorsProtectionInfo.minorsProtectionMode;
hilog.info(
0x0000
,
'testTag'
,
'Succeeded in getting minorsProtectionMode is: %{public}s'
,
minorsProtectionMode.valueOf());
/
/
未成年人模式已开启,获取年龄段信息
if
(minorsProtectionMode) {
const ageGroup: minorsProtection.AgeGroup | undefined
=
minorsProtectionInfo.ageGroup;
if
(ageGroup) {
hilog.info(
0x0000
,
'testTag'
,
'Succeeded in getting lowerAge is: %{public}s'
, ageGroup.lowerAge.toString());
hilog.info(
0x0000
,
'testTag'
,
'Succeeded in getting upperAge is: %{public}s'
, ageGroup.upperAge.toString());
}
}
else
{
/
/
未成年人模式未开启,建议应用跟随系统未成年人模式,展示正常内容
}
})
.catch((error: BusinessError<
object
>)
=
> {
this.dealGetMinorsInfoAllError(error);
});
}
else
{
hilog.info(
0x0000
,
'testTag'
,
'The current device does not support the invoking of the getMinorsProtectionInfo interface.'
);
}
dealGetMinorsInfoAllError(error: BusinessError<
object
>): void {
hilog.error(
0x0000
,
'testTag'
, `Failed to getMinorsProtectionInfo. Code: ${error.code}, message: ${error.message}`);
}