防止录频和截屏的方案:1.在module.json5添加ohos.permission.PRIVACY\_WINDOW权限2.在EntryAbility文件中添加下面的代码:onWindowStageCreate(windowStage: window.WindowStage): void { let windowClass: window.Window = windowStage.getMainWindowSync(); // 获取应用主窗口 AppStorage.setOrCreate("windowClass",windowClass); }3.在所在页面添加代码:import { window } from '@kit.ArkUI'; import { BusinessError } from '@ohos.base'; @Entry @Component struct Index43 { private windowStage = AppStorage.get("windowStage") as window.WindowStage private windowClass = AppStorage.get("windowClass") as window.Window build() { Row() { Column() { Text('禁止截屏') .fontSize(50) .fontWeight(FontWeight.Bold) .onClick(() => { let isPrivacyMode: boolean = true; try { this.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)); } }) Text('允许截屏') .fontSize(50) .fontWeight(FontWeight.Bold) .onClick(() => { let isPrivacyMode: boolean = false; try { this.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)); } }) } .width('100%') } .height('100%') } }
防止录频和截屏的方案:
1.在module.json5添加ohos.permission.PRIVACY\_WINDOW权限
2.在EntryAbility文件中添加下面的代码:
3.在所在页面添加代码: