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

打印 上一主题 下一主题

主题 831|帖子 831|积分 2493

1.申请权限
  1.   "requestPermissions": [
  2.       {
  3.         "name": "ohos.permission.PRIVACY_WINDOW"
  4.       },
  5.     ],
复制代码
2.ui
  1. import { common, OpenLinkOptions, Want } from '@kit.AbilityKit'
  2. import { BusinessError } from '@kit.BasicServicesKit'
  3. import { window } from '@kit.ArkUI';
  4. import { promptAction } from '@kit.ArkUI';
  5. @Entry()
  6. @Component
  7. struct TransactionHistory {
  8.   async setWindowPrivacyModeTrue(context: Context) {
  9.     let windowClass: window.Window = await window.getLastWindow(context)
  10.     try {
  11.       windowClass.setWindowPrivacyMode(true, (err: BusinessError) => {
  12.         const errCode: number = err.code;
  13.         if (errCode) {
  14.           console.error('Failed to set the window to privacy mode. Cause:' + JSON.stringify(err));
  15.           if (errCode == 201) {
  16.           }
  17.           return;
  18.         }
  19.         promptAction.showToast({
  20.           message: `已开启 防截屏录屏`,
  21.           duration: 2000,
  22.           bottom: '500lpx'
  23.         });
  24.         console.info('Succeeded in setting the window to privacy mode.');
  25.       });
  26.     } catch (exception) {
  27.       console.error('Failed to set the window to privacy mode. Cause:' + JSON.stringify(exception));
  28.     }
  29.   }
  30.   async setWindowPrivacyModeFalse(context: Context) {
  31.     let windowClass: window.Window = await window.getLastWindow(context)
  32.     try {
  33.       windowClass.setWindowPrivacyMode(false, (err: BusinessError) => {
  34.         const errCode: number = err.code;
  35.         if (errCode) {
  36.           console.error('Failed to set the window to privacy mode. Cause:' + JSON.stringify(err));
  37.           if (errCode == 201) {
  38.           }
  39.           return;
  40.         }
  41.         promptAction.showToast({
  42.           message: `已关闭 防截屏录屏`,
  43.           duration: 2000,
  44.           bottom: '500lpx'
  45.         });
  46.         console.info('Succeeded in setting the window to privacy mode.');
  47.       });
  48.     } catch (exception) {
  49.       console.error('Failed to set the window to privacy mode. Cause:' + JSON.stringify(exception));
  50.     }
  51.   }
  52.   build() {
  53.     Column() {
  54.       Button('开启防截屏录屏').onClick(() => {
  55.         this.setWindowPrivacyModeTrue(getContext())
  56.       })
  57.       Button('关闭防截屏录屏').onClick(() => {
  58.         this.setWindowPrivacyModeFalse(getContext())
  59.       })
  60.     }.width('100%')
  61.   }
  62. }
复制代码


免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!更多信息从访问主页:qidao123.com:ToB企服之家,中国第一个企服评测及商务社交产业平台。
回复

使用道具 举报

0 个回复

倒序浏览

快速回复

您需要登录后才可以回帖 登录 or 立即注册

本版积分规则

雁过留声

金牌会员
这个人很懒什么都没写!

标签云

快速回复 返回顶部 返回列表