Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
DCloud
uni-api
提交
60a4ccd7
U
uni-api
项目概览
DCloud
/
uni-api
通知
670
Star
23
Fork
12
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
3
列表
看板
标记
里程碑
合并请求
1
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
U
uni-api
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
3
Issue
3
列表
看板
标记
里程碑
合并请求
1
合并请求
1
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
提交
60a4ccd7
编写于
2月 16, 2023
作者:
DCloud-yinjiacheng
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
uni-usercapturescreen Android 新增禁止截屏API
上级
432d69d0
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
77 addition
and
1 deletion
+77
-1
pages/index/index.vue
pages/index/index.vue
+29
-0
uni_modules/uni-usercapturescreen/package.json
uni_modules/uni-usercapturescreen/package.json
+2
-1
uni_modules/uni-usercapturescreen/utssdk/app-android/index.uts
...odules/uni-usercapturescreen/utssdk/app-android/index.uts
+46
-0
未找到文件。
pages/index/index.vue
浏览文件 @
60a4ccd7
...
...
@@ -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
>
...
...
uni_modules/uni-usercapturescreen/package.json
浏览文件 @
60a4ccd7
...
...
@@ -34,7 +34,8 @@
"uni-ext-api"
:{
"uni"
:
{
"onUserCaptureScreen"
:
"onUserCaptureScreen"
,
"offUserCaptureScreen"
:
"offUserCaptureScreen"
"offUserCaptureScreen"
:
"offUserCaptureScreen"
,
"setUserCaptureScreen"
:
"setUserCaptureScreen"
}
},
"dependencies"
:
[],
...
...
uni_modules/uni-usercapturescreen/utssdk/app-android/index.uts
浏览文件 @
60a4ccd7
...
...
@@ -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.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录