HarmonyOS 口令输入界面可以被截屏或者录屏怎么处理

HarmonyOS
2天前
浏览
收藏 0
回答 1
待解决
回答 1
按赞同
/
按时间
superinsect

在EntryAbility的onWindowStageCreate中缓存:

let windowClass: window.Window = windowStage.getMainWindowSync()
// 获取应用主窗口
AppStorage.setOrCreate("windowClass", windowClass)

使用

import { window } from '@kit.ArkUI';
import { BusinessError } from '@ohos.base';

@Entry
@Component
struct Index43 {
  private windowClass = AppStorage.get("windowClass") as window.Window
  @State message: string = 'Hello World';

  build() {
    Row() {
      Column() {
        Text('禁止截屏')
          .fontSize(50)
          .fontWeight(FontWeight.Bold)
          .onClick(() => {
            let isPrivacyMode: boolean = true;
            try {
              this.windowClass.setWindowPrivacyMode(isPrivacyMode, (err: BusinessError) => {
                const errCode: number = err.code;
                if (errCode) {
                  console.error('Failed to set the window to privacy mode. Cause:' + JSON.stringify(err));
                  return;
                }
                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));
            }
          })

        Text('允许截屏')
          .fontSize(50)
          .fontWeight(FontWeight.Bold)
          .onClick(() => {
            let isPrivacyMode: boolean = false;
            try {
              this.windowClass.setWindowPrivacyMode(isPrivacyMode, (err: BusinessError) => {
                const errCode: number = err.code;
                if (errCode) {
                  console.error('Failed to set the window to privacy mode. Cause:' + JSON.stringify(err));
                  return;
                }
                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));
            }
          })
      }
      .width('100%')
    }
    .height('100%')
  }
}
import { window } from '@kit.ArkUI';
import { BusinessError } from '@ohos.base';

@Entry
@Component
struct Index43 {
  private windowClass = AppStorage.get("windowClass") as window.Window
  @State message: string = 'Hello World';

  build() {
    Row() {
      Column() {
        Text('禁止截屏')
          .fontSize(50)
          .fontWeight(FontWeight.Bold)
          .onClick(() => {
            let isPrivacyMode: boolean = true;
            try {
              this.windowClass.setWindowPrivacyMode(isPrivacyMode, (err: BusinessError) => {
                const errCode: number = err.code;
                if (errCode) {
                  console.error('Failed to set the window to privacy mode. Cause:' + JSON.stringify(err));
                  return;
                }
                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));
            }
          })

        Text('允许截屏')
          .fontSize(50)
          .fontWeight(FontWeight.Bold)
          .onClick(() => {
            let isPrivacyMode: boolean = false;
            try {
              this.windowClass.setWindowPrivacyMode(isPrivacyMode, (err: BusinessError) => {
                const errCode: number = err.code;
                if (errCode) {
                  console.error('Failed to set the window to privacy mode. Cause:' + JSON.stringify(err));
                  return;
                }
                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));
            }
          })
      }
      .width('100%')
    }
    .height('100%')
  }
}
import { window } from '@kit.ArkUI';
import { BusinessError } from '@ohos.base';

@Entry
@Component
struct Index43 {
  private windowClass = AppStorage.get("windowClass") as window.Window
  @State message: string = 'Hello World';

  build() {
    Row() {
      Column() {
        Text('禁止截屏')
          .fontSize(50)
          .fontWeight(FontWeight.Bold)
          .onClick(() => {
            let isPrivacyMode: boolean = true;
            try {
              this.windowClass.setWindowPrivacyMode(isPrivacyMode, (err: BusinessError) => {
                const errCode: number = err.code;
                if (errCode) {
                  console.error('Failed to set the window to privacy mode. Cause:' + JSON.stringify(err));
                  return;
                }
                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));
            }
          })

        Text('允许截屏')
          .fontSize(50)
          .fontWeight(FontWeight.Bold)
          .onClick(() => {
            let isPrivacyMode: boolean = false;
            try {
              this.windowClass.setWindowPrivacyMode(isPrivacyMode, (err: BusinessError) => {
                const errCode: number = err.code;
                if (errCode) {
                  console.error('Failed to set the window to privacy mode. Cause:' + JSON.stringify(err));
                  return;
                }
                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));
            }
          })
      }
      .width('100%')
    }
    .height('100%')
  }
}

开启和关闭写在页面对应的生命周期中。

分享
微博
QQ
微信
回复
2天前
相关问题
防止屏幕或者
651浏览 • 1回复 待解决
HarmonyOS 不被或者如何实现
34浏览 • 1回复 待解决
如何、投
1974浏览 • 1回复 待解决
HarmonyOS 如何禁用
230浏览 • 1回复 待解决
HarmonyOS 如何设置放
559浏览 • 1回复 待解决
HarmonyOS 如何防
266浏览 • 1回复 待解决
HarmonyOS 如何禁止
550浏览 • 1回复 待解决
HarmonyOS 安全键盘输入问题
325浏览 • 1回复 待解决
dayu200开发板如何或者
298浏览 • 0回复 待解决