HarmonyOS 如何禁用截屏、录屏

密码输入可视化界面可被截屏、录屏,涉及密码输入的场景都涉及,请问如何禁用 截屏、录屏?

HarmonyOS
2024-12-26 15:07:42
1272浏览
收藏 0
回答 1
回答 1
按赞同
/
按时间
shlp

参考以下步骤和demo:

1、在module.json5文件中声明需要使用的ohos.permission.PRIVACY_WINDOW权限,参考文档:https://developer.huawei.com/consumer/cn/doc/harmonyos-guides-V5/declare-permissions-V5

"requestPermissions":[
{ "name" : "ohos.permission.PRIVACY_WINDOW" }
]
  • 1.
  • 2.
  • 3.

2.示例代码:

// windowUtils.ets
import window from '@ohos.window';
import common from '@ohos.app.ability.common';
export class windowUtils {
  static setWindowPrivacyModeInPage(context: common.UIAbilityContext,isFlag: boolean) {
    window.getLastWindow(context).then((lastWindow)=>{
      lastWindow.setWindowPrivacyMode(isFlag);
    })
  }
}
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
//页面
import common from '@ohos.app.ability.common';
import { windowUtils } from '../common/windowUtils';
@Entry
@Component
struct Index3 {
  @State message: string = 'Hello World';
  onPageShow(): void {
    windowUtils.setWindowPrivacyModeInPage(getContext(this) as common.UIAbilityContext, true);
  }
  onPageHide() {
    windowUtils.setWindowPrivacyModeInPage(getContext(this) as common.UIAbilityContext,false);
  }
  build() {
    Row() {
      Column() {
        Text(this.message)
          .fontSize(50)
          .fontWeight(FontWeight.Bold)
      }
      .width('100%')
    }
    .height('100%')
  }
}
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22.
  • 23.
  • 24.
  • 25.
分享
微博
QQ
微信
回复
2024-12-26 17:34:00


相关问题
如何、投
3265浏览 • 1回复 待解决
HarmonyOS 如何
1016浏览 • 1回复 待解决
HarmonyOS 如何设置放
1248浏览 • 1回复 待解决
HarmonyOS 如何禁止
1429浏览 • 1回复 待解决
HarmonyOS 不被或者如何实现
694浏览 • 1回复 待解决
防止屏幕或者
1437浏览 • 1回复 待解决
页面如何
250浏览 • 0回复 待解决
flutter的页面如何
354浏览 • 1回复 待解决