getMinorsProtectionInfoSync:该方法为同步方法,调用该方法获取未成年人模式的开启状态,以及年龄段信息。应用可跟随未成年人模式开启状态,进行开启/关闭应用的未成年人模式,使用年龄段信息,展示适龄内容。
建议应用调用getMinorsProtectionInfoSync()接口进行查询,代码样例:
import { minorsProtection } from '@kit.AccountKit'; @Entry @Component struct minorsProtection1 { @State minorsProtectionMode: boolean = false; @State status: string = ''; build() { Column() { Row() { Text('当前未成年模式开启状态:' + this.status) .fontSize(20) .margin(20) } .width('90%') Row() { Button('点击查询') .onClick(() => { this.minorsProtectionMode = minorsProtection.getMinorsProtectionInfoSync().minorsProtectionMode; this.status = this.minorsProtectionMode + ''; }) } .width('90%') .justifyContent(FlexAlign.Center) } .height('100%') .width('100%') .justifyContent(FlexAlign.Center) } }