求告知如何实现防截屏功能

如何实现防截屏功能

HarmonyOS
2024-07-22 12:32:42
浏览
收藏 0
回答 1
回答 1
按赞同
/
按时间
jshyb

1、设置窗口为隐私模式时,需要entry的module.json5文件中添加相关权限

2、使用setWindowPrivacyMode设置隐私模式

import { window } from '@kit.ArkUI'; 
import { BusinessError } from '@kit.BasicServicesKit'; 
 
@Entry 
@Component 
struct Index20 { 
  @State message: string = 'Hello World'; 
  window?: window.Window; 
 
  aboutToAppear(): void { 
    window.getLastWindow(getContext(this)).then((mainWindow) => { 
      this.setWindowPrivacyMode(mainWindow, true) 
    }).catch((error: ESObject) => { 
      console.log("getMainWindow error: " + JSON.stringify(error)) 
    }) 
  } 
 
  setWindowPrivacyMode(windowClass: window.Window, isPrivacyMode: boolean) { 
    try { 
      // 设置窗口为隐私模式,窗口内容将无法被截屏或录屏。 
      let promise = windowClass.setWindowPrivacyMode(isPrivacyMode); 
      promise.then(() => { 
        console.info('Succeeded in setting the window to privacy mode.'); 
      }).catch((err: BusinessError) => { 
        console.error('Failed to set the window to privacy mode. Cause: ' + JSON.stringify(err)); 
      }); 
 
      console.info(`setWindowPrivacyMode 已执行`); 
    } catch (exception) { 
      console.error('Failed to set the window to the privacy mode. Cause:' + JSON.stringify(exception)); 
    } 
  } 
 
  build() { 
    Column() { 
      Text(this.message) 
        .id('Index20HelloWorld') 
        .fontSize(50) 
        .fontWeight(FontWeight.Bold) 
        .alignRules({ 
          center: { anchor: '__container__', align: VerticalAlign.Center }, 
          middle: { anchor: '__container__', align: HorizontalAlign.Center } 
        }) 
    } 
    .height('100%') 
    .width('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.
  • 45.
  • 46.
  • 47.
  • 48.
分享
微博
QQ
微信
回复
2024-07-22 20:15:19
相关问题
求大佬告知如何实现功能
2759浏览 • 1回复 待解决
HarmonyOS 功能如何实现
911浏览 • 1回复 待解决
如何实现功能,有人知道吗?
2709浏览 • 1回复 待解决
HarmonyOS 如何
1052浏览 • 1回复 待解决
HarmonyOS
976浏览 • 1回复 待解决
页面如何
301浏览 • 0回复 待解决
HarmonyOS 单个页面问题
577浏览 • 1回复 待解决
flutter的页面如何
402浏览 • 1回复 待解决
HarmonyOS 长分享功能实现
740浏览 • 1回复 待解决
能否实现响应者链,,求告知
1143浏览 • 1回复 待解决
HarmonyOS 密码登录页面未做
1126浏览 • 1回复 待解决
求告知如何强制刷新UI?
1258浏览 • 1回复 待解决
求告知ohpm如何迁移仓
1029浏览 • 1回复 待解决
求告知如何发起HTTP请求
1280浏览 • 1回复 待解决
求告知如何申请广告跟踪权限
1242浏览 • 1回复 待解决
求告知如何从view生成图片
895浏览 • 1回复 待解决
求告知如何获取当前定位
1181浏览 • 1回复 待解决
求告知子窗口如何添加动画
888浏览 • 1回复 待解决