鸿蒙开发中如何设置禁止截屏录屏?
使用 MainWindow的 setWindowPrivacyMode(true)
方法.
具体来说, 在 EntryAbility的 onWindowStageCreate(windowStage: window.WindowStage)
方法中可以获取到 MainWindow:
windowStage.getMainWindow((err, windowClass: window.Window) => {
this.mainWindow = windowClass;
});
然后通过 MainWindow设置进入隐私模式, 实现禁止截屏和录屏.
/**
* Sets whether is private mode or not.
*
* @permission ohos.permission.PRIVACY_WINDOW
* @param { boolean } isPrivacyMode in private mode if true, or not if false.
* @returns { Promise<void> } Promise that returns no value.
* @throws { BusinessError } 201 - Permission verification failed. The application does not have the permission required to call the API.
* @throws { BusinessError } 401 - Parameter error. Possible cause: 1. Mandatory parameters are left unspecified;
* 2. Incorrect parameter types.
* @throws { BusinessError } 1300002 - This window state is abnormal.
* @syscap SystemCapability.WindowManager.WindowManager.Core
* @atomicservice
* @since 12
*/
setWindowPrivacyMode(isPrivacyMode: boolean): Promise<void>;