Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
DCloud
Hello UTS
提交
0802e20f
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看板
提交
0802e20f
编写于
5月 22, 2024
作者:
WOSHIMAHAIFENG
浏览文件
操作
浏览文件
下载
差异文件
Merge branch 'dev-activitycb' into 'dev'
[activitycallback+privacy]添加示例 See merge request
!7
上级
840d9470
0dbf2711
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
297 addition
and
273 deletion
+297
-273
pages/SyntaxCase/utsAndroid.uvue
pages/SyntaxCase/utsAndroid.uvue
+286
-245
uni_modules/uts-platform-api/utssdk/app-android/index.uts
uni_modules/uts-platform-api/utssdk/app-android/index.uts
+10
-5
uni_modules/uts-syntaxcase/utssdk/index.uts
uni_modules/uts-syntaxcase/utssdk/index.uts
+1
-23
未找到文件。
pages/SyntaxCase/utsAndroid.uvue
浏览文件 @
0802e20f
<template>
<template>
<!-- #ifdef APP-ANDROID -->
<!-- #ifdef APP-ANDROID -->
<!-- #ifdef APP -->
<scroll-view style="flex: 1">
<scroll-view style="flex: 1">
<!-- #endif -->
<view>
<view>
<view class="uni-padding-wrap uni-common-mt">
<view class="uni-padding-wrap uni-common-mt">
<view class="uni-hello-text"> 逐一点击执行,观察测试反馈 </view>
<view class="uni-hello-text"> 逐一点击执行,观察测试反馈 </view>
...
@@ -19,7 +17,6 @@
...
@@ -19,7 +17,6 @@
<button @click="pathTestClick">路径转换测试</button>
<button @click="pathTestClick">路径转换测试</button>
<button @click="privacyStateClick">隐私协议状态测试</button>
<button @click="privacyStateClick">隐私协议状态测试</button>
<button @click="privacyStateCallBackClick">隐私协议回调测试</button>
<button @click="privacyStateCallBackClick">隐私协议回调测试</button>
<button @click="privacyStateCallBackClick">隐私协议回调测试</button>
<view class="uni-padding-wrap uni-common-mt">
<view class="uni-padding-wrap uni-common-mt">
<view class="uni-hello-text">
<view class="uni-hello-text">
1. 当前页面已通过initAppLifecycle函数注册了生命周期监听。
1. 当前页面已通过initAppLifecycle函数注册了生命周期监听。
...
@@ -44,299 +41,343 @@
...
@@ -44,299 +41,343 @@
</view>
</view>
<button @tap="getDeviceInfoClick">获取设备基础信息</button>
<button @tap="getDeviceInfoClick">获取设备基础信息</button>
<button @tap="getFileProviderUriClick">使用外部应用访问私有文件</button>
<button @tap="getFileProviderUriClick">使用外部应用访问私有文件</button>
<!-- #ifdef APP-ANDROID -->
<button @tap="activityCallback">注册activity 回调方法</button>
<button @tap="activityCallback">注册activity 回调方法</button>
<view class="uni-padding-wrap uni-common-mt">
<view class="uni-padding-wrap uni-common-mt">
<view class="uni-hello-text">
<view class="uni-hello-text">
点击注册activity 回调方法后,可以手动切换其他APP再返回,可在控制台和界面观察事件日志
点击注册activity 回调方法后,可以手动切换其他APP再返回,可在控制台和界面观察事件日志
</view>
</view>
</view>
<view class="uni-padding-wrap uni-common-mt"
>
</view
>
<view class="text-box" scroll-y="true
">
<view class="uni-padding-wrap uni-common-mt
">
<text>{{ cbText }}</text
>
<view class="text-box" scroll-y="true"
>
<
/view
>
<
text>{{ cbText }}</text
>
</view>
</view>
<button @tap="unRegActivityCallback">取消注册activity 回调方法</button>
</view>
<button @tap="unRegActivityCallback">取消注册activity 回调方法</button>
<!-- #endif -->
</view>
</view>
<!-- #ifdef APP -->
</scroll-view>
</scroll-view>
<!-- #endif -->
<!-- #endif -->
<!-- #endif -->
</template>
</template>
<script>
<script>
<!-- #ifdef APP-ANDROID -->
import {
import {
getAppContextTest,
getAppContextTest,
getUniActivityTest,
getUniActivityTest,
getJavaClassTest,
getJavaClassTest,
getAppTempPathTest,
getAppTempPathTest,
typeofClickTest,
typeofClickTest,
gotoSystemPermissionActivityTest,
gotoSystemPermissionActivityTest,
arrayPermissionFlowTest,
arrayPermissionFlowTest,
singlePermissionFlowTest,
singlePermissionFlowTest,
dispatchAsyncTest,
dispatchAsyncTest,
convert2AbsFullPathTest,
convert2AbsFullPathTest,
unRegLifecycle,
unRegLifecycle,
initAppLifecycle,
initAppLifecycle,
gotoCameraTake,
gotoCameraTake,
getDeviceInfoTest,
getDeviceInfoTest,
privacyStateTest
privacyStateTest,
} from '@/uni_modules/uts-platform-api'
privacyStateCallBackTest
// #ifdef APP-ANDROID
} from '@/uni_modules/uts-platform-api'
import {
// #ifdef APP-ANDROID
import {
UTSAcvitiyLifeCycleCallback,
UTSAcvitiyLifeCycleCallback,
UTSAcvitiyKeyEventCallback,
UTSAcvitiyKeyEventCallback,
UTSActivityWindowCallback,
UTSActivityWindowCallback,
UTSActivityCallback,
UTSActivityCallback,
UTSActivityComponentCallback,
UTSActivityComponentCallback,
onCallbackChange,
onCallbackChange
registerCallbacks,
} from '@/uni_modules/uts-syntaxcase'
unRegisterCallbacks
// #endif
} from '@/uni_modules/uts-syntaxcase'
// #endif
import File from 'java.io.File';
import Intent from 'android.content.Intent';
/**
* 测试在页面生命周期之外,使用api
*/
export default {
data() {
return {
text: '',
cbText: '',
selectImage: '',
callback: [] as Any[]
}
},
unmounted() {
// #ifdef APP-ANDROID
this.unRegActivityCallback()
// #endif
import File from 'java.io.File';
},
import Intent from 'android.content.Intent';
onLoad: function () {
let that = this
initAppLifecycle(function (eventLog) {
// 展示捕捉到的声明周期日志
let nextLine = that.text + eventLog
that.text = nextLine
let nextLineFlag = that.text + '\n'
that.text = nextLineFlag
})
},
methods: {
privacyStateClick() {
privacyStateTest(function (ret, desc) {
if (ret) {
uni.showToast({
title: '测试通过',
})
} else {
uni.showToast({
icon: 'none',
title: '失败:' + desc,
})
}
})
},
privacyStateCallBackClick() {
let isAgree : boolean = true
const cb = (ret : PrivacyOption) => {
console.log('privacyStateCallBackTest->' + ret.isAgree)
if (ret.isAgree==isAgree) {
uni.showToast({
title: '测试通过'
})
} else {
uni.showToast({
icon: 'none',
title: '失败'
})
}
}
// 先重置用户同意状态
UTSAndroid.onPrivacyAgreeChange(cb)
UTSAndroid.setPrivacyAgree(isAgree)
UTSAndroid.offPrivacyAgreeChange(cb)
setTimeout(function () {
console.log('privacyStateCallBackTest->false' )
UTSAndroid.setPrivacyAgree(false)
}, 5000);
},
getDeviceInfoClick() {
this.text = getDeviceInfoTest()
},
testGoOtherActivity() {
var that = this
let ret = gotoCameraTake(function (file) {
// 展示捕捉到的声明周期日志
console.log(file)
that.selectImage = 'file://' + file
})
/**
if (!ret) {
* 测试在页面生命周期之外,使用api
*/
export default {
data() {
return {
text: '',
cbText:'',
selectImage: '',
callbackIds: [] as string[]
}
},
unmounted() {
// #ifdef APP-ANDROID
this.unRegActivityCallback()
// #endif
},
onLoad: function () {
let that = this
initAppLifecycle(function (eventLog) {
// 展示捕捉到的声明周期日志
let nextLine = that.text + eventLog
that.text = nextLine
let nextLineFlag = that.text + '\n'
that.text = nextLineFlag
})
},
methods: {
privacyStateClick() {
privacyStateTest(function (ret, desc) {
if (ret) {
uni.showToast({
uni.showToast({
title: '测试通过',
icon: 'none',
title: '测试失败',
})
}
},
testUnRegLifecycle() {
// 取消注册生命周期
unRegLifecycle()
},
getJavaClassClick() {
if (getJavaClassTest()) {
uni.showToast({
title: '测试通过'
})
})
} else {
} else {
uni.showToast({
uni.showToast({
icon: '
none
',
icon: '
error
',
title: '
失败:' + desc,
title: '
测试失败'
})
})
}
}
})
},
},
getAppContextClick() {
privacyStateCallBackClick() {
if (getAppContextTest()) {
privacyStateCallBackTest(function(ret, desc) {
if (ret) {
uni.showToast({
uni.showToast({
title: '测试通过'
title: '测试通过'
,
})
})
} else {
} else {
uni.showToast({
uni.showToast({
icon: '
none
',
icon: '
error
',
title: '
失败:' + desc
title: '
测试失败',
})
})
}
}
})
},
},
getDeviceInfoClick() {
this.text = getDeviceInfoTest()
},
testGoOtherActivity() {
var that = this
let ret = gotoCameraTake(function (file) {
// 展示捕捉到的声明周期日志
console.log(file)
that.selectImage = 'file://' + file
})
if (!ret) {
getUniActivityClick() {
uni.showToast({
if (getUniActivityTest()) {
icon: 'none',
title: '测试失败',
})
}
},
testUnRegLifecycle() {
// 取消注册生命周期
unRegLifecycle()
},
getJavaClassClick() {
if (getJavaClassTest()) {
uni.showToast({
title: '测试通过'
})
} else {
uni.showToast({
icon: 'error',
title: '测试失败'
})
}
},
getAppContextClick() {
if (getAppContextTest()) {
uni.showToast({
title: '测试通过',
})
} else {
uni.showToast({
icon: 'error',
title: '测试失败',
})
}
},
getUniActivityClick() {
if (getUniActivityTest()) {
uni.showToast({
title: '测试通过',
})
} else {
uni.showToast({
icon: 'error',
title: '测试失败',
})
}
},
pathTestClick() {
if (convert2AbsFullPathTest()) {
uni.showToast({
title: '测试通过',
})
} else {
uni.showToast({
icon: 'error',
title: '测试失败',
})
}
},
getFileProviderUriClick() {
let file = new File(UTSAndroid.getResourcePath("static/logo.png"))
const uri = UTSAndroid.getFileProviderUri(file)
console.log("uri",uri.toString())
const intent = new Intent(Intent.ACTION_VIEW, uri)
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION) // 添加权限标志
const context = UTSAndroid.getUniActivity()!;
context.startActivity(intent);
},
getAppTempPathClick() {
if (getAppTempPathTest()) {
uni.showToast({
title: '测试通过',
})
} else {
uni.showToast({
icon: 'error',
title: '测试失败',
})
}
},
dispatchAsyncClick() {
dispatchAsyncTest(function (ret, desc) {
if (ret) {
uni.showToast({
uni.showToast({
title: '测试通过',
title: '测试通过',
})
})
} else {
} else {
uni.showToast({
uni.showToast({
icon: '
none
',
icon: '
error
',
title: '
失败:' + desc
,
title: '
测试失败'
,
})
})
}
}
})
},
},
pathTestClick() {
typeofClick() {
if (convert2AbsFullPathTest()) {
if (typeofClickTest()) {
uni.showToast({
title: '测试通过',
})
} else {
uni.showToast({
icon: 'error',
title: '测试失败',
})
}
},
gotoSystemPermissionActivityClick() {
gotoSystemPermissionActivityTest()
},
arrayPermissionFlowClick() {
arrayPermissionFlowTest(function (ret, desc) {
if (ret) {
uni.showToast({
uni.showToast({
icon: 'none',
title: '测试通过',
title: '测试通过',
})
})
} else {
} else {
uni.showToast({
uni.showToast({
icon: '
none
',
icon: '
error
',
title: '
失败:' + desc
,
title: '
测试失败'
,
})
})
}
}
})
},
},
getFileProviderUriClick() {
singlePermissionFlowClick() {
let file = new File(UTSAndroid.getResourcePath("static/logo.png"))
singlePermissionFlowTest(function (ret, desc) {
const uri = UTSAndroid.getFileProviderUri(file)
if (ret) {
console.log("uri", uri.toString())
const intent = new Intent(Intent.ACTION_VIEW, uri)
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION) // 添加权限标志
const context = UTSAndroid.getUniActivity()!;
context.startActivity(intent);
},
getAppTempPathClick() {
if (getAppTempPathTest()) {
uni.showToast({
uni.showToast({
icon: 'none',
title: '测试通过',
title: '测试通过',
})
})
} else {
} else {
uni.showToast({
uni.showToast({
icon: '
none
',
icon: '
error
',
title: '
失败:' + desc
,
title: '
测试失败'
,
})
})
}
}
})
},
},
dispatchAsyncClick() {
// #ifdef APP-ANDROID
dispatchAsyncTest(function (ret, desc) {
activityCallback(){
if (ret) {
var that = this
uni.showToast({
onCallbackChange(function (eventLog:string) {
title: '测试通过',
// 展示捕捉到的声明周期日志
})
let nextLine = that.cbText + eventLog
} else {
that.cbText = nextLine
uni.showToast({
let nextLineFlag = that.cbText + '\n'
icon: 'none',
that.cbText = nextLineFlag
title: '失败:' + desc,
})
})
registerCallbacks()
}
},
})
unRegActivityCallback(){
},
unRegisterCallbacks()
typeofClick() {
}
if (typeofClickTest()) {
// #endif
uni.showToast({
title: '测试通过',
})
} else {
uni.showToast({
icon: 'error',
title: '测试失败',
})
}
},
gotoSystemPermissionActivityClick() {
gotoSystemPermissionActivityTest()
},
arrayPermissionFlowClick() {
arrayPermissionFlowTest(function (ret, desc) {
if (ret) {
uni.showToast({
icon: 'none',
title: '测试通过',
})
} else {
uni.showToast({
icon: 'none',
title: '失败:' + desc,
})
}
})
},
singlePermissionFlowClick() {
singlePermissionFlowTest(function (ret, desc) {
if (ret) {
uni.showToast({
icon: 'none',
title: '测试通过',
})
} else {
uni.showToast({
icon: 'none',
title: '失败:' + desc,
})
}
})
},
// #ifdef APP-ANDROID
// #ifdef UNI-APP-X
activityCallback() {
var that = this
onCallbackChange(function (eventLog : string) {
// 展示捕捉到的声明周期日志
let nextLine = that.cbText + eventLog
that.cbText = nextLine
let nextLineFlag = that.cbText + '\n'
that.cbText = nextLineFlag
})
this.callback.push(new UTSAcvitiyLifeCycleCallback())
this.callback.push(new UTSActivityWindowCallback())
this.callback.push(new UTSAcvitiyKeyEventCallback())
this.callback.push(new UTSActivityCallback())
this.callback.push(new UTSActivityComponentCallback())
this.callback.forEach((value) => {
if (value instanceof UTSAcvitiyLifeCycleCallback) {
UTSAndroid.onActivityCallback(value)
}
if (value instanceof UTSActivityWindowCallback) {
UTSAndroid.onActivityCallback(value)
}
if (value instanceof UTSAcvitiyKeyEventCallback) {
UTSAndroid.onActivityCallback(value)
}
if (value instanceof UTSActivityCallback) {
UTSAndroid.onActivityCallback(value)
}
if (value instanceof UTSActivityComponentCallback) {
UTSAndroid.onActivityCallback(value)
}
},
})
}
},
<!-- #endif -->
unRegActivityCallback() {
this.callback.forEach((value) => {
if (value instanceof UTSAcvitiyLifeCycleCallback) {
UTSAndroid.offActivityCallback(value)
}
if (value instanceof UTSActivityWindowCallback) {
UTSAndroid.offActivityCallback(value)
}
if (value instanceof UTSAcvitiyKeyEventCallback) {
UTSAndroid.offActivityCallback(value)
}
if (value instanceof UTSActivityCallback) {
UTSAndroid.offActivityCallback(value)
}
if (value instanceof UTSActivityComponentCallback) {
UTSAndroid.offActivityCallback(value)
}
})
}
// #endif
// #endif
},
}
</script>
</script>
<style>
<style>
.testButton {
.testButton {
width: 100%;
width: 100%;
}
}
</style>
</style>
\ No newline at end of file
uni_modules/uts-platform-api/utssdk/app-android/index.uts
浏览文件 @
0802e20f
...
@@ -83,18 +83,23 @@ export function privacyStateTest(callback : (ret : boolean, desc : string) => vo
...
@@ -83,18 +83,23 @@ export function privacyStateTest(callback : (ret : boolean, desc : string) => vo
export function privacyStateCallBackTest(callback : (ret : boolean, desc : string) => void) {
export function privacyStateCallBackTest(callback : (ret : boolean, desc : string) => void) {
let isAgree : boolean = true
let isAgree : boolean = true
const cb = (ret :
boolea
n) => {
const cb = (ret :
PrivacyOptio
n) => {
console.log('privacyStateCallBackTest->' + ret)
console.log('privacyStateCallBackTest->' + ret
.isAgree
)
if (ret == isAgree) {
if (ret
.isAgree
== isAgree) {
callback(true, "pass")
callback(true, "pass")
} else {
} else {
callback(false, "callback error")
callback(false, "callback error")
}
}
}
}
// 先重置用户同意状态
// 先重置用户同意状态
const callBackId=UTSAndroid.registerPrivacyAgreeListener
(cb)
UTSAndroid.onPrivacyAgreeChange
(cb)
UTSAndroid.setPrivacyAgree(isAgree)
UTSAndroid.setPrivacyAgree(isAgree)
UTSAndroid.unRegisterPrivacyAgreeListener(callBackId)
UTSAndroid.offPrivacyAgreeChange(cb)
setTimeout(function () {
console.log('privacyStateCallBackTest->false')
UTSAndroid.setPrivacyAgree(false)
}, 5000);
}
}
/**
/**
...
...
uni_modules/uts-syntaxcase/utssdk/index.uts
浏览文件 @
0802e20f
...
@@ -178,32 +178,10 @@ import ActionMode from 'android.view.ActionMode';
...
@@ -178,32 +178,10 @@ import ActionMode from 'android.view.ActionMode';
// export let onCallBackChange: (event: string) => void = (res) => {};
// export let onCallBackChange: (event: string) => void = (res) => {};
let
callback
:
(
eventLog
:
string
)
=>
void
=
(
res
)
=>
{
};
let
callback
:
(
eventLog
:
string
)
=>
void
=
(
res
)
=>
{
};
let
callbackIds
:
string
[]
=
[];
export
function
onCallbackChange
(
fn
:
(
eventLog
:
string
)
=>
void
)
{
export
function
onCallbackChange
(
fn
:
(
eventLog
:
string
)
=>
void
)
{
callback
=
fn
callback
=
fn
}
}
export
function
registerCallbacks
()
{
let
reg1
=
UTSAndroid
.
registerActivityCallback
(
new
UTSAcvitiyLifeCycleCallback
())
let
reg2
=
UTSAndroid
.
registerActivityCallback
(
new
UTSActivityWindowCallback
())
let
reg3
=
UTSAndroid
.
registerActivityCallback
(
new
UTSAcvitiyKeyEventCallback
())
let
reg4
=
UTSAndroid
.
registerActivityCallback
(
new
UTSActivityCallback
())
let
reg5
=
UTSAndroid
.
registerActivityCallback
(
new
UTSActivityComponentCallback
())
callbackIds
.
push
(
reg1
)
callbackIds
.
push
(
reg2
)
callbackIds
.
push
(
reg3
)
callbackIds
.
push
(
reg4
)
callbackIds
.
push
(
reg5
)
}
export
function
unRegisterCallbacks
()
{
callbackIds
.
forEach
((
value
)
=>
{
console
.
log
(
value
)
UTSAndroid
.
unRegisterActivityCallback
(
value
)
})
}
export
class
UTSAcvitiyLifeCycleCallback
extends
UniActivityLifeCycleCallback
{
export
class
UTSAcvitiyLifeCycleCallback
extends
UniActivityLifeCycleCallback
{
constructor
()
{
constructor
()
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录