Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
DCloud
unidocs-uni-app-x-zh
提交
090b535b
U
unidocs-uni-app-x-zh
项目概览
DCloud
/
unidocs-uni-app-x-zh
通知
144
Star
2
Fork
33
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
9
列表
看板
标记
里程碑
合并请求
11
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
U
unidocs-uni-app-x-zh
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
9
Issue
9
列表
看板
标记
里程碑
合并请求
11
合并请求
11
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环境中均
<!-- 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
...
...
@@ -37,16 +27,6 @@ UTSAndroid.onAppConfigChange(listener!);
<!-- 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
...
...
@@ -58,15 +38,7 @@ UTSAndroid.onAppConfigChange(listener!);
<!-- 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
...
...
@@ -78,15 +50,7 @@ UTSAndroid.onAppTrimMemory(listener);
<!-- 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
...
...
@@ -98,15 +62,7 @@ UTSAndroid.onAppTrimMemory(listener);
<!-- UTSJSON.UTSAndroid.onAppActivityPause.compatibility -->
```
ts
// 点击Home按钮返回桌面,观察日志输出
let
listener
:(()
=>
void
)
|
null
=
null
;
listener
=
()
=>
{
console
.
log
(
"
onAppActivityPause
"
);
UTSAndroid
.
offAppActivityPause
(
listener
);
}
UTSAndroid
.
onAppActivityPause
(
listener
);
```
### offAppActivityPause
...
...
@@ -118,15 +74,6 @@ UTSAndroid.onAppActivityPause(listener);
<!-- UTSJSON.UTSAndroid.offAppActivityPause.compatibility -->
```
ts
// 点击Home按钮返回桌面,观察日志输出
let
listener
:(()
=>
void
)
|
null
=
null
;
listener
=
()
=>
{
console
.
log
(
"
onAppActivityPause
"
);
UTSAndroid
.
offAppActivityPause
(
listener
);
}
UTSAndroid
.
onAppActivityPause
(
listener
);
```
### onAppActivityResume
...
...
@@ -139,15 +86,6 @@ UTSAndroid.onAppActivityPause(listener);
<!-- UTSJSON.UTSAndroid.onAppActivityResume.compatibility -->
```
ts
// 点击Home按钮返回桌面,再返回应用。 观察日志输出
let
listener
:(()
=>
void
)
|
null
=
null
;
listener
=
()
=>
{
console
.
log
(
"
onAppActivityResume
"
);
UTSAndroid
.
offAppActivityResume
(
listener
);
}
UTSAndroid
.
onAppActivityResume
(
listener
);
```
### offAppActivityResume
...
...
@@ -159,15 +97,7 @@ UTSAndroid.onAppActivityResume(listener);
<!-- UTSJSON.UTSAndroid.offAppActivityResume.compatibility -->
```
ts
// 点击Home按钮返回桌面,再返回应用。 观察日志输出
let
listener
:(()
=>
void
)
|
null
=
null
;
listener
=
()
=>
{
console
.
log
(
"
onAppActivityResume
"
);
UTSAndroid
.
offAppActivityResume
(
listener
);
}
UTSAndroid
.
onAppActivityResume
(
listener
);
```
### onAppActivityDestroy
...
...
@@ -179,14 +109,7 @@ UTSAndroid.onAppActivityResume(listener);
<!-- UTSJSON.UTSAndroid.onAppActivityDestroy.compatibility -->
```
ts
let
listener
:(()
=>
void
)
|
null
=
null
;
listener
=
()
=>
{
console
.
log
(
"
onAppActivityDestroy
"
);
UTSAndroid
.
offAppActivityDestroy
(
listener
);
}
UTSAndroid
.
onAppActivityDestroy
(
listener
);
```
### offAppActivityDestroy
...
...
@@ -198,14 +121,7 @@ UTSAndroid.onAppActivityDestroy(listener);
<!-- UTSJSON.UTSAndroid.offAppActivityDestroy.compatibility -->
```
ts
let
listener
:(()
=>
void
)
|
null
=
null
;
listener
=
()
=>
{
console
.
log
(
"
onAppActivityDestroy
"
);
UTSAndroid
.
offAppActivityDestroy
(
listener
);
}
UTSAndroid
.
onAppActivityDestroy
(
listener
);
```
### onAppActivityResult
...
...
@@ -218,31 +134,7 @@ UTSAndroid.onAppActivityDestroy(listener);
<!-- 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
...
...
@@ -254,31 +146,7 @@ if (takePictureIntent.resolveActivity(UTSAndroid.getUniActivity()!.getPackageMan
<!-- 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
...
...
@@ -290,15 +158,7 @@ if (takePictureIntent.resolveActivity(UTSAndroid.getUniActivity()!.getPackageMan
<!-- UTSJSON.UTSAndroid.onAppActivityBack.compatibility -->
```
ts
// 点击设备回退按钮,观察日志输出
let
listener
:(()
=>
void
)
|
null
=
null
;
listener
=
()
=>
{
console
.
log
(
"
onAppActivityBack
"
);
UTSAndroid
.
offAppActivityBack
(
listener
);
}
UTSAndroid
.
onAppActivityBack
(
listener
);
```
### offAppActivityBack
...
...
@@ -310,15 +170,7 @@ UTSAndroid.onAppActivityBack(listener);
<!-- UTSJSON.UTSAndroid.offAppActivityBack.compatibility -->
```
ts
// 点击设备回退按钮,观察日志输出
let
listener
:(()
=>
void
)
|
null
=
null
;
listener
=
()
=>
{
console
.
log
(
"
onAppActivityBack
"
);
UTSAndroid
.
offAppActivityBack
(
listener
);
}
UTSAndroid
.
onAppActivityBack
(
listener
);
```
### getAppContext()
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录