可以在web页面注册防截屏录屏的方法,通过jsbridge传递到web页面中。在口令输入页面调用该方法禁止录屏即可。参考文档:https://developer.huawei.com/consumer/cn/doc/best-practices-V5/bpta-harmony-application-security-V5\#section18516943133816setWindowPrivacyMode方法需要添加权限:ohos.permission.PRIVACY\_WINDOW参考文档:https://developer.huawei.com/consumer/cn/doc/harmonyos-references-V5/js-apis-window-V5\#setwindowprivacymode9//module.json5 "requestPermissions": [ { "name": "ohos.permission.PRIVACY_WINDOW" } ] // EntryAbility.ets onWindowStageCreate(windowStage: window.WindowStage): Promise<void> { // Main window is created, set main page for this ability hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onWindowStageCreate'); ..... AppStorage.setOrCreate('windowStage', windowStage); } // WebDemo.ets import web_webview from '@ohos.web.webview'; import { window } from '@kit.ArkUI'; class JsBridge { windowClass: window.Window constructor(windowStage: window.WindowStage) { this.windowClass = windowStage.getMainWindowSync() } setPrivacyMode(flag: boolean) { this.windowClass.setWindowPrivacyMode(flag); } } @Entry @Component struct WebComponent { controller: web_webview.WebviewController = new web_webview.WebviewController() windowStage: window.WindowStage = AppStorage.get('windowStage') as window.WindowStage @State jsBridge: JsBridge = new JsBridge(this.windowStage) build() { Column() { Web({ src: $rawfile("index.html"), controller: this.controller }) // 将对象注入到web端 .javaScriptProxy({ object: this.jsBridge, name: "jsBridge", methodList: ["setPrivacyMode"], controller: this.controller }) } } } // index.html <!DOCTYPE html> <html lang="en"> <body> <h1>setPrivacyMode</h1> <button type="button" onclick="callArkTS(true)">禁止截屏</button> <button type="button" onclick="callArkTS(false)">可以截屏</button> <script> function callArkTS(flag) { jsBridge.setPrivacyMode(flag); } </script> </body> </html>
可以在web页面注册防截屏录屏的方法,通过jsbridge传递到web页面中。在口令输入页面调用该方法禁止录屏即可。
参考文档:https://developer.huawei.com/consumer/cn/doc/best-practices-V5/bpta-harmony-application-security-V5\#section18516943133816
setWindowPrivacyMode方法需要添加权限:ohos.permission.PRIVACY\_WINDOW
参考文档:https://developer.huawei.com/consumer/cn/doc/harmonyos-references-V5/js-apis-window-V5\#setwindowprivacymode9