Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
DCloud
Hello UTS
提交
368b85f3
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看板
提交
368b85f3
编写于
7月 11, 2024
作者:
M
mahaifeng
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[activity-callback]修改示例位置
上级
a96be066
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
107 addition
and
84 deletion
+107
-84
pages/SyntaxCase/utsAndroid.uvue
pages/SyntaxCase/utsAndroid.uvue
+0
-80
pages/SystemAPI/SystemAPI.uvue
pages/SystemAPI/SystemAPI.uvue
+107
-4
未找到文件。
pages/SyntaxCase/utsAndroid.uvue
浏览文件 @
368b85f3
...
@@ -41,19 +41,6 @@
...
@@ -41,19 +41,6 @@
</view>
</view>
<button @tap="getDeviceInfoClick">获取设备基础信息</button>
<button @tap="getDeviceInfoClick">获取设备基础信息</button>
<button @tap="getFileProviderUriClick">使用外部应用访问私有文件</button>
<button @tap="getFileProviderUriClick">使用外部应用访问私有文件</button>
<button @tap="activityCallback">注册activity 回调方法</button>
<view class="uni-padding-wrap uni-common-mt">
<view class="uni-hello-text">
点击注册activity 回调方法后,可以手动切换其他APP再返回,可在控制台和界面观察事件日志
</view>
</view>
<view class="uni-padding-wrap uni-common-mt">
<view class="text-box" scroll-y="true">
<text>{{ cbText }}</text>
</view>
</view>
<button @tap="unRegActivityCallback">取消注册activity 回调方法</button>
</view>
</view>
</scroll-view>
</scroll-view>
<!-- #endif -->
<!-- #endif -->
...
@@ -102,16 +89,10 @@
...
@@ -102,16 +89,10 @@
data() {
data() {
return {
return {
text: '',
text: '',
cbText: '',
selectImage: '',
selectImage: '',
callback: [] as Any[]
}
}
},
},
unmounted() {
unmounted() {
// #ifdef APP-ANDROID
this.unRegActivityCallback()
// #endif
},
},
onLoad: function () {
onLoad: function () {
// #ifdef APP-ANDROID
// #ifdef APP-ANDROID
...
@@ -321,67 +302,6 @@
...
@@ -321,67 +302,6 @@
})
})
},
},
// #endif
// #endif
// #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
})
let index = getCurrentPages().length - 1
let page = getCurrentPages()[index]
console.log('page route=' + page.route)
this.callback.push(new UTSAcvitiyLifeCycleCallback())
this.callback.push(new UTSActivityWindowCallback())
this.callback.push(new UTSAcvitiyKeyEventCallback())
this.callback.push(new UTSActivityCallback(), page.route)
this.callback.push(new UTSActivityComponentCallback())
this.callback.forEach((value) => {
if (value instanceof UTSAcvitiyLifeCycleCallback) {
UTSAndroid.onActivityCallback(value,page.route)
}
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)
}
})
},
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>
...
...
pages/SystemAPI/SystemAPI.uvue
浏览文件 @
368b85f3
...
@@ -20,7 +20,20 @@
...
@@ -20,7 +20,20 @@
<script lang="ts">
<script lang="ts">
import { gotoDemoActivity,sayHelloFromJar } from "@/uni_modules/uts-nativepage";
import { gotoDemoActivity,sayHelloFromJar } from "@/uni_modules/uts-nativepage";
import { getBatteryInfo, GetBatteryInfoOptions } from "@/uni_modules/uts-getbatteryinfo";
import { getBatteryInfo, GetBatteryInfoOptions } from "@/uni_modules/uts-getbatteryinfo";
// #ifdef APP-ANDROID
import {
UTSAcvitiyLifeCycleCallback,
UTSAcvitiyKeyEventCallback,
UTSActivityWindowCallback,
UTSActivityCallback,
UTSActivityComponentCallback,
onCallbackChange
} from '@/uni_modules/uts-syntaxcase'
import File from 'java.io.File';
import Intent from 'android.content.Intent';
// #endif
type Page = {
type Page = {
name : string,
name : string,
url ?: string
url ?: string
...
@@ -31,7 +44,12 @@
...
@@ -31,7 +44,12 @@
open : boolean,
open : boolean,
pages : Page[],
pages : Page[],
}
}
export default {
export default {
unmounted() {
// #ifdef APP-ANDROID
this.unRegActivityCallback()
// #endif
},
data() {
data() {
return {
return {
title: '系统API示例',
title: '系统API示例',
...
@@ -42,7 +60,15 @@
...
@@ -42,7 +60,15 @@
pages: [{
pages: [{
name: "获取电池电量",
name: "获取电池电量",
function: "testGetBatteryCapacity"
function: "testGetBatteryCapacity"
}] as Page[]
}
// #ifdef APP-ANDROID
,
{
name: "注册activity 回调方法",
function: "testActivityCallback"
},
// #endif
] as Page[]
},
},
{
{
name: "系统事件",
name: "系统事件",
...
@@ -74,7 +100,9 @@
...
@@ -74,7 +100,9 @@
] as ListItem[],
] as ListItem[],
arrowUpIcon: '/static/icons/arrow-up.png',
arrowUpIcon: '/static/icons/arrow-up.png',
arrowDownIcon: '/static/icons/arrow-down.png',
arrowDownIcon: '/static/icons/arrow-down.png',
arrowRightIcon: '/static/icons/arrow-right.png',
arrowRightIcon: '/static/icons/arrow-right.png',
callback: [] as Any[],
cbText: '',
}
}
},
},
methods: {
methods: {
...
@@ -94,6 +122,9 @@
...
@@ -94,6 +122,9 @@
case 'testGetBatteryCapacity':
case 'testGetBatteryCapacity':
this.testGetBatteryCapacity()
this.testGetBatteryCapacity()
break
break
case 'testActivityCallback':
this.testActivityCallback()
break
case 'testGotoDemoActivity':
case 'testGotoDemoActivity':
this.testGotoDemoActivity()
this.testGotoDemoActivity()
case 'testNativeJar':
case 'testNativeJar':
...
@@ -107,7 +138,7 @@
...
@@ -107,7 +138,7 @@
})
})
},
},
testGetBatteryCapacity() {
testGetBatteryCapacity() {
getBatteryInfo({
getBatteryInfo({
success(res) {
success(res) {
uni.showToast({
uni.showToast({
...
@@ -117,6 +148,78 @@
...
@@ -117,6 +148,78 @@
}
}
} as GetBatteryInfoOptions)
} as GetBatteryInfoOptions)
},
},
// #ifdef APP-ANDROID
testActivityCallback(){
this.activityCallback()
},
activityCallback() {
uni.showToast({
title: "注册成功,请尝试切换到其他app,在切换回来",
icon: 'none'
});
var that = this
onCallbackChange(function (eventLog : string) {
// 展示捕捉到的声明周期日志
let nextLine = that.cbText + eventLog
that.cbText = nextLine
let nextLineFlag = that.cbText + '\n'
that.cbText = nextLineFlag
console.log(that.cbText)
uni.showToast({
title: "activity 回调方法:" +eventLog,
icon: 'none'
});
})
let index = getCurrentPages().length - 1
let page = getCurrentPages()[index]
this.callback.push(new UTSAcvitiyLifeCycleCallback())
this.callback.push(new UTSActivityWindowCallback())
this.callback.push(new UTSAcvitiyKeyEventCallback())
this.callback.push(new UTSActivityCallback(), page.route)
this.callback.push(new UTSActivityComponentCallback())
this.callback.forEach((value) => {
if (value instanceof UTSAcvitiyLifeCycleCallback) {
UTSAndroid.onActivityCallback(value,'tabBar')
}
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)
}
})
},
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
testNativeJar() {
testNativeJar() {
let ret = sayHelloFromJar();
let ret = sayHelloFromJar();
uni.showToast({
uni.showToast({
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录