Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenHarmony
Docs
提交
d7ae8dcc
D
Docs
项目概览
OpenHarmony
/
Docs
1 年多 前同步成功
通知
159
Star
292
Fork
28
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
D
Docs
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
d7ae8dcc
编写于
12月 27, 2022
作者:
zyjhandsome
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
优化《@ohos.app.ability.appManager (appManager)》章节部分内容,修复'on'示例代码问题
Signed-off-by:
zyjhandsome
<
zyjhandsome@126.com
>
上级
d7a488ad
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
55 addition
and
55 deletion
+55
-55
zh-cn/application-dev/reference/apis/js-apis-app-ability-appManager.md
...tion-dev/reference/apis/js-apis-app-ability-appManager.md
+55
-55
未找到文件。
zh-cn/application-dev/reference/apis/js-apis-app-ability-appManager.md
浏览文件 @
d7ae8dcc
...
...
@@ -27,10 +27,10 @@ static isRunningInStabilityTest(callback: AsyncCallback<boolean>): void
|AsyncCallback
<
boolean
>
|以回调方式返回接口运行结果及当前是否处于稳定性测试场景,可进行错误处理或其他自定义处理。true: 处于稳定性测试场景,false:处于非稳定性测试场景。 |
**示例:**
```
ts
appManager
.
isRunningInStabilityTest
((
err
,
flag
)
=>
{
if
(
err
.
code
!=
0
)
{
if
(
err
.
code
!=
=
0
)
{
conseole
.
log
(
"
isRunningInStabilityTest faile, err:
"
+
JSON
.
stringify
(
err
));
}
else
{
console
.
log
(
"
The result of isRunningInStabilityTest is:
"
+
JSON
.
stringify
(
flag
));
...
...
@@ -54,7 +54,7 @@ static isRunningInStabilityTest(): Promise<boolean>
| Promise
<
boolean
>
| 以Promise方式返回接口运行结果及当前是否处于稳定性测试场景,可进行错误处理或其他自定义处理。true: 处于稳定性测试场景,false:处于非稳定性测试场景。 |
**示例:**
```
ts
appManager
.
isRunningInStabilityTest
().
then
((
flag
)
=>
{
console
.
log
(
"
The result of isRunningInStabilityTest is:
"
+
JSON
.
stringify
(
flag
));
...
...
@@ -79,7 +79,7 @@ isRamConstrainedDevice(): Promise\<boolean>;
| Promise
<
boolean
>
| 以Promise方式返回接口运行结果及当前设备是否为ram受限设备,可进行错误处理或其他自定义处理。true:当前设备为ram受限设备,false:当前设备为非ram受限设备。 |
**示例:**
```
ts
appManager
.
isRamConstrainedDevice
().
then
((
data
)
=>
{
console
.
log
(
"
The result of isRamConstrainedDevice is:
"
+
JSON
.
stringify
(
data
));
...
...
@@ -103,10 +103,10 @@ isRamConstrainedDevice(callback: AsyncCallback\<boolean>): void;
| AsyncCallback
<
boolean
>
|以回调方式返回接口运行结果及当前设备是否为ram受限设备,可进行错误处理或其他自定义处理。true:当前设备为ram受限设备,false:当前设备为非ram受限设备。 |
**示例:**
```
ts
appManager
.
isRamConstrainedDevice
((
err
,
data
)
=>
{
if
(
err
.
code
!=
0
)
{
if
(
err
.
code
!=
=
0
)
{
console
.
log
(
"
isRamConstrainedDevice faile, err:
"
+
JSON
.
stringify
(
err
));
}
else
{
console
.
log
(
"
The result of isRamConstrainedDevice is:
"
+
JSON
.
stringify
(
data
));
...
...
@@ -129,7 +129,7 @@ getAppMemorySize(): Promise\<number>;
| Promise
<
number
>
| 以Promise方式返回接口运行结果及应用程序内存大小,可进行错误处理或其他自定义处理。 |
**示例:**
```
ts
appManager
.
getAppMemorySize
().
then
((
data
)
=>
{
console
.
log
(
"
The size of app memory is:
"
+
JSON
.
stringify
(
data
));
...
...
@@ -153,10 +153,10 @@ getAppMemorySize(callback: AsyncCallback\<number>): void;
|AsyncCallback
<
number
>
|以回调方式返回接口运行结果及应用程序内存大小,可进行错误处理或其他自定义处理。 |
**示例:**
```
ts
appManager
.
getAppMemorySize
((
err
,
data
)
=>
{
if
(
err
.
code
!=
0
)
{
if
(
err
.
code
!=
=
0
)
{
console
.
log
(
"
getAppMemorySize faile, err:
"
+
JSON
.
stringify
(
err
));
}
else
{
console
.
log
(
"
The size of app memory is:
"
+
JSON
.
stringify
(
data
));
...
...
@@ -183,7 +183,7 @@ getProcessRunningInformation(): Promise\<Array\<ProcessRunningInformation>>;
| Promise
\<
Array
\<
[
ProcessRunningInformation
](
js-apis-inner-application-processRunningInformation.md
)
>> | 以Promise方式返回接口运行结果及有关运行进程的信息,可进行错误处理或其他自定义处理。 |
**示例:**
```
ts
appManager
.
getProcessRunningInformation
().
then
((
data
)
=>
{
console
.
log
(
"
The process running information is:
"
+
JSON
.
stringify
(
data
));
...
...
@@ -211,10 +211,10 @@ getProcessRunningInformation(callback: AsyncCallback\<Array\<ProcessRunningInfor
|AsyncCallback
\<
Array
\<
[
ProcessRunningInformation
](
js-apis-inner-application-processRunningInformation.md
)
>> | 以回调方式返回接口运行结果及有关运行进程的信息,可进行错误处理或其他自定义处理。 |
**示例:**
```
ts
appManager
.
getProcessRunningInformation
((
err
,
data
)
=>
{
if
(
err
.
code
!=
0
)
{
if
(
err
.
code
!=
=
0
)
{
console
.
log
(
"
getProcessRunningInformation faile, err:
"
+
JSON
.
stringify
(
err
));
}
else
{
console
.
log
(
"
The process running information is:
"
+
JSON
.
stringify
(
data
));
...
...
@@ -248,30 +248,30 @@ on(type: "applicationState", observer: ApplicationStateObserver): number;
| number | 已注册观测器的数字代码,可用于off接口取消注册观测器。|
**示例:**
```
js
var
applicationStateObserver
=
{
let
applicationStateObserver
=
{
onForegroundApplicationChanged
(
appStateData
)
{
console
.
log
(
'
------------ onForegroundApplicationChanged -----------
'
+
JSON
.
stringify
(
appStateData
)
);
console
.
log
(
`[appManager] onForegroundApplicationChanged:
${
JSON
.
stringify
(
appStateData
)}
`
);
},
onAbilityStateChanged
(
abilityStateData
)
{
console
.
log
(
'
------------ onAbilityStateChanged -----------
'
+
JSON
.
stringify
(
abilityStateData
)
);
console
.
log
(
`[appManager] onAbilityStateChanged:
${
JSON
.
stringify
(
abilityStateData
)}
`
);
},
onProcessCreated
(
processData
)
{
console
.
log
(
'
------------ onProcessCreated -----------
'
+
JSON
.
stringify
(
processData
)
);
console
.
log
(
`[appManager] onProcessCreated:
${
JSON
.
stringify
(
processData
)}
`
);
},
onProcessDied
(
processData
)
{
console
.
log
(
'
------------ onProcessDied -----------
'
+
JSON
.
stringify
(
processData
)
);
console
.
log
(
`[appManager] onProcessDied:
${
JSON
.
stringify
(
processData
)}
`
);
},
onProcessStateChanged
(
processData
)
{
console
.
log
(
'
------------ onProcessStateChanged -----------
'
+
JSON
.
stringify
(
processData
)
);
console
.
log
(
`[appManager] onProcessStateChanged:
${
JSON
.
stringify
(
processData
)}
`
);
}
}
try
{
const
observerCode
=
appManager
.
on
(
applicationStateObserver
);
console
.
log
(
'
-------- observerCode: ---------
'
+
observerCode
);
const
observerCode
=
appManager
.
on
(
'
applicationState
'
,
applicationStateObserver
);
console
.
log
(
`[appManager] observerCode:
${
observerCode
}
`
);
}
catch
(
paramError
)
{
console
.
log
(
'
error:
'
+
paramError
.
code
+
'
,
'
+
paramError
.
message
);
console
.
log
(
`[appManager] error:
${
paramError
.
code
}
,
${
paramError
.
message
}
`
);
}
```
...
...
@@ -293,7 +293,7 @@ on(type: "applicationState", observer: ApplicationStateObserver, bundleNameList:
| -------- | -------- | -------- | -------- |
| type | string | 是 | 调用接口类型,固定填"applicationState"字符串。 |
| observer |
[
ApplicationStateObserver
](
./js-apis-inner-application-applicationStateObserver.md
)
| 是 | 应用状态观测器,用于观测应用的生命周期变化。 |
| bundleNameList |
Array
<string>
| 是 | 表示需要注册监听的bundleName数组。最大值128。 |
| bundleNameList |
`Array<string>`
| 是 | 表示需要注册监听的bundleName数组。最大值128。 |
**返回值:**
...
...
@@ -302,33 +302,33 @@ on(type: "applicationState", observer: ApplicationStateObserver, bundleNameList:
| number | 已注册观测器的数字代码,可用于off接口注销观测器。|
**示例:**
```
js
var
applicationStateObserver
=
{
let
applicationStateObserver
=
{
onForegroundApplicationChanged
(
appStateData
)
{
console
.
log
(
'
------------ onForegroundApplicationChanged -----------
'
+
JSON
.
stringify
(
appStateData
)
);
console
.
log
(
`[appManager] onForegroundApplicationChanged:
${
JSON
.
stringify
(
appStateData
)}
`
);
},
onAbilityStateChanged
(
abilityStateData
)
{
console
.
log
(
'
------------ onAbilityStateChanged -----------
'
+
JSON
.
stringify
(
abilityStateData
)
);
console
.
log
(
`[appManager] onAbilityStateChanged:
${
JSON
.
stringify
(
abilityStateData
)}
`
);
},
onProcessCreated
(
processData
)
{
console
.
log
(
'
------------ onProcessCreated -----------
'
+
JSON
.
stringify
(
processData
)
);
console
.
log
(
`[appManager] onProcessCreated:
${
JSON
.
stringify
(
processData
)}
`
);
},
onProcessDied
(
processData
)
{
console
.
log
(
'
------------ onProcessDied -----------
'
+
JSON
.
stringify
(
processData
)
);
console
.
log
(
`[appManager] onProcessDied:
${
JSON
.
stringify
(
processData
)}
`
);
},
onProcessStateChanged
(
processData
)
{
console
.
log
(
'
------------ onProcessStateChanged -----------
'
+
JSON
.
stringify
(
processData
)
);
console
.
log
(
`[appManager] onProcessStateChanged:
${
JSON
.
stringify
(
processData
)}
`
);
}
}
var
bundleNameList
=
[
'
bundleName1
'
,
'
bundleName2
'
];
let
bundleNameList
=
[
'
bundleName1
'
,
'
bundleName2
'
];
try
{
const
observerCode
=
appManager
.
on
(
"
applicationState
"
,
applicationStateObserver
,
bundleNameList
);
console
.
log
(
'
-------- observerCode: ---------
'
,
observerCode
);
console
.
log
(
`[appManager] observerCode:
${
observerCode
}
`
);
}
catch
(
paramError
)
{
console
.
log
(
'
error:
'
+
paramError
.
code
+
'
,
'
+
paramError
.
message
);
console
.
log
(
`[appManager] error:
${
paramError
.
code
}
,
${
paramError
.
message
}
`
);
}
```
```
## appManager.off
...
...
@@ -351,12 +351,12 @@ off(type: "applicationState", observerId: number, callback: AsyncCallback\<void
| callback | AsyncCallback
\<
void> | 是 | 以回调方式返回接口运行结果,可进行错误处理或其他自定义处理。 |
**示例:**
```
ts
var
observerId = 100;
let
observerId
=
100
;
function
unregisterApplicationStateObserverCallback
(
err
)
{
if (err.code != 0) {
if
(
err
.
code
!=
=
0
)
{
console
.
log
(
"
unregisterApplicationStateObserverCallback faile, err:
"
+
JSON
.
stringify
(
err
));
}
else
{
console
.
log
(
"
unregisterApplicationStateObserverCallback success.
"
);
...
...
@@ -395,9 +395,9 @@ off(type: "applicationState", observerId: number): Promise\<void>;
| Promise
\<
void> | 以Promise方式返回接口运行结果,可进行错误处理或其他自定义处理。 |
**示例:**
```
ts
var
observerId = 100;
let
observerId
=
100
;
try
{
appManager
.
off
(
observerId
).
then
((
data
)
=>
{
...
...
@@ -429,10 +429,10 @@ getForegroundApplications(callback: AsyncCallback\<Array\<AppStateData>>): void;
| callback | AsyncCallback
\<
Array
\<
[
AppStateData
](
js-apis-inner-application-appStateData.md
)
>> | 是 | 以回调方式返回接口运行结果及应用状态数据数组,可进行错误处理或其他自定义处理。 |
**示例:**
```
ts
function
getForegroundApplicationsCallback
(
err
,
data
)
{
if (err.code != 0) {
if
(
err
.
code
!=
=
0
)
{
console
.
log
(
"
getForegroundApplicationsCallback fail, err:
"
+
JSON
.
stringify
(
err
));
}
else
{
console
.
log
(
"
getForegroundApplicationsCallback success, data:
"
+
JSON
.
stringify
(
data
));
...
...
@@ -464,10 +464,10 @@ getForegroundApplications(callback: AsyncCallback\<Array\<AppStateData>>): void;
| callback | AsyncCallback
\<
Array
\<
[
AppStateData
](
js-apis-inner-application-appStateData.md
)
>> | 是 | 以Promise方式返回接口运行结果及应用状态数据数组,可进行错误处理或其他自定义处理。 |
**示例:**
```
ts
function
getForegroundApplicationsCallback
(
err
,
data
)
{
if (err.code != 0) {
if
(
err
.
code
!=
=
0
)
{
console
.
log
(
"
getForegroundApplicationsCallback fail, err:
"
+
JSON
.
stringify
(
err
));
}
else
{
console
.
log
(
"
getForegroundApplicationsCallback success, data:
"
+
JSON
.
stringify
(
data
));
...
...
@@ -499,7 +499,7 @@ getForegroundApplications(): Promise\<Array\<AppStateData>>;
| Promise
\<
Array
\<
[
AppStateData
](
js-apis-inner-application-appStateData.md
)
>> | 返回前台进程应用程序的数组。 |
**示例:**
```
ts
appManager
.
getForegroundApplications
().
then
((
data
)
=>
{
console
.
log
(
"
getForegroundApplications success, data:
"
+
JSON
.
stringify
(
data
));
...
...
@@ -530,8 +530,8 @@ killProcessWithAccount(bundleName: string, accountId: number): Promise\<void\>
**示例:**
```
ts
var
bundleName = 'bundleName';
var
accountId = 0;
let
bundleName
=
'
bundleName
'
;
let
accountId
=
0
;
try
{
appManager
.
killProcessWithAccount
(
bundleName
,
accountId
).
then
(()
=>
{
console
.
log
(
"
killProcessWithAccount success
"
);
...
...
@@ -570,7 +570,7 @@ killProcessWithAccount(bundleName: string, accountId: number, callback: AsyncCal
var
bundleName
=
'
bundleName
'
;
var
accountId
=
0
;
function
killProcessWithAccountCallback
(
err
,
data
)
{
if (err.code != 0) {
if
(
err
.
code
!=
=
0
)
{
console
.
log
(
"
killProcessWithAccountCallback fail, err:
"
+
JSON
.
stringify
(
err
));
}
else
{
console
.
log
(
"
killProcessWithAccountCallback success.
"
);
...
...
@@ -599,11 +599,11 @@ killProcessesByBundleName(bundleName: string, callback: AsyncCallback\<void>);
| callback | AsyncCallback
\<
void> | 是 | 以回调方式返回接口运行结果,可进行错误处理或其他自定义处理。 |
**示例:**
```
ts
var
bundleName
=
'
bundleName
'
;
function
killProcessesByBundleNameCallback
(
err
,
data
)
{
if (err.code != 0) {
if
(
err
.
code
!=
=
0
)
{
console
.
log
(
"
killProcessesByBundleNameCallback fail, err:
"
+
JSON
.
stringify
(
err
));
}
else
{
console
.
log
(
"
killProcessesByBundleNameCallback success.
"
);
...
...
@@ -641,9 +641,9 @@ killProcessesByBundleName(bundleName: string): Promise\<void>;
| Promise
\<
void> | 返回执行结果。 |
**示例:**
```
ts
var
bundleName = 'bundleName';
let
bundleName
=
'
bundleName
'
;
try
{
appManager
.
killProcessesByBundleName
(
bundleName
).
then
((
data
)
=>
{
console
.
log
(
"
killProcessesByBundleName success.
"
);
...
...
@@ -675,9 +675,9 @@ clearUpApplicationData(bundleName: string, callback: AsyncCallback\<void>);
| callback | AsyncCallback
\<
void> | 是 | 以回调方式返回接口运行结果,可进行错误处理或其他自定义处理。 |
**示例:**
```
ts
var
bundleName = 'bundleName';
let
bundleName
=
'
bundleName
'
;
function
clearUpApplicationDataCallback
(
err
,
data
)
{
if
(
err
)
{
console
.
log
(
"
clearUpApplicationDataCallback fail, err:
"
+
JSON
.
stringify
(
err
));
...
...
@@ -717,9 +717,9 @@ clearUpApplicationData(bundleName: string): Promise\<void>;
| Promise
\<
void> | 以Promise方式返回接口运行结果,可进行错误处理或其他自定义处理。 |
**示例:**
```
ts
var
bundleName = 'bundleName';
let
bundleName
=
'
bundleName
'
;
try
{
appManager
.
clearUpApplicationData
(
bundleName
).
then
((
data
)
=>
{
console
.
log
(
"
clearUpApplicationData success.
"
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录