import { BusinessError } from '@ohos.base';
let isPrivacyMode: boolean = true;
try {
windowClass.setWindowPrivacyMode(isPrivacyMode, (err: BusinessError) => {
const errCode: number = err.code;
if (errCode) {
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));
}
可以使用 setWindowPrivacyMode(isPrivacyMode: boolean, callback: AsyncCallback<void>): void 来设置窗口是否为隐私模式,使用 callback 异步回调。设置为隐私模式的窗口,窗口内容将无法被截屏或录屏。此接口可用于禁止截屏/录屏的场景。
需要权限:ohos.permission.PRIVACY_WINDOW
参考代码如下:
实现步骤: