Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenHarmony
Docs
提交
9914c7a2
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看板
体验新版 GitCode,发现更多精彩内容 >>
提交
9914c7a2
编写于
12月 23, 2022
作者:
D
donglin
浏览文件
操作
浏览文件
下载
差异文件
Merge branch 'master' of gitee.com:donglin9/docs
Change-Id: I85da248207663d0c6f2a10118aeee12953f2ef48
上级
473bc686
e2765fed
变更
6
显示空白变更内容
内联
并排
Showing
6 changed file
with
340 addition
and
184 deletion
+340
-184
zh-cn/application-dev/reference/apis/js-apis-app-ability-abilityConstant.md
...dev/reference/apis/js-apis-app-ability-abilityConstant.md
+104
-6
zh-cn/application-dev/reference/apis/js-apis-app-ability-abilityDelegatorRegistry.md
...ence/apis/js-apis-app-ability-abilityDelegatorRegistry.md
+16
-6
zh-cn/application-dev/reference/apis/js-apis-app-ability-abilityLifecycleCallback.md
...ence/apis/js-apis-app-ability-abilityLifecycleCallback.md
+28
-22
zh-cn/application-dev/reference/apis/js-apis-app-ability-abilityManager.md
...-dev/reference/apis/js-apis-app-ability-abilityManager.md
+68
-52
zh-cn/application-dev/reference/apis/js-apis-app-ability-abilityStage.md
...on-dev/reference/apis/js-apis-app-ability-abilityStage.md
+3
-3
zh-cn/application-dev/reference/apis/js-apis-app-ability-appManager.md
...tion-dev/reference/apis/js-apis-app-ability-appManager.md
+121
-95
未找到文件。
zh-cn/application-dev/reference/apis/js-apis-app-ability-abilityConstant.md
浏览文件 @
9914c7a2
...
...
@@ -24,7 +24,7 @@ import AbilityConstant from '@ohos.app.ability.AbilityConstant';
## AbilityConstant.LaunchReason
初次启动原因,该类型为枚举,可配合
[
Ability
](
js-apis-app-ability-uiAbility.md
)
的
[
onCreate(want, launchParam)
](
js-apis-app-ability-uiAbility.md#uiabilityoncreate
)
方法根据launchParam.launchReason的不同类型执行相应操作。
Ability
初次启动原因,该类型为枚举,可配合
[
Ability
](
js-apis-app-ability-uiAbility.md
)
的
[
onCreate(want, launchParam)
](
js-apis-app-ability-uiAbility.md#uiabilityoncreate
)
方法根据launchParam.launchReason的不同类型执行相应操作。
**系统能力**
:以下各项对应的系统能力均为SystemCapability.Ability.AbilityRuntime.Core
...
...
@@ -36,10 +36,23 @@ import AbilityConstant from '@ohos.app.ability.AbilityConstant';
| CONTINUATION | 3 | 跨端设备迁移启动ability。 |
| APP_RECOVERY | 4 | 设置应用恢复后,应用故障时自动恢复启动ability。 |
**示例:**
```
ts
import
UIAbility
form
'
@ohos.app.ability.UIAbility
'
;
class
MyAbility
extends
UIAbility
{
onCreate
(
want
,
launchParam
)
{
if
(
launcherParam
.
launchReason
==
AbilityConstant
.
LaunchReason
.
START_ABILITY
)
{
console
.
log
(
"
The ability has been started by the way of startAbility.
"
);
}
}
}
```
## AbilityConstant.LastExitReason
上次退出原因,该类型为枚举,可配合
[
Ability
](
js-apis-app-ability-uiAbility.md
)
的
[
onCreate(want, launchParam)
](
js-apis-app-ability-uiAbility.md#uiabilityoncreate
)
方法根据launchParam.lastExitReason的不同类型执行相应操作。
Ability
上次退出原因,该类型为枚举,可配合
[
Ability
](
js-apis-app-ability-uiAbility.md
)
的
[
onCreate(want, launchParam)
](
js-apis-app-ability-uiAbility.md#uiabilityoncreate
)
方法根据launchParam.lastExitReason的不同类型执行相应操作。
**系统能力**
:以下各项对应的系统能力均为SystemCapability.Ability.AbilityRuntime.Core
...
...
@@ -49,10 +62,23 @@ import AbilityConstant from '@ohos.app.ability.AbilityConstant';
| ABILITY_NOT_RESPONDING | 1 | ability未响应。 |
| NORMAL | 2 | 正常退出。 |
**示例:**
```
ts
import
UIAbility
form
'
@ohos.app.ability.UIAbility
'
;
class
MyAbility
extends
UIAbility
{
onCreate
(
want
,
launchParam
)
{
if
(
launcherParam
.
lastExitReason
==
AbilityConstant
.
LastExitReason
.
ABILITY_NOT_RESPONDING
)
{
console
.
log
(
"
The ability has exit last because the ability was not responding.
"
);
}
}
}
```
## AbilityConstant.OnContinueResult
迁移结果,该类型为枚举,可配合
[
Ability
](
js-apis-app-ability-uiAbility.md
)
的
[
onContinue(wantParam)
](
js-apis-app-ability-uiAbility.md#uiabilityoncontinue
)
方法进完成相应的返回。
Ability
迁移结果,该类型为枚举,可配合
[
Ability
](
js-apis-app-ability-uiAbility.md
)
的
[
onContinue(wantParam)
](
js-apis-app-ability-uiAbility.md#uiabilityoncontinue
)
方法进完成相应的返回。
**系统能力**
:以下各项对应的系统能力均为SystemCapability.Ability.AbilityRuntime.Core
...
...
@@ -62,6 +88,18 @@ import AbilityConstant from '@ohos.app.ability.AbilityConstant';
| REJECT | 1 | 拒绝。 |
| MISMATCH | 2 | 不匹配。|
**示例:**
```
ts
import
UIAbility
form
'
@ohos.app.ability.UIAbility
'
;
class
MyAbility
extends
UIAbility
{
onContinue
(
wantParam
)
{
return
AbilityConstant
.
OnConinueResult
.
AGREE
;
}
}
```
## AbilityConstant.WindowMode
启动Ability时的窗口模式,该类型为枚举,可配合startAbility使用指定启动Ability的窗口模式。
...
...
@@ -76,6 +114,25 @@ import AbilityConstant from '@ohos.app.ability.AbilityConstant';
| WINDOW_MODE_SPLIT_SECONDARY | 101 | 分屏多窗口次要模式。 |
| WINDOW_MODE_FLOATING | 102 | 自由悬浮形式窗口模式。 |
**示例:**
```
ts
let
want
=
{
bundleName
:
"
com.test.example
"
,
abilityName
:
"
MainAbility
"
};
let
option
=
{
windowMode
:
AbilityConstant
.
WindowMode
.
WINDOW_MODE_FULLSCREEN
};
// 确保从上下文获取到context
this
.
context
.
startAbility
(
want
,
option
).
then
(()
=
{
console
.
log
(
"
Succeed to start ability.
"
);
}).
catch
((
error
)
=>
{
console
.
log
(
"
Failed to start ability with error:
"
+
JSON
.
stringify
(
error
));
});
```
## AbilityConstant.MemoryLevel
内存级别,该类型为枚举,可配合
[
Ability
](
js-apis-app-ability-ability.md
)
的
[
onMemoryLevel(level)
](
js-apis-app-ability-ability.md#abilityonmemorylevel
)
方法根据level执行不同内存级别的相应操作。
...
...
@@ -88,6 +145,20 @@ import AbilityConstant from '@ohos.app.ability.AbilityConstant';
| MEMORY_LEVEL_LOW | 1 | 内存占用低。 |
| MEMORY_LEVEL_CRITICAL | 2 | 内存占用高。 |
**示例:**
```
ts
import
UIAbility
form
'
@ohos.app.ability.UIAbility
'
;
class
MyAbility
extends
UIAbility
{
onMemoryLevel
(
level
)
{
if
(
level
==
AbilityConstant
.
MemoryLevel
.
MEMORY_LEVEL_CRITICAL
)
{
console
.
log
(
"
The memory of device is critical, please release some memory.
"
);
}
}
}
```
## AbilityConstant.OnSaveResult
保存应用数据的结果,该类型为枚举,可配合
[
Ability
](
js-apis-app-ability-uiAbility.md
)
的
[
onSaveState(reason, wantParam)
](
js-apis-app-ability-uiAbility.md#uiabilityonsavestate
)
方法完成相应的返回。
...
...
@@ -103,6 +174,18 @@ import AbilityConstant from '@ohos.app.ability.AbilityConstant';
| RECOVERY_REJECT | 4 | 拒绝恢复保存状态。|
| ALL_REJECT | 5 | 总是拒绝保存状态。|
**示例:**
```
ts
import
UIAbility
form
'
@ohos.app.ability.UIAbility
'
;
class
MyAbility
extends
UIAbility
{
onSaveState
(
reason
,
wantParam
)
{
return
AbilityConstant
.
OnSaveResult
.
ALL_AGREE
;
}
}
```
## AbilityConstant.StateType
保存应用数据场景原因,该类型为枚举,可配合
[
Ability
](
js-apis-app-ability-uiAbility.md
)
的
[
onSaveState(reason, wantParam)
](
js-apis-app-ability-uiAbility.md#uiabilityonsavestate
)
方法根据reason的不同类型执行相应操作。
...
...
@@ -113,3 +196,18 @@ import AbilityConstant from '@ohos.app.ability.AbilityConstant';
| ----------------------------- | ---- | ------------------------------------------------------------ |
| CONTINUATION | 0 | 迁移保存状态。 |
| APP_RECOVERY | 1 | 应用恢复保存状态。 |
**示例:**
```
ts
import
UIAbility
form
'
@ohos.app.ability.UIAbility
'
;
class
MyAbility
extends
UIAbility
{
onSaveState
(
reason
,
wantParam
)
{
if
(
reason
==
AbilityConstant
.
StateType
.
CONTINUATION
)
{
console
.
log
(
"
Save the ability data when the ability continuation.
"
);
}
return
AbilityConstant
.
OnSaveResult
.
ALL_AGREE
;
}
}
```
\ No newline at end of file
zh-cn/application-dev/reference/apis/js-apis-app-ability-abilityDelegatorRegistry.md
浏览文件 @
9914c7a2
# @ohos.app.ability.abilityDelegatorRegistry (AbilityDelegatorRegistry)
AbilityDelegatorRegistry
模块提供用于存储已注册的
[
AbilityDelegator
](
js-apis-inner-application-abilityDelegator.md
)
和
[
AbilityDelegatorArgs
](
js-apis-inner-application-abilityDelegatorArgs.md
)
对象的全局寄存器的能力,包括获取应用程序的
[
AbilityDelegator
](
js-apis-inner-application-abilityDelegator.md
)
对象、获取单元测试参数
[
AbilityDelegatorArgs
](
js-apis-inner-application-abilityDelegatorArgs.md
)
对象
。
AbilityDelegatorRegistry
是
[
测试框架
](
../../ability-deprecated/ability-delegator.md
)
模块,该模块用于获取
[
AbilityDelegator
](
js-apis-inner-application-abilityDelegator.md
)
和
[
AbilityDelegatorArgs
](
js-apis-inner-application-abilityDelegatorArgs.md
)
对象,其中
[
AbilityDelegator
](
js-apis-inner-application-abilityDelegator.md
)
对象提供添加用于监视指定ability的生命周期状态更改的AbilityMonitor对象的能力,
[
AbilityDelegatorArgs
](
js-apis-inner-application-abilityDelegatorArgs.md
)
对象提供获取当前测试参数的能力
。
> **说明:**
>
> 本模块首批接口从API version 9开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。
> 本模块接口仅可在测试框架中使用。
## 导入模块
```
ts
import
AbilityDelegatorRegistry
from
'
@ohos.app.ability.abilityDelegatorRegistry
'
import
AbilityDelegatorRegistry
from
'
@ohos.app.ability.abilityDelegatorRegistry
'
;
```
## AbilityLifecycleState
...
...
@@ -20,7 +21,7 @@ Ability生命周期状态,该类型为枚举,可配合[AbilityDelegator](js-
| 名称 | 值 | 说明 |
| ------------- | ---- | --------------------------- |
| UNINITIALIZED | 0 | 表示
无效状态。
|
| UNINITIALIZED | 0 | 表示
Ability处于无效状态。
|
| CREATE | 1 | 表示Ability处于已创建状态。 |
| FOREGROUND | 2 | 表示Ability处于前台状态。 |
| BACKGROUND | 3 | 表示Ability处于后台状态。 |
...
...
@@ -30,7 +31,7 @@ Ability生命周期状态,该类型为枚举,可配合[AbilityDelegator](js-
getAbilityDelegator():
[
AbilityDelegator
](
js-apis-inner-application-abilityDelegator.md
)
获取应用程序的
[
AbilityDelegator
](
js-apis-inner-application-abilityDelegator.md
)
对象。
获取应用程序的
[
AbilityDelegator
](
js-apis-inner-application-abilityDelegator.md
)
对象
,该对象能够使用调度测试框架的相关功能
。
**系统能力:**
SystemCapability.Ability.AbilityRuntime.Core
...
...
@@ -43,6 +44,8 @@ getAbilityDelegator(): [AbilityDelegator](js-apis-inner-application-abilityDeleg
**示例:**
```
ts
import
AbilityDelegatorRegistry
from
'
@ohos.app.ability.abilityDelegatorRegistry
'
;
var
abilityDelegator
;
abilityDelegator
=
AbilityDelegatorRegistry
.
getAbilityDelegator
();
...
...
@@ -50,8 +53,12 @@ let want = {
bundleName
:
"
com.ohos.example
"
,
abilityName
:
"
MainAbility
"
}
abilityDelegator
.
startAbility
(
want
,
(
err
,
data
)
=>
{
console
.
log
(
"
startAbility callback err:
"
+
JSON
.
stringify
(
err
)
+
"
data:
"
+
JSON
.
stringify
(
data
));
abilityDelegator
.
startAbility
(
want
,
(
err
)
=>
{
if
(
err
.
code
!=
0
)
{
console
.
log
(
"
Success start ability.
"
);
}
else
{
console
.
log
(
"
Failed start ability, error:
"
+
JSON
.
stringify
(
err
));
}
})
```
...
...
@@ -72,8 +79,11 @@ getArguments(): [AbilityDelegatorArgs](js-apis-inner-application-abilityDelegato
**示例:**
```
ts
import
AbilityDelegatorRegistry
from
'
@ohos.app.ability.abilityDelegatorRegistry
'
;
var
args
=
AbilityDelegatorRegistry
.
getArguments
();
console
.
info
(
"
getArguments bundleName:
"
+
args
.
bundleName
);
console
.
info
(
"
getArguments parameters:
"
+
JSON
.
stringify
(
args
.
parameters
));
console
.
info
(
"
getArguments testCaseNames:
"
+
args
.
testCaseNames
);
console
.
info
(
"
getArguments testRunnerClassName:
"
+
args
.
testRunnerClassName
);
```
zh-cn/application-dev/reference/apis/js-apis-app-ability-abilityLifecycleCallback.md
浏览文件 @
9914c7a2
# @ohos.app.ability.abilityLifecycleCallback (AbilityLifecycleCallback)
AbilityLifecycleCallback模块提供应用上下文
[
ApplicationContext
](
js-apis-inner-application-applicationContext.md
)
的生命周期
监听方法的回调类
的能力,包括
[
onAbilityCreate
](
#abilitylifecyclecallbackonabilitycreate
)
、
[
onWindowStageCreate
](
#abilitylifecyclecallbackonwindowstagecreate
)
、
[
onWindowStageActive
](
#abilitylifecyclecallbackonwindowstageactive
)
、
[
onWindowStageInactive
](
#abilitylifecyclecallbackonwindowstageinactive
)
、
[
onWindowStageDestroy
](
#abilitylifecyclecallbackonwindowstagedestroy
)
、
[
onAbilityDestroy
](
#abilitylifecyclecallbackonabilitydestroy
)
、
[
onAbilityForeground
](
#abilitylifecyclecallbackonabilityforeground
)
、
[
onAbilityBackground
](
#abilitylifecyclecallbackonabilitybackground
)
、
[
onAbilityContinue
](
#abilitylifecyclecallbackonabilitycontinue
)
方法。
AbilityLifecycleCallback模块提供应用上下文
[
ApplicationContext
](
js-apis-inner-application-applicationContext.md
)
的生命周期
发生变化时触发相应回调
的能力,包括
[
onAbilityCreate
](
#abilitylifecyclecallbackonabilitycreate
)
、
[
onWindowStageCreate
](
#abilitylifecyclecallbackonwindowstagecreate
)
、
[
onWindowStageActive
](
#abilitylifecyclecallbackonwindowstageactive
)
、
[
onWindowStageInactive
](
#abilitylifecyclecallbackonwindowstageinactive
)
、
[
onWindowStageDestroy
](
#abilitylifecyclecallbackonwindowstagedestroy
)
、
[
onAbilityDestroy
](
#abilitylifecyclecallbackonabilitydestroy
)
、
[
onAbilityForeground
](
#abilitylifecyclecallbackonabilityforeground
)
、
[
onAbilityBackground
](
#abilitylifecyclecallbackonabilitybackground
)
、
[
onAbilityContinue
](
#abilitylifecyclecallbackonabilitycontinue
)
方法。
> **说明:**
>
...
...
@@ -161,52 +161,58 @@ import AbilityLifecycleCallback from "@ohos.app.ability.AbilityLifecycleCallback
// 声明ability生命周期回调
let
abilityLifecycleCallback
=
{
onAbilityCreate
(
ability
){
console
.
log
(
"
AbilityLifecycleCallback onAbilityCreate
ability:
"
+
JSON
.
stringify
(
ability
)
);
console
.
log
(
"
AbilityLifecycleCallback onAbilityCreate
.
"
);
},
onWindowStageCreate
(
ability
,
windowStage
){
console
.
log
(
"
AbilityLifecycleCallback onWindowStageCreate ability:
"
+
JSON
.
stringify
(
ability
));
console
.
log
(
"
AbilityLifecycleCallback onWindowStageCreate windowStage:
"
+
JSON
.
stringify
(
windowStage
));
console
.
log
(
"
AbilityLifecycleCallback onWindowStageCreate.
"
);
},
onWindowStageActive
(
ability
,
windowStage
){
console
.
log
(
"
AbilityLifecycleCallback onWindowStageActive ability:
"
+
JSON
.
stringify
(
ability
));
console
.
log
(
"
AbilityLifecycleCallback onWindowStageActive windowStage:
"
+
JSON
.
stringify
(
windowStage
));
console
.
log
(
"
AbilityLifecycleCallback onWindowStageActive.
"
);
},
onWindowStageInactive
(
ability
,
windowStage
){
console
.
log
(
"
AbilityLifecycleCallback onWindowStageInactive ability:
"
+
JSON
.
stringify
(
ability
));
console
.
log
(
"
AbilityLifecycleCallback onWindowStageInactive windowStage:
"
+
JSON
.
stringify
(
windowStage
));
console
.
log
(
"
AbilityLifecycleCallback onWindowStageInactive.
"
);
},
onWindowStageDestroy
(
ability
,
windowStage
){
console
.
log
(
"
AbilityLifecycleCallback onWindowStageDestroy ability:
"
+
JSON
.
stringify
(
ability
));
console
.
log
(
"
AbilityLifecycleCallback onWindowStageDestroy windowStage:
"
+
JSON
.
stringify
(
windowStage
));
console
.
log
(
"
AbilityLifecycleCallback onWindowStageDestroy.
"
);
},
onAbilityDestroy
(
ability
){
console
.
log
(
"
AbilityLifecycleCallback onAbilityDestroy
ability:
"
+
JSON
.
stringify
(
ability
)
);
console
.
log
(
"
AbilityLifecycleCallback onAbilityDestroy
.
"
);
},
onAbilityForeground
(
ability
){
console
.
log
(
"
AbilityLifecycleCallback onAbilityForeground
ability:
"
+
JSON
.
stringify
(
ability
)
);
console
.
log
(
"
AbilityLifecycleCallback onAbilityForeground
.
"
);
},
onAbilityBackground
(
ability
){
console
.
log
(
"
AbilityLifecycleCallback onAbilityBackground
ability:
"
+
JSON
.
stringify
(
ability
)
);
console
.
log
(
"
AbilityLifecycleCallback onAbilityBackground
.
"
);
},
onAbilityContinue
(
ability
){
console
.
log
(
"
AbilityLifecycleCallback onAbilityContinue
ability:
"
+
JSON
.
stringify
(
ability
)
);
console
.
log
(
"
AbilityLifecycleCallback onAbilityContinue
.
"
);
}
}
var
lifecycleId
;
export
default
class
MyAbility
extends
UIAbility
{
onCreate
()
{
console
.
log
(
"
MyAbility onCreate
"
)
// 1.通过context属性获取applicationContext
let
applicationContext
=
this
.
context
.
getApplicationContext
();
// 2.通过applicationContext注册监听应用内生命周期
globalThis
.
lifecycleid
=
applicationContext
.
on
(
"
abilityLifecycle
"
,
abilityLifecycleCallback
);
console
.
log
(
"
registerAbilityLifecycleCallback number:
"
+
JSON
.
stringify
(
lifecycleid
));
try
{
lifecycleId
=
applicationContext
.
on
(
"
abilityLifecycle
"
,
abilityLifecycleCallback
);
console
.
log
(
"
registerAbilityLifecycleCallback number:
"
+
JSON
.
stringify
(
lifecycleId
));
}
catch
(
paramError
)
{
console
.
log
(
"
error:
"
+
paramError
.
code
+
"
,
"
+
paramError
.
message
);
}
},
onDestroy
()
{
let
applicationContext
=
this
.
context
.
getApplicationContext
();
// 3.通过applicationContext注销监听应用内生命周期
applicationContext
.
off
(
"
abilityLifecycle
"
,
globalThis
.
lifecycleid
,
(
error
,
data
)
=>
{
console
.
log
(
"
unregisterAbilityLifecycleCallback success, err:
"
+
JSON
.
stringify
(
error
));
applicationContext
.
off
(
"
abilityLifecycle
"
,
lifecycleId
,
(
error
)
=>
{
if
(
error
.
code
!=
0
)
{
console
.
log
(
"
unregisterAbilityLifecycleCallback failed, error:
"
+
JSON
.
stringify
(
error
));
}
else
{
console
.
log
(
"
unregisterAbilityLifecycleCallback success.
"
);
}
});
}
}
...
...
zh-cn/application-dev/reference/apis/js-apis-app-ability-abilityManager.md
浏览文件 @
9914c7a2
# @ohos.app.ability.abilityManager (AbilityManager)
AbilityManager模块提供
对Ability相关信息和状态信息进行获取、新增、修改等
能力。
AbilityManager模块提供
获取、新增、修改Ability相关信息和状态信息进行的
能力。
> **说明:**
>
...
...
@@ -19,7 +19,7 @@ Ability的状态,该类型为枚举,可配合[AbilityRunningInfo](js-apis-in
**系统能力**
:以下各项对应的系统能力均为SystemCapability.Ability.AbilityRuntime.Core
**系统API**
: 此
接口为系统接口
,三方应用不支持调用。
**系统API**
: 此
枚举类型为系统接口内部定义
,三方应用不支持调用。
| 名称 | 值 | 说明 |
| -------- | -------- | -------- |
...
...
@@ -33,7 +33,7 @@ Ability的状态,该类型为枚举,可配合[AbilityRunningInfo](js-apis-in
updateConfiguration(config:
[
Configuration
](
js-apis-app-ability-configuration.md
)
, callback: AsyncCallback
\<
void>): void
通过
修改配置
来更新配置(callback形式)。
通过
传入修改的配置项
来更新配置(callback形式)。
**需要权限**
: ohos.permission.UPDATE_CONFIGURATION
...
...
@@ -44,13 +44,13 @@ updateConfiguration(config: [Configuration](js-apis-app-ability-configuration.md
| 参数名 | 类型 | 必填 | 说明 |
| --------- | ---------------------------------------- | ---- | -------------- |
| config |
[
Configuration
](
js-apis-app-ability-configuration.md
)
| 是 | 新的配置项,仅需配置需要更新的项。 |
| callback | AsyncCallback
\<
void> | 是 |
被指定的回调方法
。 |
| callback | AsyncCallback
\<
void> | 是 |
以回调方式返回接口运行结果,可进行错误处理或其他自定义处理
。 |
**示例**
:
```
ts
var
config
=
{
language
:
'
chinese
'
,
language
:
'
Zh-Hans
'
,
colorMode
:
COLOR_MODE_LIGHT
,
direction
:
DIRECTION_VERTICAL
,
screenDensity
:
SCREEN_DENSITY_SDPI
,
...
...
@@ -59,8 +59,12 @@ var config = {
}
try
{
abilityManager
.
updateConfiguration
(
config
,
()
=>
{
console
.
log
(
'
------------ updateConfiguration -----------
'
);
abilityManager
.
updateConfiguration
(
config
,
(
err
)
=>
{
if
(
err
.
code
!=
0
)
{
console
.
log
(
"
updateConfiguration fail, err:
"
+
JSON
.
stringify
(
err
));
}
else
{
console
.
log
(
"
updateConfiguration success.
"
);
}
})
}
catch
(
paramError
)
{
console
.
log
(
'
error.code:
'
+
JSON
.
stringify
(
paramError
.
code
)
+
...
...
@@ -88,13 +92,13 @@ updateConfiguration(config: [Configuration](js-apis-app-ability-configuration.md
| 类型 | 说明 |
| ---------------------------------------- | ------- |
| Promise
\<
void> |
返回执行结果
。 |
| Promise
\<
void> |
以Promise方式返回接口运行结果息,可进行错误处理或其他自定义处理
。 |
**示例**
:
```
ts
var
config
=
{
language
:
'
chinese
'
,
language
:
'
Zh-Hans
'
,
colorMode
:
COLOR_MODE_LIGHT
,
direction
:
DIRECTION_VERTICAL
,
screenDensity
:
SCREEN_DENSITY_SDPI
,
...
...
@@ -104,9 +108,9 @@ var config = {
try
{
abilityManager
.
updateConfiguration
(
config
).
then
(()
=>
{
console
.
log
(
'
updateConfiguration success
'
);
console
.
log
(
'
updateConfiguration success.
'
);
}).
catch
((
err
)
=>
{
console
.
log
(
'
updateConfiguration fail
'
);
console
.
log
(
'
updateConfiguration fail, err:
'
+
JSON
.
stringify
(
err
)
);
})
}
catch
(
paramError
)
{
console
.
log
(
'
error.code:
'
+
JSON
.
stringify
(
paramError
.
code
)
+
...
...
@@ -128,14 +132,18 @@ getAbilityRunningInfos(callback: AsyncCallback\<Array\<[AbilityRunningInfo](js-a
| 参数名 | 类型 | 必填 | 说明 |
| --------- | ---------------------------------------- | ---- | -------------- |
| callback | AsyncCallback
\<
Array
\<
[
AbilityRunningInfo
](
js-apis-inner-application-abilityRunningInfo.md
)
>> | 是 |
被指定的回调方法,返回运行中的ability信息
。 |
| callback | AsyncCallback
\<
Array
\<
[
AbilityRunningInfo
](
js-apis-inner-application-abilityRunningInfo.md
)
>> | 是 |
以回调方式返回接口运行结果及运行中的ability信息,可进行错误处理或其他自定义处理
。 |
**示例**
:
```
ts
try
{
abilityManager
.
getAbilityRunningInfos
((
err
,
data
)
=>
{
console
.
log
(
"
getAbilityRunningInfos err:
"
+
err
+
"
data:
"
+
JSON
.
stringify
(
data
));
if
(
err
.
code
!=
0
)
{
console
.
log
(
"
getAbilityRunningInfos fail, error:
"
+
JSON
.
stringify
(
err
));
}
else
{
console
.
log
(
"
getAbilityRunningInfos success, data:
"
+
JSON
.
stringify
(
data
));
}
});
}
catch
(
paramError
)
{
console
.
log
(
'
error.code:
'
+
JSON
.
stringify
(
paramError
.
code
)
+
...
...
@@ -157,16 +165,16 @@ getAbilityRunningInfos(): Promise\<Array\<[AbilityRunningInfo](js-apis-inner-app
| 类型 | 说明 |
| ---------------------------------------- | ------- |
| Promise
\<
Array
\<
[
AbilityRunningInfo
](
js-apis-inner-application-abilityRunningInfo.md
)
>> |
返回运行中的ability信息
。 |
| Promise
\<
Array
\<
[
AbilityRunningInfo
](
js-apis-inner-application-abilityRunningInfo.md
)
>> |
以Promise方式返回接口运行结果及运行中的ability信息,可进行错误处理或其他自定义处理
。 |
**示例**
:
```
ts
try
{
abilityManager
.
getAbilityRunningInfos
().
then
((
data
)
=>
{
console
.
log
(
"
getAbilityRunningInfos
data:
"
+
JSON
.
stringify
(
data
))
console
.
log
(
"
getAbilityRunningInfos success,
data:
"
+
JSON
.
stringify
(
data
))
}).
catch
((
err
)
=>
{
console
.
log
(
"
getAbilityRunningInfos err:
"
+
err
)
console
.
log
(
"
getAbilityRunningInfos fail, err:
"
+
JSON
.
stringify
(
err
));
});
}
catch
(
paramError
)
{
console
.
log
(
'
error.code:
'
+
JSON
.
stringify
(
paramError
.
code
)
+
...
...
@@ -189,7 +197,7 @@ getExtensionRunningInfos(upperLimit: number, callback: AsyncCallback\<Array\<[Ex
| 参数名 | 类型 | 必填 | 说明 |
| --------- | ---------------------------------------- | ---- | -------------- |
| upperLimit | number | 是 | 获取消息数量的最大限制。 |
| callback | AsyncCallback
\<
Array
\<
[
ExtensionRunningInfo
](
js-apis-inner-application-extensionRunningInfo.md
)
>> | 是 |
被指定的回调方法,返回运行中的extension信息
。 |
| callback | AsyncCallback
\<
Array
\<
[
ExtensionRunningInfo
](
js-apis-inner-application-extensionRunningInfo.md
)
>> | 是 |
以回调方式返回接口运行结果及运行中的extension信息,可进行错误处理或其他自定义处理
。 |
**示例**
:
...
...
@@ -198,7 +206,11 @@ var upperLimit = 0;
try
{
abilityManager
.
getExtensionRunningInfos
(
upperLimit
,
(
err
,
data
)
=>
{
console
.
log
(
"
getExtensionRunningInfos err:
"
+
err
+
"
data:
"
+
JSON
.
stringify
(
data
));
if
(
err
.
code
!=
0
)
{
console
.
log
(
"
getExtensionRunningInfos fail, err:
"
+
JSON
.
stringify
(
err
));
}
else
{
console
.
log
(
"
getExtensionRunningInfos success, data:
"
+
JSON
.
stringify
(
data
));
}
});
}
catch
(
paramError
)
{
console
.
log
(
'
error.code:
'
+
JSON
.
stringify
(
paramError
.
code
)
+
...
...
@@ -226,7 +238,7 @@ getExtensionRunningInfos(upperLimit: number): Promise\<Array\<[ExtensionRunningI
| 类型 | 说明 |
| ---------------------------------------- | ------- |
| Promise
\<
Array
\<
[
ExtensionRunningInfo
](
js-apis-inner-application-extensionRunningInfo.md
)
>> |
返回运行中的extension信息
。 |
| Promise
\<
Array
\<
[
ExtensionRunningInfo
](
js-apis-inner-application-extensionRunningInfo.md
)
>> |
以Promise方式返回接口运行结果及运行中的extension信息,可进行错误处理或其他自定义处理
。 |
**示例**
:
...
...
@@ -235,9 +247,9 @@ var upperLimit = 0;
try
{
abilityManager
.
getExtensionRunningInfos
(
upperLimit
).
then
((
data
)
=>
{
console
.
log
(
"
getExtensionRunningInfos
data:
"
+
JSON
.
stringify
(
data
));
console
.
log
(
"
getExtensionRunningInfos success,
data:
"
+
JSON
.
stringify
(
data
));
}).
catch
((
err
)
=>
{
console
.
log
(
"
getExtensionRunningInfos err:
"
+
err
);
console
.
log
(
"
getExtensionRunningInfos fail, err:
"
+
JSON
.
stringify
(
err
)
);
})
}
catch
(
paramError
)
{
console
.
log
(
'
error.code:
'
+
JSON
.
stringify
(
paramError
.
code
)
+
...
...
@@ -257,13 +269,17 @@ getTopAbility(callback: AsyncCallback\<[ElementName](js-apis-bundleManager-eleme
| 参数名 | 类型 | 必填 | 说明 |
| --------- | ---------------------------------------- | ---- | -------------- |
| callback | AsyncCallback
\<
[
ElementName
](
js-apis-bundleManager-elementName.md
)
> | 是 |
被指定的回调方法,返回目前获焦窗口的应用名
。 |
| callback | AsyncCallback
\<
[
ElementName
](
js-apis-bundleManager-elementName.md
)
> | 是 |
以回调方式返回接口运行结果及应用名,可进行错误处理或其他自定义处理
。 |
**示例**
:
```
ts
abilityManager
.
getTopAbility
((
err
,
data
)
=>
{
console
.
log
(
"
getTopAbility err:
"
+
err
+
"
data:
"
+
JSON
.
stringify
(
data
));
if
(
err
.
code
!=
0
)
{
console
.
log
(
"
getTopAbility fail, err:
"
+
JSON
.
stringify
(
err
));
}
else
{
console
.
log
(
"
getTopAbility success, data:
"
+
JSON
.
stringify
(
data
));
}
});
```
...
...
@@ -279,14 +295,14 @@ getTopAbility(): Promise\<[ElementName](js-apis-bundleManager-elementName.md)>;
| 类型 | 说明 |
| ---------------------------------------- | ------- |
| Promise
\<
[
ElementName
](
js-apis-bundleManager-elementName.md
)
>|
返回目前获焦窗口的应用名
。 |
| Promise
\<
[
ElementName
](
js-apis-bundleManager-elementName.md
)
>|
以Promise方式返回接口运行结果及应用名,可进行错误处理或其他自定义处理
。 |
**示例**
:
```
ts
abilityManager
.
getTopAbility
().
then
((
data
)
=>
{
console
.
log
(
"
getTopAbility data:
"
+
JSON
.
stringify
(
data
));
console
.
log
(
"
getTopAbility
success,
data:
"
+
JSON
.
stringify
(
data
));
}).
catch
((
err
)
=>
{
console
.
log
(
"
getTopAbility
err:
"
+
err
);
console
.
log
(
"
getTopAbility
fail, err:
"
+
JSON
.
stringify
(
err
)
);
})
```
\ No newline at end of file
zh-cn/application-dev/reference/apis/js-apis-app-ability-abilityStage.md
浏览文件 @
9914c7a2
...
...
@@ -28,7 +28,7 @@ onCreate(): void
```
ts
class
MyAbilityStage
extends
AbilityStage
{
onCreate
()
{
console
.
log
(
"
MyAbilityStage.onCreate is called
"
)
console
.
log
(
"
MyAbilityStage.onCreate is called
"
)
;
}
}
```
...
...
@@ -118,10 +118,10 @@ class MyAbilityStage extends AbilityStage {
context:
[
AbilityStageContext
](
js-apis-inner-application-abilityStageContext.md
)
;
指示
有关上下文的配置信息
。
指示
AbilityStage的上下文,
。
**系统能力**
:SystemCapability.Ability.AbilityRuntime.Core
| 属性名 | 类型 | 说明 |
| ----------- | --------------------------- | ------------------------------------------------------------ |
| context |
[
AbilityStageContext
](
js-apis-inner-application-abilityStageContext.md
)
| 在
启动能力阶段进行初始化时回调
。 |
| context |
[
AbilityStageContext
](
js-apis-inner-application-abilityStageContext.md
)
| 在
Ability启动阶段进行初始化时回调,获取到该Ability的context值
。 |
zh-cn/application-dev/reference/apis/js-apis-app-ability-appManager.md
浏览文件 @
9914c7a2
...
...
@@ -20,18 +20,21 @@ static isRunningInStabilityTest(callback: AsyncCallback<boolean>): void
**系统能力**
:SystemCapability.Ability.AbilityRuntime.Core
**
参数
:**
**
返回值
:**
|
参数名 | 类型 | 必填
| 说明 |
| -------- | -------- |
-------- | -------- |
|
callback | AsyncCallback
<
boolean
>
| 是 | 返回当前是否处于稳定性测试场景
。true: 处于稳定性测试场景,false:处于非稳定性测试场景。 |
|
类型
| 说明 |
| -------- | -------- |
|
AsyncCallback
<
boolean
>
|以回调方式返回接口运行结果及当前是否处于稳定性测试场景,可进行错误处理或其他自定义处理
。true: 处于稳定性测试场景,false:处于非稳定性测试场景。 |
**示例:**
```
ts
appManager
.
isRunningInStabilityTest
((
err
,
flag
)
=>
{
console
.
log
(
'
error:
'
+
JSON
.
stringify
(
err
));
console
.
log
(
'
The result of isRunningInStabilityTest is:
'
+
JSON
.
stringify
(
flag
));
if
(
err
.
code
!=
0
)
{
conseole
.
log
(
"
isRunningInStabilityTest faile, err:
"
+
JSON
.
stringify
(
err
));
}
else
{
console
.
log
(
"
The result of isRunningInStabilityTest is:
"
+
JSON
.
stringify
(
flag
));
}
})
```
...
...
@@ -48,15 +51,15 @@ static isRunningInStabilityTest(): Promise<boolean>
| 类型 | 说明 |
| -------- | -------- |
| Promise
<
boolean
>
|
返回当前是否处于稳定性测试场景
。true: 处于稳定性测试场景,false:处于非稳定性测试场景。 |
| Promise
<
boolean
>
|
以Promise方式返回接口运行结果及当前是否处于稳定性测试场景,可进行错误处理或其他自定义处理
。true: 处于稳定性测试场景,false:处于非稳定性测试场景。 |
**示例:**
```
ts
appManager
.
isRunningInStabilityTest
().
then
((
flag
)
=>
{
console
.
log
(
'
The result of isRunningInStabilityTest is:
'
+
JSON
.
stringify
(
flag
));
console
.
log
(
"
The result of isRunningInStabilityTest is:
"
+
JSON
.
stringify
(
flag
));
}).
catch
((
error
)
=>
{
console
.
log
(
'
error:
'
+
JSON
.
stringify
(
error
));
console
.
log
(
"
error:
"
+
JSON
.
stringify
(
error
));
});
```
...
...
@@ -73,15 +76,15 @@ isRamConstrainedDevice(): Promise\<boolean>;
| 类型 | 说明 |
| -------- | -------- |
| Promise
<
boolean
>
|
是否为ram受限设备
。true:当前设备为ram受限设备,false:当前设备为非ram受限设备。 |
| Promise
<
boolean
>
|
以Promise方式返回接口运行结果及当前设备是否为ram受限设备,可进行错误处理或其他自定义处理
。true:当前设备为ram受限设备,false:当前设备为非ram受限设备。 |
**示例:**
```
ts
appManager
.
isRamConstrainedDevice
().
then
((
data
)
=>
{
console
.
log
(
'
The result of isRamConstrainedDevice is:
'
+
JSON
.
stringify
(
data
));
console
.
log
(
"
The result of isRamConstrainedDevice is:
"
+
JSON
.
stringify
(
data
));
}).
catch
((
error
)
=>
{
console
.
log
(
'
error:
'
+
JSON
.
stringify
(
error
));
console
.
log
(
"
error:
"
+
JSON
.
stringify
(
error
));
});
```
...
...
@@ -93,18 +96,21 @@ isRamConstrainedDevice(callback: AsyncCallback\<boolean>): void;
**系统能力**
:SystemCapability.Ability.AbilityRuntime.Core
**
参数
:**
**
返回值
:**
|
参数名 | 类型 | 必填
| 说明 |
| -------- | -------- |
-------- | -------- |
|
callback | AsyncCallback
<
boolean
>
| 是 | 返回当前是否是ram受限设备
。true:当前设备为ram受限设备,false:当前设备为非ram受限设备。 |
|
类型
| 说明 |
| -------- | -------- |
|
AsyncCallback
<
boolean
>
|以回调方式返回接口运行结果及当前设备是否为ram受限设备,可进行错误处理或其他自定义处理
。true:当前设备为ram受限设备,false:当前设备为非ram受限设备。 |
**示例:**
```
ts
appManager
.
isRamConstrainedDevice
((
err
,
data
)
=>
{
console
.
log
(
'
error:
'
+
JSON
.
stringify
(
err
));
console
.
log
(
'
The result of isRamConstrainedDevice is:
'
+
JSON
.
stringify
(
data
));
if
(
err
.
code
!=
0
)
{
console
.
log
(
"
isRamConstrainedDevice faile, err:
"
+
JSON
.
stringify
(
err
));
}
else
{
console
.
log
(
"
The result of isRamConstrainedDevice is:
"
+
JSON
.
stringify
(
data
));
}
})
```
...
...
@@ -120,15 +126,15 @@ getAppMemorySize(): Promise\<number>;
| 类型 | 说明 |
| -------- | -------- |
| Promise
<
number
>
|
应用程序内存大小
。 |
| Promise
<
number
>
|
以Promise方式返回接口运行结果及应用程序内存大小,可进行错误处理或其他自定义处理
。 |
**示例:**
```
ts
appManager
.
getAppMemorySize
().
then
((
data
)
=>
{
console
.
log
(
'
The size of app memory is:
'
+
JSON
.
stringify
(
data
));
console
.
log
(
"
The size of app memory is:
"
+
JSON
.
stringify
(
data
));
}).
catch
((
error
)
=>
{
console
.
log
(
'
error:
'
+
JSON
.
stringify
(
error
));
console
.
log
(
"
error:
"
+
JSON
.
stringify
(
error
));
});
```
...
...
@@ -140,18 +146,21 @@ getAppMemorySize(callback: AsyncCallback\<number>): void;
**系统能力**
:SystemCapability.Ability.AbilityRuntime.Core
**
参数
:**
**
返回值
:**
|
参数名 | 类型 | 必填
| 说明 |
| -------- | -------- |
-------- | -------- |
|
callback | AsyncCallback
<
number
>
| 是 | 应用程序内存大小
。 |
|
类型
| 说明 |
| -------- | -------- |
|
AsyncCallback
<
number
>
|以回调方式返回接口运行结果及应用程序内存大小,可进行错误处理或其他自定义处理
。 |
**示例:**
```
ts
appManager
.
getAppMemorySize
((
err
,
data
)
=>
{
console
.
log
(
'
error:
'
+
JSON
.
stringify
(
err
));
console
.
log
(
'
The size of app memory is:
'
+
JSON
.
stringify
(
data
));
if
(
err
.
code
!=
0
)
{
console
.
log
(
"
getAppMemorySize faile, err:
"
+
JSON
.
stringify
(
err
));
}
else
{
console
.
log
(
"
The size of app memory is:
"
+
JSON
.
stringify
(
data
));
}
})
```
...
...
@@ -171,15 +180,15 @@ getProcessRunningInformation(): Promise\<Array\<[ProcessRunningInformation](js-a
| 类型 | 说明 |
| -------- | -------- |
| Promise
\<
Array
\<
[
ProcessRunningInformation
](
js-apis-inner-application-processRunningInformation.md
)
>> |
获取有关运行进程的信息
。 |
| 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
));
console
.
log
(
"
The process running information is:
"
+
JSON
.
stringify
(
data
));
}).
catch
((
error
)
=>
{
console
.
log
(
'
error:
'
+
JSON
.
stringify
(
error
));
console
.
log
(
"
error:
"
+
JSON
.
stringify
(
error
));
});
```
...
...
@@ -195,18 +204,21 @@ getProcessRunningInformation(callback: AsyncCallback\<Array\<[ProcessRunningInfo
**系统API**
: 此接口为系统接口,三方应用不支持调用。
**
参数
:**
**
返回值
:**
|
参数名 | 类型 | 必填
| 说明 |
| -------- | -------- |
-------- | -------- |
|
callback | AsyncCallback
\<
Array
\<
[
ProcessRunningInformation
](
js-apis-inner-application-processRunningInformation.md
)
>> | 是 | 获取有关运行进程的信息
。 |
|
类型
| 说明 |
| -------- | -------- |
|
AsyncCallback
\<
Array
\<
[
ProcessRunningInformation
](
js-apis-inner-application-processRunningInformation.md
)
>> | 以回调方式返回接口运行结果及有关运行进程的信息,可进行错误处理或其他自定义处理
。 |
**示例:**
```
ts
appManager
.
getProcessRunningInformation
((
err
,
data
)
=>
{
console
.
log
(
'
error :
'
+
JSON
.
stringify
(
err
));
console
.
log
(
'
The process running information is:
'
+
JSON
.
stringify
(
data
));
if
(
err
.
code
!=
0
)
{
console
.
log
(
"
getProcessRunningInformation faile, err:
"
+
JSON
.
stringify
(
err
));
}
else
{
console
.
log
(
"
The process running information is:
"
+
JSON
.
stringify
(
data
));
}
})
```
...
...
@@ -214,7 +226,7 @@ appManager.getProcessRunningInformation((err, data) => {
on(type: "applicationState", observer:
[
ApplicationStateObserver
](
./js-apis-inner-application-applicationStateObserver.md
)
): number;
注册全部应用程序状态观测器。
注册全部应用程序
的
状态观测器。
**需要权限**
:ohos.permission.RUNNING_STATE_OBSERVER
...
...
@@ -227,31 +239,37 @@ on(type: "applicationState", observer: [ApplicationStateObserver](./js-apis-inne
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| type | string | 是 | 调用接口类型,固定填"applicationState"字符串。 |
| observer |
[
ApplicationStateObserver
](
./js-apis-inner-application-applicationStateObserver.md
)
| 是 | 返回观测器的数字代码ID。 |
| observer |
[
ApplicationStateObserver
](
./js-apis-inner-application-applicationStateObserver.md
)
| 是 | 应用状态观测器,用于观测应用的生命周期变化。 |
**返回值:**
| 类型 | 说明 |
| --- | --- |
| number | 已注册观测器的数字代码,可用于off接口取消注册观测器。|
**示例:**
```
js
var
applicationStateObserver
=
{
onForegroundApplicationChanged
(
appStateData
)
{
console
.
log
(
'
------------ onForegroundApplicationChanged -----------
'
,
appStateData
);
console
.
log
(
'
------------ onForegroundApplicationChanged -----------
'
+
JSON
.
stringify
(
appStateData
)
);
},
onAbilityStateChanged
(
abilityStateData
)
{
console
.
log
(
'
------------ onAbilityStateChanged -----------
'
,
abilityStateData
);
console
.
log
(
'
------------ onAbilityStateChanged -----------
'
+
JSON
.
stringify
(
abilityStateData
)
);
},
onProcessCreated
(
processData
)
{
console
.
log
(
'
------------ onProcessCreated -----------
'
,
processData
);
console
.
log
(
'
------------ onProcessCreated -----------
'
+
JSON
.
stringify
(
processData
)
);
},
onProcessDied
(
processData
)
{
console
.
log
(
'
------------ onProcessDied -----------
'
,
processData
);
console
.
log
(
'
------------ onProcessDied -----------
'
+
JSON
.
stringify
(
processData
)
);
},
onProcessStateChanged
(
processData
)
{
console
.
log
(
'
------------ onProcessStateChanged -----------
'
,
processData
);
console
.
log
(
'
------------ onProcessStateChanged -----------
'
+
JSON
.
stringify
(
processData
)
);
}
}
try
{
const
observerCode
=
appManager
.
on
(
applicationStateObserver
);
console
.
log
(
'
-------- observerCode: ---------
'
,
observerCode
);
console
.
log
(
'
-------- observerCode: ---------
'
+
observerCode
);
}
catch
(
paramError
)
{
console
.
log
(
'
error:
'
+
paramError
.
code
+
'
,
'
+
paramError
.
message
);
}
...
...
@@ -261,7 +279,7 @@ try {
on(type: "applicationState", observer:
[
ApplicationStateObserver
](
./js-apis-inner-application-applicationStateObserver.md
)
, bundleNameList: Array
\<
string>): number;
注册指定应用程序状态观测器。
注册指定应用程序
的
状态观测器。
**需要权限**
:ohos.permission.RUNNING_STATE_OBSERVER
...
...
@@ -274,38 +292,44 @@ on(type: "applicationState", observer: [ApplicationStateObserver](./js-apis-inne
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| type | string | 是 | 调用接口类型,固定填"applicationState"字符串。 |
| observer |
[
ApplicationStateObserver
](
./js-apis-inner-application-applicationStateObserver.md
)
| 是 |
返回观测器的数字代码ID
。 |
| observer |
[
ApplicationStateObserver
](
./js-apis-inner-application-applicationStateObserver.md
)
| 是 |
应用状态观测器,用于观测应用的生命周期变化
。 |
| bundleNameList | Array
<string>
| 是 | 表示需要注册监听的bundleName数组。最大值128。 |
**返回值:**
| 类型 | 说明 |
| --- | --- |
| number | 已注册观测器的数字代码,可用于off接口注销观测器。|
**示例:**
```
js
var
applicationStateObserver
=
{
```
js
var
applicationStateObserver
=
{
onForegroundApplicationChanged
(
appStateData
)
{
console
.
log
(
'
------------ onForegroundApplicationChanged -----------
'
,
appStateData
);
console
.
log
(
'
------------ onForegroundApplicationChanged -----------
'
+
JSON
.
stringify
(
appStateData
)
);
},
onAbilityStateChanged
(
abilityStateData
)
{
console
.
log
(
'
------------ onAbilityStateChanged -----------
'
,
abilityStateData
);
console
.
log
(
'
------------ onAbilityStateChanged -----------
'
+
JSON
.
stringify
(
abilityStateData
)
);
},
onProcessCreated
(
processData
)
{
console
.
log
(
'
------------ onProcessCreated -----------
'
,
processData
);
console
.
log
(
'
------------ onProcessCreated -----------
'
+
JSON
.
stringify
(
processData
)
);
},
onProcessDied
(
processData
)
{
console
.
log
(
'
------------ onProcessDied -----------
'
,
processData
);
console
.
log
(
'
------------ onProcessDied -----------
'
+
JSON
.
stringify
(
processData
)
);
},
onProcessStateChanged
(
processData
)
{
console
.
log
(
'
------------ onProcessStateChanged -----------
'
,
processData
);
console
.
log
(
'
------------ onProcessStateChanged -----------
'
+
JSON
.
stringify
(
processData
)
);
}
}
var
bundleNameList
=
[
'
bundleName1
'
,
'
bundleName2
'
];
try
{
}
var
bundleNameList
=
[
'
bundleName1
'
,
'
bundleName2
'
];
try
{
const
observerCode
=
appManager
.
on
(
"
applicationState
"
,
applicationStateObserver
,
bundleNameList
);
console
.
log
(
'
-------- observerCode: ---------
'
,
observerCode
);
}
catch
(
paramError
)
{
}
catch
(
paramError
)
{
console
.
log
(
'
error:
'
+
paramError
.
code
+
'
,
'
+
paramError
.
message
);
}
}
```
## appManager.off
off(type: "applicationState", observerId: number, callback: AsyncCallback\<void>): void;
...
...
@@ -324,7 +348,7 @@ off(type: "applicationState", observerId: number, callback: AsyncCallback\<void
| -------- | -------- | -------- | -------- |
| type | string | 是 | 调用接口类型,固定填"applicationState"字符串。 |
| observerId | number | 是 | 表示观测器的编号代码。 |
| callback | AsyncCallback
\<
void> | 是 |
表示指定的回调方法
。 |
| callback | AsyncCallback\<void> | 是 |
以回调方式返回接口运行结果,可进行错误处理或其他自定义处理
。 |
**示例:**
...
...
@@ -332,8 +356,10 @@ off(type: "applicationState", observerId: number, callback: AsyncCallback\<void
var observerId = 100;
function unregisterApplicationStateObserverCallback(err) {
if
(
err
)
{
console
.
log
(
'
------------ unregisterApplicationStateObserverCallback ------------
'
,
err
);
if (err.code != 0) {
console.log("unregisterApplicationStateObserverCallback faile, err: " + JSON.stringify(err));
} else {
console.log("unregisterApplicationStateObserverCallback success.");
}
}
try {
...
...
@@ -366,7 +392,7 @@ off(type: "applicationState", observerId: number): Promise\<void>;
| 类型 | 说明 |
| -------- | -------- |
| Promise
\<
void> |
返回执行结果
。 |
| Promise\<void> |
以Promise方式返回接口运行结果,可进行错误处理或其他自定义处理
。 |
**示例:**
...
...
@@ -375,9 +401,9 @@ var observerId = 100;
try {
appManager.off(observerId).then((data) => {
console
.
log
(
'
----------- unregisterApplicationStateObserver success ----------
'
,
data
);
console.log(
"unregisterApplicationStateObserver success, data: " + JSON.stringify(data)
);
}).catch((err) => {
console
.
log
(
'
----------- unregisterApplicationStateObserver fail ----------
'
,
err
);
console.log(
"unregisterApplicationStateObserver faile, err: " + JSON.stringify(err)
);
})
} catch (paramError) {
console.log('error: ' + paramError.code + ', ' + paramError.message);
...
...
@@ -388,7 +414,7 @@ try {
getForegroundApplications(callback: AsyncCallback\<Array\<[AppStateData](js-apis-inner-application-appStateData.md)>>): void;
获取前台
进程
的应用程序。
获取前台的应用程序。
**需要权限**:ohos.permission.GET_RUNNING_INFO
...
...
@@ -400,16 +426,16 @@ getForegroundApplications(callback: AsyncCallback\<Array\<[AppStateData](js-apis
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| callback | AsyncCallback
\<
Array
\<
[
AppStateData
](
js-apis-inner-application-appStateData.md
)
>> | 是 |
表示应用的状态数据
。 |
| callback | AsyncCallback\<Array\<[AppStateData](js-apis-inner-application-appStateData.md)>> | 是 |
以回调方式返回接口运行结果及应用状态数据数组,可进行错误处理或其他自定义处理
。 |
**示例:**
```
ts
function getForegroundApplicationsCallback(err, data) {
if
(
err
)
{
console
.
log
(
'
--------- getForegroundApplicationsCallback fail ---------
'
,
err
.
code
+
'
:
'
+
err
.
message
);
if (err
.code != 0
) {
console.log(
"getForegroundApplicationsCallback fail, err: " + JSON.stringify(err)
);
} else {
console
.
log
(
'
--------- getForegroundApplicationsCallback success ---------
'
,
data
)
console.log(
"getForegroundApplicationsCallback success, data: " + JSON.stringify(data));
}
}
try {
...
...
@@ -435,16 +461,16 @@ getForegroundApplications(callback: AsyncCallback\<Array\<[AppStateData](js-apis
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| callback | AsyncCallback
\<
Array
\<
[
AppStateData
](
js-apis-inner-application-appStateData.md
)
>> | 是 |
表示应用的状态数据
。 |
| callback | AsyncCallback\<Array\<[AppStateData](js-apis-inner-application-appStateData.md)>> | 是 |
以Promise方式返回接口运行结果及应用状态数据数组,可进行错误处理或其他自定义处理
。 |
**示例:**
```
ts
function getForegroundApplicationsCallback(err, data) {
if
(
err
)
{
console
.
log
(
'
--------- getForegroundApplicationsCallback fail ---------
'
,
err
);
if (err
.code != 0
) {
console.log(
"getForegroundApplicationsCallback fail, err: " + JSON.stringify(err)
);
} else {
console
.
log
(
'
--------- getForegroundApplicationsCallback success ---------
'
,
data
)
console.log(
"getForegroundApplicationsCallback success, data: " + JSON.stringify(data));
}
}
try {
...
...
@@ -476,9 +502,9 @@ getForegroundApplications(): Promise\<Array\<[AppStateData](js-apis-inner-applic
```
ts
appManager.getForegroundApplications().then((data) => {
console
.
log
(
'
--------- getForegroundApplications success -------
'
,
data
);
console.log(
"getForegroundApplications success, data: " + JSON.stringify(data)
);
}).catch((err) => {
console
.
log
(
'
--------- getForegroundApplications fail -------
'
,
err
);
console.log(
"getForegroundApplications fail, err: " + JSON.stringify(err)
);
})
```
...
...
@@ -507,10 +533,10 @@ killProcessWithAccount(bundleName: string, accountId: number): Promise\<void\>
var bundleName = 'bundleName';
var accountId = 0;
try {
appManager
.
killProcessWithAccount
(
bundleName
,
accountId
).
then
((
data
)
=>
{
console
.
log
(
'
------------ killProcessWithAccount success ------------
'
,
data
);
appManager.killProcessWithAccount(bundleName, accountId).then(() => {
console.log(
"killProcessWithAccount success"
);
}).catch((err) => {
console
.
log
(
'
------------ killProcessWithAccount fail ------------
'
,
err
);
console.log(
"killProcessWithAccount fail, err: " + JSON.stringify(err)
);
})
} catch (paramError) {
console.log("error: " + paramError.code + ", " + paramError.message);
...
...
@@ -536,7 +562,7 @@ killProcessWithAccount(bundleName: string, accountId: number, callback: AsyncCal
| -------- | -------- | -------- | -------- |
| bundleName | string | 是 | 应用包名。 |
| accountId | number | 是 | 系统帐号的帐号ID,详情参考[getCreatedOsAccountsCount](js-apis-osAccount.md#getosaccountlocalidfromprocess)。 |
| callback | AsyncCallback
\<
void
\>
| 是 |
切断account进程的回调函数
。 |
| callback | AsyncCallback\<void\> | 是 |
以回调方式返回接口运行结果,可进行错误处理或其他自定义处理
。 |
**示例:**
...
...
@@ -544,10 +570,10 @@ killProcessWithAccount(bundleName: string, accountId: number, callback: AsyncCal
var bundleName = 'bundleName';
var accountId = 0;
function killProcessWithAccountCallback(err, data) {
if
(
err
)
{
console
.
log
(
'
------------- killProcessWithAccountCallback fail, err: --------------
'
,
err
);
if (err
.code != 0
) {
console.log(
"killProcessWithAccountCallback fail, err: " + JSON.stringify(err)
);
} else {
console
.
log
(
'
------------- killProcessWithAccountCallback success, data: --------------
'
,
data
);
console.log(
"killProcessWithAccountCallback success."
);
}
}
appManager.killProcessWithAccount(bundleName, accountId, killProcessWithAccountCallback);
...
...
@@ -570,17 +596,17 @@ killProcessesByBundleName(bundleName: string, callback: AsyncCallback\<void>);
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| bundleName | string | 是 | 表示包名。 |
| callback | AsyncCallback
\<
void> | 是 |
表示指定的回调方法
。 |
| callback | AsyncCallback\<void> | 是 |
以回调方式返回接口运行结果,可进行错误处理或其他自定义处理
。 |
**示例:**
```
ts
var bundleName = 'bundleName';
function killProcessesByBundleNameCallback(err, data) {
if
(
err
)
{
console
.
log
(
'
------------- killProcessesByBundleNameCallback fail, err: --------------
'
,
err
);
if (err
.code != 0
) {
console.log(
"killProcessesByBundleNameCallback fail, err: " + JSON.stringify(err)
);
} else {
console
.
log
(
'
------------- killProcessesByBundleNameCallback success, data: --------------
'
,
data
);
console.log(
"killProcessesByBundleNameCallback success."
);
}
}
try {
...
...
@@ -620,9 +646,9 @@ killProcessesByBundleName(bundleName: string): Promise\<void>;
var bundleName = 'bundleName';
try {
appManager.killProcessesByBundleName(bundleName).then((data) => {
console
.
log
(
'
------------ killProcessesByBundleName success ------------
'
,
data
);
console.log(
"killProcessesByBundleName success."
);
}).catch((err) => {
console
.
log
(
'
------------ killProcessesByBundleName fail ------------
'
,
err
);
console.log(
"killProcessesByBundleName fail, err: " + JSON.stringify(err)
);
})
} catch (paramError) {
console.log("error: " + paramError.code + ", " + paramError.message);
...
...
@@ -646,7 +672,7 @@ clearUpApplicationData(bundleName: string, callback: AsyncCallback\<void>);
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| bundleName | string | 是 | 表示包名。 |
| callback | AsyncCallback
\<
void> | 是 |
表示指定的回调方法
。 |
| callback | AsyncCallback\<void> | 是 |
以回调方式返回接口运行结果,可进行错误处理或其他自定义处理
。 |
**示例:**
...
...
@@ -654,9 +680,9 @@ clearUpApplicationData(bundleName: string, callback: AsyncCallback\<void>);
var bundleName = 'bundleName';
function clearUpApplicationDataCallback(err, data) {
if (err) {
console
.
log
(
'
------------- clearUpApplicationDataCallback fail, err: --------------
'
,
err
);
console.log(
"clearUpApplicationDataCallback fail, err: " + JSON.stringify(err)
);
} else {
console
.
log
(
'
------------- clearUpApplicationDataCallback success, data: --------------
'
,
data
);
console.log(
"clearUpApplicationDataCallback success."
);
}
}
try {
...
...
@@ -688,7 +714,7 @@ clearUpApplicationData(bundleName: string): Promise\<void>;
| 类型 | 说明 |
| -------- | -------- |
| Promise
\<
void> |
返回执行结果
。 |
| Promise\<void> |
以Promise方式返回接口运行结果,可进行错误处理或其他自定义处理
。 |
**示例:**
...
...
@@ -696,9 +722,9 @@ clearUpApplicationData(bundleName: string): Promise\<void>;
var bundleName = 'bundleName';
try {
appManager.clearUpApplicationData(bundleName).then((data) => {
console
.
log
(
'
------------ clearUpApplicationData success ------------
'
,
data
);
console.log(
"clearUpApplicationData success."
);
}).catch((err) => {
console
.
log
(
'
------------ clearUpApplicationData fail ------------
'
,
err
);
console.log(
"clearUpApplicationData fail, err: " + JSON.stringify(err)
);
})
} catch (paramError) {
console.log("error: " + paramError.code + ", " + paramError.message);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录