07-18 08:20:05.537 26598-26902 C04213/com.example...InputKeyFlow com.hm.example I [] ConsumePointerEventInner(818): InputId:17513,wid:137,pointId:0,srcType:2,rect:[0,0,2240,2440],notify:1 07-18 08:20:05.537 26598-26598 C03951/com.example...InputKeyFlow com.hm.example I [(100000:100000:scope)] InputTracking id:17513, fingerId:0, type=0, inject=0, isPrivacyMode=0 07-18 08:20:05.537 26598-26902 C02805/com.example...InputKeyFlow com.hm.example I [][OnPointerEvent:216] ac: move: 17514
日志中isPrivacyMode=0,说明当前为非隐私状态,可以被截屏。
07-18 08:24:00.853 3146-55280 C01C10/com.oho...board/ImsaKit com.ohos.sceneboard I line: 72, function: OnRemoteRequest,SystemCmdChannelStub, code: 0, callingPid: 3837, callingUid: 20020026. 07-18 08:24:00.853 3837-3837 A000FF/i.hmos....rd_InputPanel com.huawe...utMethod I setPrivacyMode: true 07-18 08:24:00.853 3146-3146 A04200/com.oho...eboard/WINDOW com.ohos.sceneboard I SCBKeyboardSession --> No need open transaction, keyboard is not rebuild
日志中setPrivacyMode: true,说明当前为隐私状态,不可以被截屏。
使用setWindowPrivacyMode接口设置窗口隐私模式,禁止截屏或录屏。此接口适用于禁止截屏/录屏的场景。
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) {
return;
}
console.info('Succeeded in setting the window to privacy mode.');
});
});
}
}
@Entry
@Component
struct Index {
message: string = 'hello world';
@Provide('NavPathStack') pageStack: NavPathStack = new NavPathStack();
context = this.getUIContext();
@Builder
PagesMap(name: string) {
if (name === 'Index') {
Index();
} else if (name === 'PageOne') {
PageOne();
}
}
build() {
Navigation(this.pageStack) {
Column() {
Button('pushPath', { stateEffect: true, type: ButtonType.Capsule })
.width('80%')
.height(40)
.margin(20)
.onClick(() => {
this.pageStack.pushPath({ name: 'PageOne' }); // 进行页面跳转
})
}
}
.navDestination(this.PagesMap)
.onNavBarStateChange((isVisible: boolean) => {
// 页面跳转回调时触发设置窗口为隐私模式
windowUtils.setWindowPrivacyModeInPage(this.context.getHostContext() as common.UIAbilityContext, isVisible);
})
}
}
@Component
struct PageOne {
@Consume('NavPathStack') pageStack: NavPathStack;
build() {
NavDestination() {
Column() {
Text('PageOne')
}
}
.title('pageOne')
.onBackPressed(() => {
return true;
})
}
} 更多信息请参考如何实现防截屏功能。