Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
DCloud
Hello UTS
提交
9fc75453
H
Hello UTS
项目概览
DCloud
/
Hello UTS
通知
1595
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看板
提交
9fc75453
编写于
10月 18, 2022
作者:
杜庆泉
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
android 截屏返回值格式修改
上级
c96a3289
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
49 addition
and
40 deletion
+49
-40
pages/SystemAPI/android/screenlisten.vue
pages/SystemAPI/android/screenlisten.vue
+1
-1
uni_modules/uts-advance/utssdk/app-android/index.uts
uni_modules/uts-advance/utssdk/app-android/index.uts
+1
-1
uni_modules/uts-nativepage/utssdk/app-android/index.uts
uni_modules/uts-nativepage/utssdk/app-android/index.uts
+0
-1
uni_modules/uts-screenshot-listener/utssdk/app-android/index.uts
...ules/uts-screenshot-listener/utssdk/app-android/index.uts
+47
-37
未找到文件。
pages/SystemAPI/android/screenlisten.vue
浏览文件 @
9fc75453
...
...
@@ -37,7 +37,7 @@
var
that
=
this
;
onUserCaptureScreen
(
function
(
res
)
{
console
.
log
(
res
);
that
.
screenImage
=
res
that
.
screenImage
=
res
.
image
uni
.
showToast
({
icon
:
"
none
"
,
title
:
'
截屏捕捉成功
'
...
...
uni_modules/uts-advance/utssdk/app-android/index.uts
浏览文件 @
9fc75453
...
...
@@ -105,7 +105,7 @@ class RemoveUIRunnable extends Runnable {
override run():void {
let decorView = getUniActivity()!.
window.decorView
;
let decorView = getUniActivity()!.
getWindow().getDecorView()
;
let frameContent = decorView.findViewById<FrameLayout>(android.R.id.content)
let targetTV = frameContent.findViewWithTag<TextView>("helloText")
...
...
uni_modules/uts-nativepage/utssdk/app-android/index.uts
浏览文件 @
9fc75453
...
...
@@ -24,7 +24,6 @@ import {
import Service from 'android.app.Service';
import System from 'java.lang.System';
import WindowManager from 'android.view.WindowManager';
class ForeService extends Service {
...
...
uni_modules/uts-screenshot-listener/utssdk/app-android/index.uts
浏览文件 @
9fc75453
...
...
@@ -14,26 +14,52 @@ import File from "java.io.File";
import Environment from "android.os.Environment";
/**
* 文件监听器
*/
let screenOB: ScreenFileObserver | null = null;
/**
* 记录文件监听器上次监听的时间戳,避免重复监听
*/
let lastFileObserverTime: number = 0;
/**
* 图片捕捉定义
*/
type OnImageCatchOptions = {
onImageCatchChange: (res: any) => void;
};
/**
* android 10版本以上通过文件监听实现
* 图片捕捉监听变量
*/
let listenOption = new OnImageCatchOptions();
/**
* android 文件监听实现
*/
class ScreenFileObserver extends FileObserver {
/**
* 所有截屏文件的存放目录
*/
allScreen: File;
constructor(screenFile: string) {
super(screenFile)
this.allScreen = File(screenFile);
console.log(allScreen);
this.allScreen = new File(screenFile);
}
override onEvent(event: Int, path?: String): void {
// 只监听文件新增事件
if (event == FileObserver.CREATE) {
let newPath: string = new File(allScreen, path!).path;
let newPath: string = new File(this.allScreen, path!).path;
let currentTime = System.currentTimeMillis();
if ((currentTime - lastFileObserverTime) < 1000) {
...
...
@@ -41,32 +67,17 @@ class ScreenFileObserver extends FileObserver {
return;
}
console.log(path);
lastFileObserverTime = System.currentTimeMillis()
listenOption.onImageCatchChange(newPath)
let ret = {
image:newPath
}
listenOption.onImageCatchChange(ret)
}
}
}
/**
* android 10 版本使用的文件监听器
*/
let screenOB: ScreenFileObserver | null = null;
type onImageCatchOptions = {
onImageCatchChange: (res: string) => void;
};
let listenOption: onImageCatchOptions = new onImageCatchOptions();
let lastFileObserverTime: number = 0;
...
...
@@ -91,24 +102,20 @@ export function requestPremission() {
/**
* 开启截图监听
*/
export function onUserCaptureScreen(success: (res: string) => void) {
listenOption.onImageCatchChange = success;
export function onUserCaptureScreen(success: (res: any) => void) {
listenOption.onImageCatchChange = success;
// android 10 以上版本,使用监听文件的方式,更加可靠
let directory_screenshot: File;
let directory_pictures = File(Environment.getExternalStorageDirectory(), Environment.DIRECTORY_PICTURES);
let directory_dcim = File(Environment.getExternalStorageDirectory(), Environment.DIRECTORY_DCIM);
console.log(directory_pictures);
console.log(directory_dcim);
let directory_pictures = new File(Environment.getExternalStorageDirectory(), Environment.DIRECTORY_PICTURES);
let directory_dcim = new File(Environment.getExternalStorageDirectory(), Environment.DIRECTORY_DCIM);
if (Build.MANUFACTURER.equals("Xiaomi", true)) {
directory_screenshot = File(directory_dcim, "Screenshots");
directory_screenshot =
new
File(directory_dcim, "Screenshots");
} else {
directory_screenshot = File(directory_pictures, "Screenshots");
directory_screenshot =
new
File(directory_pictures, "Screenshots");
}
if (screenOB != null) {
...
...
@@ -117,13 +124,13 @@ export function onUserCaptureScreen(success: (res: string) => void) {
screenOB = new ScreenFileObserver(directory_screenshot.path)
screenOB!.startWatching()
}
/**
* 关闭截屏监听
*/
export function offUserCaptureScreen(success: (res:
string
) => void) {
export function offUserCaptureScreen(success: (res:
any
) => void) {
// android 10以上,关闭监听通过移除文件监听器实现
if (screenOB != null) {
...
...
@@ -132,7 +139,10 @@ export function offUserCaptureScreen(success: (res: string) => void) {
}
lastFileObserverTime = 0;
success("");
let ret = {
}
success(ret);
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录