Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
DCloud
uni-api
提交
8eea7a8b
U
uni-api
项目概览
DCloud
/
uni-api
通知
655
Star
22
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看板
体验新版 GitCode,发现更多精彩内容 >>
提交
8eea7a8b
编写于
3月 16, 2023
作者:
DCloud-yinjiacheng
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Android uni-usercapturescreen 语法调整
上级
bbccccd5
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
30 addition
and
63 deletion
+30
-63
pages/index/index.vue
pages/index/index.vue
+7
-24
uni_modules/uni-usercapturescreen/utssdk/app-android/index.uts
...odules/uni-usercapturescreen/utssdk/app-android/index.uts
+6
-21
uni_modules/uni-usercapturescreen/utssdk/interface.uts
uni_modules/uni-usercapturescreen/utssdk/interface.uts
+17
-18
未找到文件。
pages/index/index.vue
浏览文件 @
8eea7a8b
...
...
@@ -28,8 +28,7 @@
title
:
'
Hello
'
,
memListener
:
null
,
setUserCaptureScreenFlag
:
false
,
setUserCaptureScreenText
:
'
禁止截屏
'
,
permissionGranted
:
false
setUserCaptureScreenText
:
'
禁止截屏
'
}
},
onLoad
()
{
...
...
@@ -139,30 +138,14 @@
var
that
=
this
;
uni
.
onUserCaptureScreen
(
function
(
res
)
{
console
.
log
(
res
);
if
(
uni
.
getSystemInfoSync
().
platform
==
"
android
"
)
{
// 除android 之外的平台,不需要判断返回状态码
if
(
res
.
errCode
==
-
1
){
// 启动失败
that
.
permissionGranted
=
true
;
return
;
}
else
if
(
res
.
errCode
==
0
){
uni
.
showToast
({
icon
:
"
none
"
,
title
:
'
捕获截屏事件
'
})
that
.
screenImage
=
res
.
image
}
}
else
{
// 除android 之外的平台,不需要判断返回状态码
uni
.
showToast
({
icon
:
"
none
"
,
title
:
'
捕获截屏事件
'
})
}
uni
.
showToast
({
icon
:
"
none
"
,
title
:
'
捕获截屏事件
'
})
that
.
screenImage
=
res
.
path
});
if
(
uni
.
getSystemInfoSync
().
platform
!=
"
android
"
||
that
.
permissionGranted
)
{
if
(
uni
.
getSystemInfoSync
().
platform
!=
"
android
"
)
{
// 除android 之外的平台,直接提示监听已开启
uni
.
showToast
({
icon
:
"
none
"
,
...
...
uni_modules/uni-usercapturescreen/utssdk/app-android/index.uts
浏览文件 @
8eea7a8b
...
...
@@ -8,7 +8,7 @@ import File from "java.io.File";
import Environment from "android.os.Environment";
import System from 'java.lang.System';
import WindowManager from 'android.view.WindowManager';
import {
UserCaptureScreenResult, OnUserCaptureScreenResult, SetUserCaptureScreenOptions, UserCaptureScreenCallback, OnUserCaptureScreen, OffUserCaptureScreen
, SetUserCaptureScreen } from "../interface.uts";
import {
OnUserCaptureScreenCallbackResult, UserCaptureScreenCallback, OnUserCaptureScreen, OffUserCaptureScreen, SetUserCaptureScreenSuccess, SetUserCaptureScreenOptions
, SetUserCaptureScreen } from "../interface.uts";
/**
* 文件监听器
...
...
@@ -50,10 +50,7 @@ class ScreenFileObserver extends FileObserver {
lastObserverTime = currentTime;
const screenShotPath = new File(this.screenFile, path).getPath();
const res : OnUserCaptureScreenResult = {
errCode: 0,
errMsg: "onUserCaptureScreen:ok",
errSubject: "uni-onUserCaptureScreen",
const res : OnUserCaptureScreenCallbackResult = {
path: screenShotPath
}
listener?.(res);
...
...
@@ -68,23 +65,15 @@ class ScreenFileObserver extends FileObserver {
export const onUserCaptureScreen : OnUserCaptureScreen = function (callback : UserCaptureScreenCallback | null) {
// 检查相关权限是否已授予
if (ActivityCompat.checkSelfPermission(UTSAndroid.getAppContext()!, Manifest.permission.READ_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
// 无权限,申请权限
,并且告知用户监听失败
// 无权限,申请权限
ActivityCompat.requestPermissions(UTSAndroid.getUniActivity()!, arrayOf(Manifest.permission.READ_EXTERNAL_STORAGE), 1001);
// 因权限缺失导致监听失败
const res : OnUserCaptureScreenResult = {
errCode: -1,
errMsg: "onUserCaptureScreen:permission denied",
errSubject: "uni-onUserCaptureScreen"
}
callback?.(res);
return;
}
// 更新监听
listener = callback;
let directory_screenshot : File;
if (Build.MANUFACTURER.toLowerCase() ==
=
"xiaomi") {
if (Build.MANUFACTURER.toLowerCase() == "xiaomi") {
// @Suppress("DEPRECATION")
directory_screenshot = new File(new File(Environment.getExternalStorageDirectory(), Environment.DIRECTORY_DCIM), "Screenshots");
} else {
...
...
@@ -113,11 +102,7 @@ export const offUserCaptureScreen : OffUserCaptureScreen = function (_ : UserCap
export const setUserCaptureScreen : SetUserCaptureScreen = function (option : SetUserCaptureScreenOptions) {
// 切换到UI线程
UTSAndroid.getUniActivity()?.runOnUiThread(new SetUserCaptureScreenRunnable(option.enable));
const res : UserCaptureScreenResult = {
errCode: 0,
errMsg: "setUserCaptureScreen:ok",
errSubject: "uni-setUserCaptureScreen"
}
const res : SetUserCaptureScreenSuccess = {}
option.success?.(res);
option.complete?.(res);
}
...
...
@@ -142,4 +127,4 @@ class SetUserCaptureScreenRunnable extends Runnable {
UTSAndroid.getUniActivity()?.getWindow()?.addFlags(WindowManager.LayoutParams.FLAG_SECURE);
}
}
}
}
\ No newline at end of file
uni_modules/uni-usercapturescreen/utssdk/interface.uts
浏览文件 @
8eea7a8b
/**
* uni.onUserCaptureScreen/uni.offUserCaptureScreen回调参数
*/
export type OnUserCaptureScreenCallbackResult = {
/**
* 截屏文件路径(仅Android返回)
...
...
@@ -11,30 +13,28 @@ export type OnUserCaptureScreenCallbackResult = {
*/
export type UserCaptureScreenCallback = (res : OnUserCaptureScreenCallbackResult) => void
/**
* uni.onUserCaptureScreen函数定义
* 开启截屏监听
*
* @param {UserCaptureScreenCallback} callback
* @tutorial https://uniapp.dcloud.net.cn/api/system/capture-screen.html#onusercapturescreen
* @platforms APP-IOS = ^9.0,APP-ANDROID = ^
22
* @platforms APP-IOS = ^9.0,APP-ANDROID = ^
19
* @since 3.6.8
*/
export type OnUserCaptureScreen = (callback : UserCaptureScreenCallback | null) => void
/**
* uni.offUserCaptureScreen函数定义
* 关闭截屏监听
*
* @param {UserCaptureScreenCallback} callback
* @tutorial https://uniapp.dcloud.net.cn/api/system/capture-screen.html#offusercapturescreen
* @platforms APP-IOS = ^9.0,APP-ANDROID = ^
22
* @platforms APP-IOS = ^9.0,APP-ANDROID = ^
19
* @since 3.6.8
*/
export type OffUserCaptureScreen = (callback : UserCaptureScreenCallback | null) => void
/**
* uni.setUserCaptureScreen成功回调参数
*/
...
...
@@ -48,7 +48,6 @@ export type SetUserCaptureScreenFail = {
/**
* 错误码
* 0:成功
* -1:permission denied
* 12001:system not support
* 12010:system internal error
*/
...
...
@@ -64,18 +63,18 @@ export type SetUserCaptureScreenFail = {
}
/**
* uni.setUserCaptureScreen成功回调函数定义
*/
* uni.setUserCaptureScreen成功回调函数定义
*/
export type SetUserCaptureScreenSuccessCallback = (res : SetUserCaptureScreenSuccess) => void
/**
* uni.setUserCaptureScreen失败回调函数定义
*/
* uni.setUserCaptureScreen失败回调函数定义
*/
export type SetUserCaptureScreenFailCallback = (res : SetUserCaptureScreenFail) => void
/**
* uni.setUserCaptureScreen完成回调函数定义
*/
* uni.setUserCaptureScreen完成回调函数定义
*/
export type SetUserCaptureScreenCompleteCallback = (res : any) => void
/**
...
...
@@ -89,31 +88,31 @@ export type SetUserCaptureScreenOptions = {
/**
* 接口调用成功的回调函数
*/
//success : SetUserCaptureScreenSuccessCallback | null,
//
success : SetUserCaptureScreenSuccessCallback | null,
success ?: SetUserCaptureScreenSuccessCallback,
/**
* 接口调用失败的回调函数
*/
//fail : SetUserCaptureScreenFailCallback | null,
//
fail : SetUserCaptureScreenFailCallback | null,
fail ?: SetUserCaptureScreenFailCallback,
/**
* 接口调用结束的回调函数(调用成功、失败都会执行)
*/
//
complete : SetUserCaptureScreenSuccessCallback |
SetUserCaptureScreenFailCallback | null
//
complete : SetUserCaptureScreenSuccessCallback |
SetUserCaptureScreenFailCallback | null
complete ?: SetUserCaptureScreenCompleteCallback
}
/**
* uni.setUserCaptureScreen函数定义
* 设置防截屏
*
* @param {SetUserCaptureScreenOptions} options
* @tutorial https://uniapp.dcloud.net.cn/api/system/capture-screen.html#setusercapturescreen
* @platforms APP-IOS = ^9.0,APP-ANDROID = ^
22
* @platforms APP-IOS = ^9.0,APP-ANDROID = ^
19
* @since 3.7.3
*/
export type SetUserCaptureScreen = (options : SetUserCaptureScreenOptions) => void
interface uni {
onUserCaptureScreen : OnUserCaptureScreen,
offUserCaptureScreen : OffUserCaptureScreen,
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录