diff --git a/pages/index/index.vue b/pages/index/index.vue
index 5bac7fa26c03e80a1a6ab1a38d537d4d717a10ab..4e24a5f427f951c3f59b9a99cf09ad41b305c00b 100644
--- a/pages/index/index.vue
+++ b/pages/index/index.vue
@@ -6,6 +6,8 @@
+
+
@@ -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 = '允许截屏';
+ }
+ },
}
}
diff --git a/uni_modules/uni-usercapturescreen/package.json b/uni_modules/uni-usercapturescreen/package.json
index c2c1d59c0245d622b1533ff54f72037701c621a0..461dc0ab060716de2cb2f361264769995cbf8c5a 100644
--- a/uni_modules/uni-usercapturescreen/package.json
+++ b/uni_modules/uni-usercapturescreen/package.json
@@ -34,7 +34,8 @@
"uni-ext-api":{
"uni": {
"onUserCaptureScreen": "onUserCaptureScreen",
- "offUserCaptureScreen": "offUserCaptureScreen"
+ "offUserCaptureScreen": "offUserCaptureScreen",
+ "setUserCaptureScreen": "setUserCaptureScreen"
}
},
"dependencies": [],
diff --git a/uni_modules/uni-usercapturescreen/utssdk/app-android/index.uts b/uni_modules/uni-usercapturescreen/utssdk/app-android/index.uts
index 6ff073c38d113d4544a659ecd540d24e8a95ca5d..776bc27b0903f1f7f411ee00d0bfb37e6bf1e9be 100644
--- a/uni_modules/uni-usercapturescreen/utssdk/app-android/index.uts
+++ b/uni_modules/uni-usercapturescreen/utssdk/app-android/index.uts
@@ -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);
+ }
+ }
+}
+