Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
DCloud
Hello UTS
提交
3ed223b2
H
Hello UTS
项目概览
DCloud
/
Hello UTS
通知
1598
Star
27
Fork
9
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
2
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
H
Hello UTS
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
2
Issue
2
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
提交
3ed223b2
编写于
10月 20, 2022
作者:
杜庆泉
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
截屏监听插件 增加状态码,减少权限请求接口。与微信保持一致
上级
a05bfe18
变更
2
显示空白变更内容
内联
并排
Showing
2 changed file
with
36 addition
and
42 deletion
+36
-42
pages/SystemAPI/ScreenListen/screenlisten.vue
pages/SystemAPI/ScreenListen/screenlisten.vue
+17
-24
uni_modules/uts-screenshot-listener/utssdk/app-android/index.uts
...ules/uts-screenshot-listener/utssdk/app-android/index.uts
+19
-18
未找到文件。
pages/SystemAPI/ScreenListen/screenlisten.vue
浏览文件 @
3ed223b2
...
@@ -3,7 +3,6 @@
...
@@ -3,7 +3,6 @@
<page-head
title=
"监听系统截屏"
accordion
></page-head>
<page-head
title=
"监听系统截屏"
accordion
></page-head>
<uni-list>
<uni-list>
<uni-list-item
@
tap=
"testScreenShotPremission"
title=
"准备截屏监听权限(仅Android)"
class=
"itemButton"
:clickable=
"true"
/>
<uni-list-item
@
tap=
"testScreenShotListen"
title=
"监听截屏事件"
class=
"itemButton"
:clickable=
"true"
/>
<uni-list-item
@
tap=
"testScreenShotListen"
title=
"监听截屏事件"
class=
"itemButton"
:clickable=
"true"
/>
<uni-list-item
@
tap=
"testScreenShotOff"
title=
"关闭截屏监听"
class=
"itemButton"
:clickable=
"true"
/>
<uni-list-item
@
tap=
"testScreenShotOff"
title=
"关闭截屏监听"
class=
"itemButton"
:clickable=
"true"
/>
</uni-list>
</uni-list>
...
@@ -15,7 +14,6 @@
...
@@ -15,7 +14,6 @@
<
script
>
<
script
>
import
{
import
{
requestPremission
,
onUserCaptureScreen
,
onUserCaptureScreen
,
offUserCaptureScreen
offUserCaptureScreen
}
from
"
@/uni_modules/uts-screenshot-listener
"
;
}
from
"
@/uni_modules/uts-screenshot-listener
"
;
...
@@ -29,21 +27,19 @@
...
@@ -29,21 +27,19 @@
methods
:
{
methods
:
{
testScreenShotPremission
()
{
if
(
uni
.
getSystemInfoSync
().
platform
==
"
ios
"
)
{
uni
.
showToast
({
icon
:
"
none
"
,
title
:
'
iOS 平台无需请求权限
'
})
return
;
}
// 请求写入储存的权限
requestPremission
();
},
testScreenShotListen
()
{
testScreenShotListen
()
{
var
that
=
this
;
var
that
=
this
;
onUserCaptureScreen
(
function
(
res
)
{
onUserCaptureScreen
(
function
(
res
)
{
console
.
log
(
res
);
console
.
log
(
res
);
if
(
res
.
code
==
-
1
){
// 启动失败
return
;
}
else
if
(
res
.
code
==
0
){
uni
.
showToast
({
icon
:
"
none
"
,
title
:
'
截屏监听已开启
'
})
}
else
{
uni
.
showToast
({
uni
.
showToast
({
icon
:
"
none
"
,
icon
:
"
none
"
,
title
:
'
捕获截屏事件
'
title
:
'
捕获截屏事件
'
...
@@ -51,12 +47,9 @@
...
@@ -51,12 +47,9 @@
if
(
uni
.
getSystemInfoSync
().
platform
==
"
android
"
)
{
if
(
uni
.
getSystemInfoSync
().
platform
==
"
android
"
)
{
that
.
screenImage
=
res
.
image
that
.
screenImage
=
res
.
image
}
}
}
});
});
// 提示已经开始监听,注意观察
uni
.
showToast
({
icon
:
"
none
"
,
title
:
'
截屏监听已开启
'
})
},
},
testScreenShotOff
()
{
testScreenShotOff
()
{
var
that
=
this
;
var
that
=
this
;
...
...
uni_modules/uts-screenshot-listener/utssdk/app-android/index.uts
浏览文件 @
3ed223b2
...
@@ -65,6 +65,7 @@ class ScreenFileObserver extends FileObserver {
...
@@ -65,6 +65,7 @@ class ScreenFileObserver extends FileObserver {
lastFileObserverTime = System.currentTimeMillis()
lastFileObserverTime = System.currentTimeMillis()
let ret = {
let ret = {
code:1,
image:newPath
image:newPath
}
}
...
@@ -79,30 +80,24 @@ class ScreenFileObserver extends FileObserver {
...
@@ -79,30 +80,24 @@ class ScreenFileObserver extends FileObserver {
/**
* 请求权限
*/
export function requestPremission() {
// 注册一个请求回调
// 发起权限申请
if (ActivityCompat.checkSelfPermission(getUniActivity()!, Manifest.permission.READ_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
ActivityCompat.requestPermissions(getUniActivity()!, arrayOf(Manifest.permission.READ_EXTERNAL_STORAGE), 1001)
}
// 请求权限
return { name: "requestPremission" };
}
/**
/**
* 开启截图监听
* 开启截图监听
*/
*/
export function onUserCaptureScreen(callback: (res:UTSJSONObject) => void) {
export function onUserCaptureScreen(callback: (res:UTSJSONObject) => void) {
// 检查相关权限是否已经具备
if (ActivityCompat.checkSelfPermission(getUniActivity()!, Manifest.permission.READ_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
// 不具备权限,申请权限,并且告知用户监听失败
ActivityCompat.requestPermissions(getUniActivity()!, arrayOf(Manifest.permission.READ_EXTERNAL_STORAGE), 1001)
// 因权限缺失导致监听失败
let ret = {
code:-1
}
callback(ret);
return ;
}
imageChange = callback;
imageChange = callback;
...
@@ -124,6 +119,12 @@ export function onUserCaptureScreen(callback: (res:UTSJSONObject) => void) {
...
@@ -124,6 +119,12 @@ export function onUserCaptureScreen(callback: (res:UTSJSONObject) => void) {
screenOB = new ScreenFileObserver(directory_screenshot.path)
screenOB = new ScreenFileObserver(directory_screenshot.path)
screenOB!.startWatching()
screenOB!.startWatching()
// 监听成功
let ret = {
code:0
}
callback(ret);
}
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录