HarmonyOS 防截屏

在某一个page里面开启防截屏,获取window需要做些什么操作吗

HarmonyOS
2024-12-18 15:43:32
浏览
收藏 0
回答 1
回答 1
按赞同
/
按时间
aquaa

参考以下步骤和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.
  • 4.
  • 5.

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);
    })
  }
}
//页面
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.
  • 26.
  • 27.
  • 28.
  • 29.
  • 30.
  • 31.
  • 32.
  • 33.
  • 34.
  • 35.
  • 36.
分享
微博
QQ
微信
回复
2024-12-18 17:17:19


相关问题
HarmonyOS 如何
1056浏览 • 1回复 待解决
HarmonyOS 功能如何实现
926浏览 • 1回复 待解决
HarmonyOS 单个页面问题
594浏览 • 1回复 待解决
页面如何
335浏览 • 0回复 待解决
求告知如何实现功能
1175浏览 • 1回复 待解决
HarmonyOS 密码登录页面未做
1134浏览 • 1回复 待解决
求大佬告知如何实现功能
2772浏览 • 1回复 待解决
flutter的页面如何
432浏览 • 1回复 待解决
如何实现功能,有人知道吗?
2718浏览 • 1回复 待解决
HarmonyOS
819浏览 • 1回复 待解决
如何、录、投
3436浏览 • 1回复 待解决
HarmonyOS 如何禁用、录
1054浏览 • 1回复 待解决
HarmonyOS 如何设置放
1296浏览 • 1回复 待解决
HarmonyOS 如何禁止和录
1533浏览 • 1回复 待解决
防止屏幕或者录
1482浏览 • 1回复 待解决
HarmonyOS如何获取图片
1184浏览 • 1回复 待解决