Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
DCloud
uni-api
提交
8eea7a8b
U
uni-api
项目概览
DCloud
/
uni-api
通知
675
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看板
提交
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 @@
...
@@ -28,8 +28,7 @@
title
:
'
Hello
'
,
title
:
'
Hello
'
,
memListener
:
null
,
memListener
:
null
,
setUserCaptureScreenFlag
:
false
,
setUserCaptureScreenFlag
:
false
,
setUserCaptureScreenText
:
'
禁止截屏
'
,
setUserCaptureScreenText
:
'
禁止截屏
'
permissionGranted
:
false
}
}
},
},
onLoad
()
{
onLoad
()
{
...
@@ -139,30 +138,14 @@
...
@@ -139,30 +138,14 @@
var
that
=
this
;
var
that
=
this
;
uni
.
onUserCaptureScreen
(
function
(
res
)
{
uni
.
onUserCaptureScreen
(
function
(
res
)
{
console
.
log
(
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
({
uni
.
showToast
({
icon
:
"
none
"
,
icon
:
"
none
"
,
title
:
'
捕获截屏事件
'
title
:
'
捕获截屏事件
'
})
})
that
.
screenImage
=
res
.
image
that
.
screenImage
=
res
.
path
}
}
else
{
// 除android 之外的平台,不需要判断返回状态码
uni
.
showToast
({
icon
:
"
none
"
,
title
:
'
捕获截屏事件
'
})
}
});
});
if
(
uni
.
getSystemInfoSync
().
platform
!=
"
android
"
||
that
.
permissionGranted
)
{
if
(
uni
.
getSystemInfoSync
().
platform
!=
"
android
"
)
{
// 除android 之外的平台,直接提示监听已开启
// 除android 之外的平台,直接提示监听已开启
uni
.
showToast
({
uni
.
showToast
({
icon
:
"
none
"
,
icon
:
"
none
"
,
...
...
uni_modules/uni-usercapturescreen/utssdk/app-android/index.uts
浏览文件 @
8eea7a8b
...
@@ -8,7 +8,7 @@ import File from "java.io.File";
...
@@ -8,7 +8,7 @@ import File from "java.io.File";
import Environment from "android.os.Environment";
import Environment from "android.os.Environment";
import System from 'java.lang.System';
import System from 'java.lang.System';
import WindowManager from 'android.view.WindowManager';
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 {
...
@@ -50,10 +50,7 @@ class ScreenFileObserver extends FileObserver {
lastObserverTime = currentTime;
lastObserverTime = currentTime;
const screenShotPath = new File(this.screenFile, path).getPath();
const screenShotPath = new File(this.screenFile, path).getPath();
const res : OnUserCaptureScreenResult = {
const res : OnUserCaptureScreenCallbackResult = {
errCode: 0,
errMsg: "onUserCaptureScreen:ok",
errSubject: "uni-onUserCaptureScreen",
path: screenShotPath
path: screenShotPath
}
}
listener?.(res);
listener?.(res);
...
@@ -68,23 +65,15 @@ class ScreenFileObserver extends FileObserver {
...
@@ -68,23 +65,15 @@ class ScreenFileObserver extends FileObserver {
export const onUserCaptureScreen : OnUserCaptureScreen = function (callback : UserCaptureScreenCallback | null) {
export const onUserCaptureScreen : OnUserCaptureScreen = function (callback : UserCaptureScreenCallback | null) {
// 检查相关权限是否已授予
// 检查相关权限是否已授予
if (ActivityCompat.checkSelfPermission(UTSAndroid.getAppContext()!, Manifest.permission.READ_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
if (ActivityCompat.checkSelfPermission(UTSAndroid.getAppContext()!, Manifest.permission.READ_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
// 无权限,申请权限
,并且告知用户监听失败
// 无权限,申请权限
ActivityCompat.requestPermissions(UTSAndroid.getUniActivity()!, arrayOf(Manifest.permission.READ_EXTERNAL_STORAGE), 1001);
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;
return;
}
}
// 更新监听
// 更新监听
listener = callback;
listener = callback;
let directory_screenshot : File;
let directory_screenshot : File;
if (Build.MANUFACTURER.toLowerCase() ==
=
"xiaomi") {
if (Build.MANUFACTURER.toLowerCase() == "xiaomi") {
// @Suppress("DEPRECATION")
// @Suppress("DEPRECATION")
directory_screenshot = new File(new File(Environment.getExternalStorageDirectory(), Environment.DIRECTORY_DCIM), "Screenshots");
directory_screenshot = new File(new File(Environment.getExternalStorageDirectory(), Environment.DIRECTORY_DCIM), "Screenshots");
} else {
} else {
...
@@ -113,11 +102,7 @@ export const offUserCaptureScreen : OffUserCaptureScreen = function (_ : UserCap
...
@@ -113,11 +102,7 @@ export const offUserCaptureScreen : OffUserCaptureScreen = function (_ : UserCap
export const setUserCaptureScreen : SetUserCaptureScreen = function (option : SetUserCaptureScreenOptions) {
export const setUserCaptureScreen : SetUserCaptureScreen = function (option : SetUserCaptureScreenOptions) {
// 切换到UI线程
// 切换到UI线程
UTSAndroid.getUniActivity()?.runOnUiThread(new SetUserCaptureScreenRunnable(option.enable));
UTSAndroid.getUniActivity()?.runOnUiThread(new SetUserCaptureScreenRunnable(option.enable));
const res : UserCaptureScreenResult = {
const res : SetUserCaptureScreenSuccess = {}
errCode: 0,
errMsg: "setUserCaptureScreen:ok",
errSubject: "uni-setUserCaptureScreen"
}
option.success?.(res);
option.success?.(res);
option.complete?.(res);
option.complete?.(res);
}
}
...
...
uni_modules/uni-usercapturescreen/utssdk/interface.uts
浏览文件 @
8eea7a8b
/**
* uni.onUserCaptureScreen/uni.offUserCaptureScreen回调参数
*/
export type OnUserCaptureScreenCallbackResult = {
export type OnUserCaptureScreenCallbackResult = {
/**
/**
* 截屏文件路径(仅Android返回)
* 截屏文件路径(仅Android返回)
...
@@ -11,30 +13,28 @@ export type OnUserCaptureScreenCallbackResult = {
...
@@ -11,30 +13,28 @@ export type OnUserCaptureScreenCallbackResult = {
*/
*/
export type UserCaptureScreenCallback = (res : OnUserCaptureScreenCallbackResult) => void
export type UserCaptureScreenCallback = (res : OnUserCaptureScreenCallbackResult) => void
/**
/**
* uni.onUserCaptureScreen函数定义
* uni.onUserCaptureScreen函数定义
* 开启截屏监听
* 开启截屏监听
*
*
* @param {UserCaptureScreenCallback} callback
* @param {UserCaptureScreenCallback} callback
* @tutorial https://uniapp.dcloud.net.cn/api/system/capture-screen.html#onusercapturescreen
* @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
* @since 3.6.8
*/
*/
export type OnUserCaptureScreen = (callback : UserCaptureScreenCallback | null) => void
export type OnUserCaptureScreen = (callback : UserCaptureScreenCallback | null) => void
/**
/**
* uni.offUserCaptureScreen函数定义
* 关闭截屏监听
* 关闭截屏监听
*
*
* @param {UserCaptureScreenCallback} callback
* @param {UserCaptureScreenCallback} callback
* @tutorial https://uniapp.dcloud.net.cn/api/system/capture-screen.html#offusercapturescreen
* @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
* @since 3.6.8
*/
*/
export type OffUserCaptureScreen = (callback : UserCaptureScreenCallback | null) => void
export type OffUserCaptureScreen = (callback : UserCaptureScreenCallback | null) => void
/**
/**
* uni.setUserCaptureScreen成功回调参数
* uni.setUserCaptureScreen成功回调参数
*/
*/
...
@@ -48,7 +48,6 @@ export type SetUserCaptureScreenFail = {
...
@@ -48,7 +48,6 @@ export type SetUserCaptureScreenFail = {
/**
/**
* 错误码
* 错误码
* 0:成功
* 0:成功
* -1:permission denied
* 12001:system not support
* 12001:system not support
* 12010:system internal error
* 12010:system internal error
*/
*/
...
@@ -89,31 +88,31 @@ export type SetUserCaptureScreenOptions = {
...
@@ -89,31 +88,31 @@ export type SetUserCaptureScreenOptions = {
/**
/**
* 接口调用成功的回调函数
* 接口调用成功的回调函数
*/
*/
//success : SetUserCaptureScreenSuccessCallback | null,
//
success : SetUserCaptureScreenSuccessCallback | null,
success ?: SetUserCaptureScreenSuccessCallback,
success ?: SetUserCaptureScreenSuccessCallback,
/**
/**
* 接口调用失败的回调函数
* 接口调用失败的回调函数
*/
*/
//fail : SetUserCaptureScreenFailCallback | null,
//
fail : SetUserCaptureScreenFailCallback | null,
fail ?: SetUserCaptureScreenFailCallback,
fail ?: SetUserCaptureScreenFailCallback,
/**
/**
* 接口调用结束的回调函数(调用成功、失败都会执行)
* 接口调用结束的回调函数(调用成功、失败都会执行)
*/
*/
//
complete : SetUserCaptureScreenSuccessCallback |
SetUserCaptureScreenFailCallback | null
//
complete : SetUserCaptureScreenSuccessCallback |
SetUserCaptureScreenFailCallback | null
complete ?: SetUserCaptureScreenCompleteCallback
complete ?: SetUserCaptureScreenCompleteCallback
}
}
/**
/**
* uni.setUserCaptureScreen函数定义
* 设置防截屏
* 设置防截屏
*
*
* @param {SetUserCaptureScreenOptions} options
* @param {SetUserCaptureScreenOptions} options
* @tutorial https://uniapp.dcloud.net.cn/api/system/capture-screen.html#setusercapturescreen
* @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
* @since 3.7.3
*/
*/
export type SetUserCaptureScreen = (options : SetUserCaptureScreenOptions) => void
export type SetUserCaptureScreen = (options : SetUserCaptureScreenOptions) => void
interface uni {
interface uni {
onUserCaptureScreen : OnUserCaptureScreen,
onUserCaptureScreen : OnUserCaptureScreen,
offUserCaptureScreen : OffUserCaptureScreen,
offUserCaptureScreen : OffUserCaptureScreen,
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录