【HarmonyOS】鸿蒙中防止截屏和录屏(设置窗口为隐私模式)
在Entry > module.json5 中配置如下权限。
·
export class windowManager {
// 设置窗口为隐私模式
static privacyScreen(isPrivacy: boolean = false) {
let windowClass: window.Window | undefined = undefined
let isPrivacyMode = isPrivacy
try {
window.getLastWindow(getContext(), (error, data) => {
if (error.code) {
console.log('error= ' + JSON.stringify(error))
return
}
windowClass = data
windowClass.setWindowPrivacyMode(isPrivacyMode, (err) => {
if (err.code) {
console.error('Failed to set the window to privacy mode. Cause:' + JSON.stringify(err));
return;
}
console.info('Succeeded in setting the window to privacy mode.');
});
})
} catch (exception) {
console.error('Failed to set the window to privacy mode. Cause:' + JSON.stringify(exception));
}
}
}
在Entry > module.json5 中配置如下权限
{ "name": "ohos.permission.PRIVACY_WINDOW" }
更多推荐
所有评论(0)