IT评测·应用市场-qidao123.com
标题:
鸿蒙中开启关闭防截屏录屏
[打印本页]
作者:
雁过留声
时间:
2024-12-12 20:49
标题:
鸿蒙中开启关闭防截屏录屏
1.申请权限
"requestPermissions": [
{
"name": "ohos.permission.PRIVACY_WINDOW"
},
],
复制代码
2.ui
import { common, OpenLinkOptions, Want } from '@kit.AbilityKit'
import { BusinessError } from '@kit.BasicServicesKit'
import { window } from '@kit.ArkUI';
import { promptAction } from '@kit.ArkUI';
@Entry()
@Component
struct TransactionHistory {
async setWindowPrivacyModeTrue(context: Context) {
let windowClass: window.Window = await window.getLastWindow(context)
try {
windowClass.setWindowPrivacyMode(true, (err: BusinessError) => {
const errCode: number = err.code;
if (errCode) {
console.error('Failed to set the window to privacy mode. Cause:' + JSON.stringify(err));
if (errCode == 201) {
}
return;
}
promptAction.showToast({
message: `已开启 防截屏录屏`,
duration: 2000,
bottom: '500lpx'
});
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));
}
}
async setWindowPrivacyModeFalse(context: Context) {
let windowClass: window.Window = await window.getLastWindow(context)
try {
windowClass.setWindowPrivacyMode(false, (err: BusinessError) => {
const errCode: number = err.code;
if (errCode) {
console.error('Failed to set the window to privacy mode. Cause:' + JSON.stringify(err));
if (errCode == 201) {
}
return;
}
promptAction.showToast({
message: `已关闭 防截屏录屏`,
duration: 2000,
bottom: '500lpx'
});
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));
}
}
build() {
Column() {
Button('开启防截屏录屏').onClick(() => {
this.setWindowPrivacyModeTrue(getContext())
})
Button('关闭防截屏录屏').onClick(() => {
this.setWindowPrivacyModeFalse(getContext())
})
}.width('100%')
}
}
复制代码
免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!更多信息从访问主页:qidao123.com:ToB企服之家,中国第一个企服评测及商务社交产业平台。
欢迎光临 IT评测·应用市场-qidao123.com (https://dis.qidao123.com/)
Powered by Discuz! X3.4