From 3d1b74e2376f0c89440b0c8fb706cfff2632ed57 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=9C=E5=BA=86=E6=B3=89?= Date: Tue, 9 Jul 2024 17:05:04 +0800 Subject: [PATCH] Update utsandroid.md --- docs/uts/utsandroid.md | 72 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 72 insertions(+) diff --git a/docs/uts/utsandroid.md b/docs/uts/utsandroid.md index c12c1067..d559d00d 100644 --- a/docs/uts/utsandroid.md +++ b/docs/uts/utsandroid.md @@ -62,6 +62,12 @@ app-android平台专有内置对象。在uni-app和uni-app x的uts环境中均 +```ts +UTSAndroid.onAppActivityPause(() => { + let eventName = "onAppActivityPause - " + Date.now(); + console.log(eventName); +}); +``` ### offAppActivityPause @@ -74,6 +80,13 @@ app-android平台专有内置对象。在uni-app和uni-app x的uts环境中均 +```ts +// 移除全部监听 +UTSAndroid.offAppActivityPause(); +// 移除指定监听 +UTSAndroid.offAppActivityPause(() => { +}); +``` ### onAppActivityResume @@ -87,6 +100,16 @@ app-android平台专有内置对象。在uni-app和uni-app x的uts环境中均 + +```ts +UTSAndroid.onAppActivityResume(() => { + let eventName = "onAppActivityResume - " + Date.now(); + console.log(eventName); +}); +``` + + + ### offAppActivityResume @@ -99,6 +122,15 @@ app-android平台专有内置对象。在uni-app和uni-app x的uts环境中均 +```ts +// 移除全部监听 +UTSAndroid.onAppActivityResume(); +// 移除指定监听 +UTSAndroid.onAppActivityResume(() => { +}); +``` + + ### onAppActivityDestroy @@ -109,6 +141,12 @@ app-android平台专有内置对象。在uni-app和uni-app x的uts环境中均 +```ts +UTSAndroid.onAppActivityDestroy(() => { + let eventName = "onAppActivityDestroy- " + Date.now(); + console.log(eventName); +}); +``` ### offAppActivityDestroy @@ -122,6 +160,14 @@ app-android平台专有内置对象。在uni-app和uni-app x的uts环境中均 +```ts +// 移除全部监听 +UTSAndroid.offAppActivityDestroy(); +// 移除指定监听 +UTSAndroid.offAppActivityDestroy(() => { +}); +``` + ### onAppActivityResult @@ -134,6 +180,24 @@ app-android平台专有内置对象。在uni-app和uni-app x的uts环境中均 +App 的 activity 启动其他activity的回调结果监听 对应原生的 [onActivityResult](https://developer.android.com/training/basics/intents/result) + +需要特别注意的是 `requestCode` 参数,这个参数用于区别 不同的请求来源,开发者应该只处理自己发起请求 + +```ts +let customRequestCode = 12000 + +UTSAndroid.onAppActivityResult((requestCode: Int, resultCode: Int, data?: Intent) => { + if(requestCode == 12000){ + // 我们发起的请求 + let eventName = "onAppActivityResult - requestCode:" + requestCode + " -resultCode:"+resultCode + " -data:"+JSON.stringify(data); + console.log(eventName); + }else{ + // 别的代码发起的请求,不要处理 + } + +}); +``` ### offAppActivityResult @@ -146,6 +210,14 @@ app-android平台专有内置对象。在uni-app和uni-app x的uts环境中均 +```ts +// 移除全部监听 +UTSAndroid.offAppActivityResult(); +// 移除指定监听 +UTSAndroid.offAppActivityResult(() => { +}); +``` + ### onAppActivityBack -- GitLab