HarmonyOS 如何设置页面防止截屏?

HarmonyOS 如何设置页面防止截屏?

HarmonyOS
2024-11-26 09:26:19
578浏览
收藏 0
回答 1
回答 1
按赞同
/
按时间
Excelsior_abit

​在module.json5文件中声明需要使用的 ohos.permission.PRIVACY_WINDOW 权限,参考文档:​https://developer.huawei.com/consumer/cn/doc/harmonyos-guides-V5/declare-permissions-V5#%E5%9C%A8%E9%85%8D%E7%BD%AE%E6%96%87%E4%BB%B6%E4%B8%AD%E5%A3%B0%E6%98%8E%E6%9D%83%E9%99%90

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

示例代码:

// 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.
  • 37.
  • 38.
  • 39.
  • 40.
  • 41.
  • 42.
  • 43.
  • 44.
分享
微博
QQ
微信
回复
2024-11-26 15:13:01
相关问题
防止屏幕或者录
1467浏览 • 1回复 待解决
HarmonyOS 如何设置
1281浏览 • 1回复 待解决
页面如何防录
299浏览 • 0回复 待解决
HarmonyOS 单个页面问题
575浏览 • 1回复 待解决
flutter的页面如何防录
395浏览 • 1回复 待解决
如何、录、投
3374浏览 • 1回复 待解决
设置禁止的隐私模式
2587浏览 • 1回复 待解决
HarmonyOS 如何禁用、录
1035浏览 • 1回复 待解决
HarmonyOS 如何防录
1048浏览 • 1回复 待解决
HarmonyOS 密码登录页面未做防
1126浏览 • 1回复 待解决
HarmonyOS 如何禁止和录
1497浏览 • 1回复 待解决
HarmonyOS如何获取图片
1184浏览 • 1回复 待解决