IT评测·应用市场-qidao123.com

标题: 鸿蒙中开启关闭防截屏录屏 [打印本页]

作者: 雁过留声    时间: 2024-12-12 20:49
标题: 鸿蒙中开启关闭防截屏录屏
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企服之家,中国第一个企服评测及商务社交产业平台。




欢迎光临 IT评测·应用市场-qidao123.com (https://dis.qidao123.com/) Powered by Discuz! X3.4