提交 9914c7a2 编写于 作者: D donglin

Merge branch 'master' of gitee.com:donglin9/docs

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