当前位置: 首页> 文旅> 文化 > 网络代理服务器软件_做网站需要学什么专业_seo网站推广价格_手机seo关键词优化

网络代理服务器软件_做网站需要学什么专业_seo网站推广价格_手机seo关键词优化

时间:2025/7/13 2:49:04来源:https://blog.csdn.net/l286935203/article/details/144735268 浏览次数:0次
网络代理服务器软件_做网站需要学什么专业_seo网站推广价格_手机seo关键词优化

在HarmonyOS next中实现防截屏主要有两种方式

setWindowPrivacyMode设置窗口是否为隐私模式,设置为隐私模式的窗口,窗口内容将无法被截屏或录屏。此接口可用于禁止截屏/录屏的场景。

方式一: 在onWindowStageCreate回调中设置主窗口为隐私模式,具体可参考示例代码:

import { window } from '@kit.ArkUI'; 
import { BusinessError } from '@kit.BasicServicesKit';onWindowStageCreate(windowStage: window.WindowStage): void { // Main window is created, set main page for this ability hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onWindowStageCreate'); // 获取主窗口 windowStage.getMainWindow((err: BusinessError, data) => { let errCode: number = err.code; if (errCode) { console.error('Failed to obtain the main window. Cause: ' + JSON.stringify(err)); return; } let windowClass: window.Window = data; console.info('Succeeded in obtaining the main window. Data: ' + JSON.stringify(data)); // 设置窗口隐私模式 let isPrivacyMode: boolean = true; try { windowClass.setWindowPrivacyMode(isPrivacyMode, (err: BusinessError) => { const errCode: number = err.code; if (errCode) { console.error('Failed to set the window to privacy mode. Cause:' + JSON.stringify(err)); return; } console.info('Succeeded in setting the window to privacy mode.'); }); } catch (exception) { console.error('Failed to set the window to privacy mode. Cause:' + JSON.stringify(exception)); } }) windowStage.loadContent('pages/Index', (err, data) => { if (err.code) { hilog.error(0x0000, 'testTag', 'Failed to load the content. Cause: %{public}s', JSON.stringify(err) ?? ''); return; } hilog.info(0x0000, 'testTag', 'Succeeded in loading the content. Data: %{public}s', JSON.stringify(data) ?? ''); }); }

方式二: 进入页面开启隐式模式,离开页面取消,具体可参考以下步骤:

首先在module.json5文件中声明需要使用的ohos.permission.PRIVACY_WINDOW 权限

"requestPermissions": [{"name": "ohos.permission.PRIVACY_WINDOW"}
]

然后在进入页面时触发onPageShow回调,调用setWindowPrivacyMode设置窗口为隐私模式,离开页面时触发onPageHide回调,设置窗口为非隐私模式,参考示例代码如下:

import { BusinessError } from '@kit.BasicServicesKit';
import { common } from '@kit.AbilityKit';
import { window } from '@kit.ArkUI';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.');});})}
}@Entry
@Component
struct Index {@State message: string = 'Hello World';onPageShow() {windowUtils.setWindowPrivacyModeInPage(getContext(this) as common.UIAbilityContext, true);}onPageHide() {windowUtils.setWindowPrivacyModeInPage(getContext(this) as common.UIAbilityContext, false);}build() {RelativeContainer() {Text(this.message).id('HelloWorld').fontSize(50).fontWeight(FontWeight.Bold).alignRules({center: { anchor: '__container__', align: VerticalAlign.Center },middle: { anchor: '__container__', align: HorizontalAlign.Center }})}.height('100%').width('100%')}
}
关键字:网络代理服务器软件_做网站需要学什么专业_seo网站推广价格_手机seo关键词优化

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com

责任编辑: