Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
DCloud
unidocs-uni-app-x-zh
提交
090b535b
U
unidocs-uni-app-x-zh
项目概览
DCloud
/
unidocs-uni-app-x-zh
通知
156
Star
2
Fork
37
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
10
列表
看板
标记
里程碑
合并请求
13
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
U
unidocs-uni-app-x-zh
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
10
Issue
10
列表
看板
标记
里程碑
合并请求
13
合并请求
13
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
提交
090b535b
编写于
4月 24, 2024
作者:
杜庆泉
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Update utsandroid.md
上级
d4dba8fa
变更
1
显示空白变更内容
内联
并排
Showing
1 changed file
with
8 addition
and
156 deletion
+8
-156
docs/uts/utsandroid.md
docs/uts/utsandroid.md
+8
-156
未找到文件。
docs/uts/utsandroid.md
浏览文件 @
090b535b
...
@@ -15,17 +15,7 @@ app-android平台专有内置对象。在uni-app和uni-app x的uts环境中均
...
@@ -15,17 +15,7 @@ app-android平台专有内置对象。在uni-app和uni-app x的uts环境中均
<!-- UTSJSON.UTSAndroid.onAppConfigChange.compatibility -->
<!-- UTSJSON.UTSAndroid.onAppConfigChange.compatibility -->
```
ts
// 切换系统主题观察日志输出
let
listener
:((
res
:
UTSJSONObject
)
=>
void
)
|
null
=
null
;
listener
=
(
ret
:
UTSJSONObject
)
=>
{
let
eventName
=
"
onAppConfigChange -
"
+
JSON
.
stringify
(
ret
);
console
.
log
(
eventName
);
UTSAndroid
.
offAppConfigChange
(
listener
);
}
UTSAndroid
.
onAppConfigChange
(
listener
!
);
```
### offAppConfigChange
### offAppConfigChange
...
@@ -37,16 +27,6 @@ UTSAndroid.onAppConfigChange(listener!);
...
@@ -37,16 +27,6 @@ UTSAndroid.onAppConfigChange(listener!);
<!-- UTSJSON.UTSAndroid.offAppConfigChange.compatibility -->
<!-- UTSJSON.UTSAndroid.offAppConfigChange.compatibility -->
```
ts
// 切换系统主题观察日志输出
let
listener
:((
res
:
UTSJSONObject
)
=>
void
)
|
null
=
null
;
listener
=
(
ret
:
UTSJSONObject
)
=>
{
let
eventName
=
"
onAppConfigChange -
"
+
JSON
.
stringify
(
ret
);
console
.
log
(
eventName
);
UTSAndroid
.
offAppConfigChange
(
listener
);
}
UTSAndroid
.
onAppConfigChange
(
listener
!
);
```
### onAppTrimMemory
### onAppTrimMemory
...
@@ -58,15 +38,7 @@ UTSAndroid.onAppConfigChange(listener!);
...
@@ -58,15 +38,7 @@ UTSAndroid.onAppConfigChange(listener!);
<!-- UTSJSON.UTSAndroid.onAppTrimMemory.compatibility -->
<!-- UTSJSON.UTSAndroid.onAppTrimMemory.compatibility -->
```
ts
// 点击Home按钮返回桌面,观察日志输出
let
listener
:((
res
:
Number
)
=>
void
)
|
null
=
null
;
listener
=
(
ret
:
Number
)
=>
{
console
.
log
(
ret
);
UTSAndroid
.
offAppTrimMemory
(
listener
);
}
UTSAndroid
.
onAppTrimMemory
(
listener
);
```
### offAppTrimMemory
### offAppTrimMemory
...
@@ -78,15 +50,7 @@ UTSAndroid.onAppTrimMemory(listener);
...
@@ -78,15 +50,7 @@ UTSAndroid.onAppTrimMemory(listener);
<!-- UTSJSON.UTSAndroid.offAppTrimMemory.compatibility -->
<!-- UTSJSON.UTSAndroid.offAppTrimMemory.compatibility -->
```
ts
// 点击Home按钮返回桌面,观察日志输出
let
listener
:((
res
:
Number
)
=>
void
)
|
null
=
null
;
listener
=
(
ret
:
Number
)
=>
{
console
.
log
(
ret
);
UTSAndroid
.
offAppTrimMemory
(
listener
);
}
UTSAndroid
.
onAppTrimMemory
(
listener
);
```
### onAppActivityPause
### onAppActivityPause
...
@@ -98,15 +62,7 @@ UTSAndroid.onAppTrimMemory(listener);
...
@@ -98,15 +62,7 @@ UTSAndroid.onAppTrimMemory(listener);
<!-- UTSJSON.UTSAndroid.onAppActivityPause.compatibility -->
<!-- UTSJSON.UTSAndroid.onAppActivityPause.compatibility -->
```
ts
// 点击Home按钮返回桌面,观察日志输出
let
listener
:(()
=>
void
)
|
null
=
null
;
listener
=
()
=>
{
console
.
log
(
"
onAppActivityPause
"
);
UTSAndroid
.
offAppActivityPause
(
listener
);
}
UTSAndroid
.
onAppActivityPause
(
listener
);
```
### offAppActivityPause
### offAppActivityPause
...
@@ -118,15 +74,6 @@ UTSAndroid.onAppActivityPause(listener);
...
@@ -118,15 +74,6 @@ UTSAndroid.onAppActivityPause(listener);
<!-- UTSJSON.UTSAndroid.offAppActivityPause.compatibility -->
<!-- UTSJSON.UTSAndroid.offAppActivityPause.compatibility -->
```
ts
// 点击Home按钮返回桌面,观察日志输出
let
listener
:(()
=>
void
)
|
null
=
null
;
listener
=
()
=>
{
console
.
log
(
"
onAppActivityPause
"
);
UTSAndroid
.
offAppActivityPause
(
listener
);
}
UTSAndroid
.
onAppActivityPause
(
listener
);
```
### onAppActivityResume
### onAppActivityResume
...
@@ -139,15 +86,6 @@ UTSAndroid.onAppActivityPause(listener);
...
@@ -139,15 +86,6 @@ UTSAndroid.onAppActivityPause(listener);
<!-- UTSJSON.UTSAndroid.onAppActivityResume.compatibility -->
<!-- UTSJSON.UTSAndroid.onAppActivityResume.compatibility -->
```
ts
// 点击Home按钮返回桌面,再返回应用。 观察日志输出
let
listener
:(()
=>
void
)
|
null
=
null
;
listener
=
()
=>
{
console
.
log
(
"
onAppActivityResume
"
);
UTSAndroid
.
offAppActivityResume
(
listener
);
}
UTSAndroid
.
onAppActivityResume
(
listener
);
```
### offAppActivityResume
### offAppActivityResume
...
@@ -159,15 +97,7 @@ UTSAndroid.onAppActivityResume(listener);
...
@@ -159,15 +97,7 @@ UTSAndroid.onAppActivityResume(listener);
<!-- UTSJSON.UTSAndroid.offAppActivityResume.compatibility -->
<!-- UTSJSON.UTSAndroid.offAppActivityResume.compatibility -->
```
ts
// 点击Home按钮返回桌面,再返回应用。 观察日志输出
let
listener
:(()
=>
void
)
|
null
=
null
;
listener
=
()
=>
{
console
.
log
(
"
onAppActivityResume
"
);
UTSAndroid
.
offAppActivityResume
(
listener
);
}
UTSAndroid
.
onAppActivityResume
(
listener
);
```
### onAppActivityDestroy
### onAppActivityDestroy
...
@@ -179,14 +109,7 @@ UTSAndroid.onAppActivityResume(listener);
...
@@ -179,14 +109,7 @@ UTSAndroid.onAppActivityResume(listener);
<!-- UTSJSON.UTSAndroid.onAppActivityDestroy.compatibility -->
<!-- UTSJSON.UTSAndroid.onAppActivityDestroy.compatibility -->
```
ts
let
listener
:(()
=>
void
)
|
null
=
null
;
listener
=
()
=>
{
console
.
log
(
"
onAppActivityDestroy
"
);
UTSAndroid
.
offAppActivityDestroy
(
listener
);
}
UTSAndroid
.
onAppActivityDestroy
(
listener
);
```
### offAppActivityDestroy
### offAppActivityDestroy
...
@@ -198,14 +121,7 @@ UTSAndroid.onAppActivityDestroy(listener);
...
@@ -198,14 +121,7 @@ UTSAndroid.onAppActivityDestroy(listener);
<!-- UTSJSON.UTSAndroid.offAppActivityDestroy.compatibility -->
<!-- UTSJSON.UTSAndroid.offAppActivityDestroy.compatibility -->
```
ts
let
listener
:(()
=>
void
)
|
null
=
null
;
listener
=
()
=>
{
console
.
log
(
"
onAppActivityDestroy
"
);
UTSAndroid
.
offAppActivityDestroy
(
listener
);
}
UTSAndroid
.
onAppActivityDestroy
(
listener
);
```
### onAppActivityResult
### onAppActivityResult
...
@@ -218,31 +134,7 @@ UTSAndroid.onAppActivityDestroy(listener);
...
@@ -218,31 +134,7 @@ UTSAndroid.onAppActivityDestroy(listener);
<!-- UTSJSON.UTSAndroid.onAppActivityResult.compatibility -->
<!-- UTSJSON.UTSAndroid.onAppActivityResult.compatibility -->
```
ts
import
Intent
from
'
android.content.Intent
'
import
MediaStore
from
"
android.provider.MediaStore
"
;
import
ActivityCompat
from
"
androidx.core.app.ActivityCompat
"
;
import
Manifest
from
"
android.Manifest
"
;
import
PackageManager
from
"
android.content.pm.PackageManager
"
;
// 检查相关权限是否已经具备
if
(
ActivityCompat
.
checkSelfPermission
(
UTSAndroid
.
getUniActivity
()
!
,
Manifest
.
permission
.
CAMERA
)
!=
PackageManager
.
PERMISSION_GRANTED
)
{
// 不具备权限,申请权限,并且告知用户监听失败
ActivityCompat
.
requestPermissions
(
UTSAndroid
.
getUniActivity
()
!
,
arrayOf
(
Manifest
.
permission
.
CAMERA
),
1002
)
}
let
listener
:((
requestCode
:
Int
,
resultCode
:
Int
,
data
:
Intent
|
null
)
=>
void
)
|
null
=
null
;
listener
=
(
requestCode
:
Int
,
resultCode
:
Int
,
data
?:
Intent
)
=>
{
console
.
log
(
requestCode
);
UTSAndroid
.
offAppActivityResult
(
listener
);
}
UTSAndroid
.
onAppActivityResult
(
listener
);
// 尝试调用系统的 拍照/选择图片
let
takePictureIntent
=
new
Intent
(
MediaStore
.
ACTION_IMAGE_CAPTURE
);
if
(
takePictureIntent
.
resolveActivity
(
UTSAndroid
.
getUniActivity
()
!
.
getPackageManager
())
!=
null
)
{
UTSAndroid
.
getUniActivity
()
!
.
startActivityForResult
(
takePictureIntent
,
1001
);
}
```
### offAppActivityResult
### offAppActivityResult
...
@@ -254,31 +146,7 @@ if (takePictureIntent.resolveActivity(UTSAndroid.getUniActivity()!.getPackageMan
...
@@ -254,31 +146,7 @@ if (takePictureIntent.resolveActivity(UTSAndroid.getUniActivity()!.getPackageMan
<!-- UTSJSON.UTSAndroid.offAppActivityResult.compatibility -->
<!-- UTSJSON.UTSAndroid.offAppActivityResult.compatibility -->
```
ts
import
Intent
from
'
android.content.Intent
'
import
MediaStore
from
"
android.provider.MediaStore
"
;
import
ActivityCompat
from
"
androidx.core.app.ActivityCompat
"
;
import
Manifest
from
"
android.Manifest
"
;
import
PackageManager
from
"
android.content.pm.PackageManager
"
;
// 检查相关权限是否已经具备
if
(
ActivityCompat
.
checkSelfPermission
(
UTSAndroid
.
getUniActivity
()
!
,
Manifest
.
permission
.
CAMERA
)
!=
PackageManager
.
PERMISSION_GRANTED
)
{
// 不具备权限,申请权限,并且告知用户监听失败
ActivityCompat
.
requestPermissions
(
UTSAndroid
.
getUniActivity
()
!
,
arrayOf
(
Manifest
.
permission
.
CAMERA
),
1002
)
}
let
listener
:((
requestCode
:
Int
,
resultCode
:
Int
,
data
:
Intent
|
null
)
=>
void
)
|
null
=
null
;
listener
=
(
requestCode
:
Int
,
resultCode
:
Int
,
data
?:
Intent
)
=>
{
console
.
log
(
requestCode
);
UTSAndroid
.
offAppActivityResult
(
listener
);
}
UTSAndroid
.
onAppActivityResult
(
listener
);
// 尝试调用系统的 拍照/选择图片
let
takePictureIntent
=
new
Intent
(
MediaStore
.
ACTION_IMAGE_CAPTURE
);
if
(
takePictureIntent
.
resolveActivity
(
UTSAndroid
.
getUniActivity
()
!
.
getPackageManager
())
!=
null
)
{
UTSAndroid
.
getUniActivity
()
!
.
startActivityForResult
(
takePictureIntent
,
1001
);
}
```
### onAppActivityBack
### onAppActivityBack
...
@@ -290,15 +158,7 @@ if (takePictureIntent.resolveActivity(UTSAndroid.getUniActivity()!.getPackageMan
...
@@ -290,15 +158,7 @@ if (takePictureIntent.resolveActivity(UTSAndroid.getUniActivity()!.getPackageMan
<!-- UTSJSON.UTSAndroid.onAppActivityBack.compatibility -->
<!-- UTSJSON.UTSAndroid.onAppActivityBack.compatibility -->
```
ts
// 点击设备回退按钮,观察日志输出
let
listener
:(()
=>
void
)
|
null
=
null
;
listener
=
()
=>
{
console
.
log
(
"
onAppActivityBack
"
);
UTSAndroid
.
offAppActivityBack
(
listener
);
}
UTSAndroid
.
onAppActivityBack
(
listener
);
```
### offAppActivityBack
### offAppActivityBack
...
@@ -310,15 +170,7 @@ UTSAndroid.onAppActivityBack(listener);
...
@@ -310,15 +170,7 @@ UTSAndroid.onAppActivityBack(listener);
<!-- UTSJSON.UTSAndroid.offAppActivityBack.compatibility -->
<!-- UTSJSON.UTSAndroid.offAppActivityBack.compatibility -->
```
ts
// 点击设备回退按钮,观察日志输出
let
listener
:(()
=>
void
)
|
null
=
null
;
listener
=
()
=>
{
console
.
log
(
"
onAppActivityBack
"
);
UTSAndroid
.
offAppActivityBack
(
listener
);
}
UTSAndroid
.
onAppActivityBack
(
listener
);
```
### getAppContext()
### getAppContext()
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录