欢迎来到尧图网

客户服务 关于我们

您的位置:首页 > 科技 > 名人名企 > 鸿蒙中开启关闭防截屏录屏

鸿蒙中开启关闭防截屏录屏

2025/5/11 21:25:27 来源:https://blog.csdn.net/2302_79548774/article/details/144396079  浏览:    关键词:鸿蒙中开启关闭防截屏录屏

1.申请权限

  "requestPermissions": [{"name": "ohos.permission.PRIVACY_WINDOW"},],

2.ui

import { common, OpenLinkOptions, Want } from '@kit.AbilityKit'
import { BusinessError } from '@kit.BasicServicesKit'
import { window } from '@kit.ArkUI';
import { promptAction } from '@kit.ArkUI';@Entry()
@Component
struct TransactionHistory {async setWindowPrivacyModeTrue(context: Context) {let windowClass: window.Window = await window.getLastWindow(context)try {windowClass.setWindowPrivacyMode(true, (err: BusinessError) => {const errCode: number = err.code;if (errCode) {console.error('Failed to set the window to privacy mode. Cause:' + JSON.stringify(err));if (errCode == 201) {}return;}promptAction.showToast({message: `已开启 防截屏录屏`,duration: 2000,bottom: '500lpx'});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));}}async setWindowPrivacyModeFalse(context: Context) {let windowClass: window.Window = await window.getLastWindow(context)try {windowClass.setWindowPrivacyMode(false, (err: BusinessError) => {const errCode: number = err.code;if (errCode) {console.error('Failed to set the window to privacy mode. Cause:' + JSON.stringify(err));if (errCode == 201) {}return;}promptAction.showToast({message: `已关闭 防截屏录屏`,duration: 2000,bottom: '500lpx'});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));}}build() {Column() {Button('开启防截屏录屏').onClick(() => {this.setWindowPrivacyModeTrue(getContext())})Button('关闭防截屏录屏').onClick(() => {this.setWindowPrivacyModeFalse(getContext())})}.width('100%')}
}

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com

热搜词