开启隐私模式失败
{
"name" : "ohos.permission.PRIVACY_WINDOW"
},
onWindowStageCreate(windowStage: window.WindowStage): void {
AppStorage.setOrCreate('ynetWindowStage',windowStage)
windowStage.getMainWindow((err, data) => {
if (err.code) {
console.error('Failed to obtain the main window. Cause: ' + JSON.stringify(err));
YLog.error(`[LifeCycle] Failed to obtain the main window. Cause ${JSON.stringify(err)}`)
return;
}
let mainWindow: window.Window = data;
AppStorage.setOrCreate('ynetMainWindow',mainWindow)// 设置隐私模式,防止截屏、录屏
export function setPrivacyMode (isPrivacyMode: boolean) {
// 取缓存中的主窗口
let windowClass = AppStorage.get("ynetMainWindow") as window.Window;
// 设置防录屏、截屏,isPrivacyMode: true,禁止截屏/录屏; isPrivacyMode: false,允许截屏/录屏;
try {
windowClass.setWindowPrivacyMode(isPrivacyMode, (err) => {
if (err.code) {
console.error('Failed to set the window to privacy mode-err. 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-exception:' + JSON.stringify(exception));
}
}
第一步:
第二步: