提交 60a4ccd7 编写于 作者: DCloud-yinjiacheng's avatar DCloud-yinjiacheng

uni-usercapturescreen Android 新增禁止截屏API

上级 432d69d0
......@@ -6,6 +6,8 @@
</view>
<button @tap="testScreenShotListen">开启截屏监听</button>
<button @tap="testScreenShotOff">关闭截屏监听</button>
<button @tap="testSetUserCaptureScreen">{{setUserCaptureScreenText}}</button>
<button @tap="testGetBatteryInfo">获取电池电量</button>
<button @tap="testonMemoryWarning">开启内存不足告警监听</button>
<button @tap="testoffMemoryWarning">关闭内存不足告警监听</button>
......@@ -25,6 +27,8 @@
return {
title: 'Hello',
memListener:null,
setUserCaptureScreenFlag: true,
setUserCaptureScreenText: '禁止截屏'
}
},
onLoad() {
......@@ -190,6 +194,31 @@
}
})
},
testSetUserCaptureScreen() {
let flag = this.setUserCaptureScreenFlag;
uni.setUserCaptureScreen({
open: flag,
success: (res) => {
console.log("setUserCaptureScreen open: " + flag + " success: " + JSON.stringify(res));
},
fail: (res) => {
console.log("setUserCaptureScreen open: " + flag + " fail: " + JSON.stringify(res));
},
complete: (res) => {
console.log("setUserCaptureScreen open: " + flag + " complete: " + JSON.stringify(res));
}
});
uni.showToast({
icon:"none",
title: this.setUserCaptureScreenText
});
this.setUserCaptureScreenFlag = !this.setUserCaptureScreenFlag;
if (this.setUserCaptureScreenFlag) {
this.setUserCaptureScreenText = '禁止截屏';
} else {
this.setUserCaptureScreenText = '允许截屏';
}
},
}
}
</script>
......
......@@ -34,7 +34,8 @@
"uni-ext-api":{
"uni": {
"onUserCaptureScreen": "onUserCaptureScreen",
"offUserCaptureScreen": "offUserCaptureScreen"
"offUserCaptureScreen": "offUserCaptureScreen",
"setUserCaptureScreen": "setUserCaptureScreen"
}
},
"dependencies": [],
......
......@@ -13,7 +13,17 @@ import FileObserver from "android.os.FileObserver";
import File from "java.io.File";
import Environment from "android.os.Environment";
import System from 'java.lang.System';
import WindowManager from 'android.view.WindowManager';
/**
* setUserCaptureScreen 参数定义
*/
type SetUserCaptureScreenOption = {
open: boolean;
success?: (res: UTSJSONObject) => void;
fail?: (res: UTSJSONObject) => void;
complete?: (res: UTSJSONObject) => void;
}
/**
......@@ -145,5 +155,41 @@ export function offUserCaptureScreen(success: (res: any) => void) {
success({});
}
/**
* 设置是否禁止截屏
*/
export function setUserCaptureScreen(option: SetUserCaptureScreenOption) {
const res = {
errCode: 0,
errMsg: "setUserCaptureScreen:ok",
errSubject: "uni-setUserCaptureScreen"
};
UTSAndroid.getUniActivity()?.runOnUiThread(new SetUserCaptureScreenRunnable(option.open));
option.success?.(res);
option.complete?.(res);
}
class SetUserCaptureScreenRunnable extends Runnable {
/**
* true 表示禁止截屏
* false 表示允许截屏
*/
private open: boolean = false;
constructor(open: boolean) {
super();
this.open = open;
}
override run(): void {
if (this.open) {
UTSAndroid.getUniActivity()?.getWindow()?.addFlags(WindowManager.LayoutParams.FLAG_SECURE);
} else {
UTSAndroid.getUniActivity()?.getWindow()?.clearFlags(WindowManager.LayoutParams.FLAG_SECURE);
}
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册