HarmonyOS 单个页面防截屏问题

我看文档基于entryAbility的防截屏可以实现,但是基于单个页面怎么去处理呢

HarmonyOS
2024-12-25 08:53:50
794浏览
收藏 0
回答 1
回答 1
按赞同
/
按时间
zbw_apple

首先在模块级别 module.json5添加权限 ohos.permission.PRIVACY_WINDOW (module -> requestPermissions)

请参考以下示例:

//1.iIndex.ets
import common from '@ohos.app.ability.common';
import { windowUtils } from './NewUtili';

@Entry
@Component
struct Index {

  @State selectId: string = 'A'
  onPageShow() {

    windowUtils.setWindowPrivacyModeInPage(getContext(this) as common.UIAbilityContext, true);
  }
  onPageHide() {
    windowUtils.setWindowPrivacyModeInPage(getContext(this) as common.UIAbilityContext,false);
  }
  build() {

  }
}
//2.windowUtils.ets
import window from '@ohos.window';
import common from '@ohos.app.ability.common';
import { BusinessError } from '@kit.BasicServicesKit';

export class windowUtils {
  static setWindowPrivacyModeInPage(context: common.UIAbilityContext,isFlag: boolean) {
    window.getLastWindow(context).then((lastWindow)=>{
      lastWindow.setWindowPrivacyMode(isFlag, (err: BusinessError) => {
        const errCode: number = err.code;
        if (errCode) {
          console.error('Failed to set the window to privacy mode. 1Cause:' + JSON.stringify(err));
          return;
        }
        console.info('Succeeded in setting the window to privacy mode.');
      });

    })
  }
}
  • 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.
分享
微博
QQ
微信
回复
2024-12-25 11:16:31


相关问题
HarmonyOS 如何
1049浏览 • 1回复 待解决
HarmonyOS
973浏览 • 1回复 待解决
页面如何
301浏览 • 0回复 待解决
HarmonyOS 密码登录页面未做
1126浏览 • 1回复 待解决
flutter的页面如何
402浏览 • 1回复 待解决
HarmonyOS 功能如何实现
911浏览 • 1回复 待解决
求告知如何实现功能
1151浏览 • 1回复 待解决
求大佬告知如何实现功能
2759浏览 • 1回复 待解决
如何实现功能,有人知道吗?
2706浏览 • 1回复 待解决
HarmonyOS 如何设置页面防止
978浏览 • 1回复 待解决
HarmonyOS
808浏览 • 1回复 待解决
HarmonyOS 安全键盘输入问题
884浏览 • 1回复 待解决
如何、录、投
3397浏览 • 1回复 待解决