提交 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执行不同内存级别的相应操作。
...@@ -83,11 +140,25 @@ import AbilityConstant from '@ohos.app.ability.AbilityConstant'; ...@@ -83,11 +140,25 @@ import AbilityConstant from '@ohos.app.ability.AbilityConstant';
**系统能力**:以下各项对应的系统能力均为SystemCapability.Ability.AbilityRuntime.Core **系统能力**:以下各项对应的系统能力均为SystemCapability.Ability.AbilityRuntime.Core
| 名称 | 值 | 说明 | | 名称 | 值 | 说明 |
| --- | --- | --- | | --- | --- | --- |
| MEMORY_LEVEL_MODERATE | 0 | 内存占用适中。 | | MEMORY_LEVEL_MODERATE | 0 | 内存占用适中。 |
| 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,53 +161,59 @@ import AbilityLifecycleCallback from "@ohos.app.ability.AbilityLifecycleCallback ...@@ -161,53 +161,59 @@ 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.");
}
});
}
} }
``` ```
\ No newline at end of file
# @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,12 +59,16 @@ var config = { ...@@ -59,12 +59,16 @@ 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) +
' error.message: ' + JSON.stringify(paramError.message)); ' error.message: ' + JSON.stringify(paramError.message));
} }
``` ```
...@@ -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,
...@@ -103,14 +107,14 @@ var config = { ...@@ -103,14 +107,14 @@ 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) +
' error.message: ' + JSON.stringify(paramError.message)); ' error.message: ' + JSON.stringify(paramError.message));
} }
``` ```
...@@ -128,18 +132,22 @@ getAbilityRunningInfos(callback: AsyncCallback\<Array\<[AbilityRunningInfo](js-a ...@@ -128,18 +132,22 @@ 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) +
' error.message: ' + JSON.stringify(paramError.message)); ' error.message: ' + JSON.stringify(paramError.message));
} }
``` ```
...@@ -157,20 +165,20 @@ getAbilityRunningInfos(): Promise\<Array\<[AbilityRunningInfo](js-apis-inner-app ...@@ -157,20 +165,20 @@ 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) +
' error.message: ' + JSON.stringify(paramError.message)); ' error.message: ' + JSON.stringify(paramError.message));
} }
``` ```
...@@ -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信息,可进行错误处理或其他自定义处理。 |
**示例** **示例**
...@@ -197,12 +205,16 @@ getExtensionRunningInfos(upperLimit: number, callback: AsyncCallback\<Array\<[Ex ...@@ -197,12 +205,16 @@ getExtensionRunningInfos(upperLimit: number, callback: AsyncCallback\<Array\<[Ex
var upperLimit = 0; 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) +
' error.message: ' + JSON.stringify(paramError.message)); ' error.message: ' + JSON.stringify(paramError.message));
} }
``` ```
...@@ -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信息,可进行错误处理或其他自定义处理。 |
**示例** **示例**
...@@ -234,14 +246,14 @@ getExtensionRunningInfos(upperLimit: number): Promise\<Array\<[ExtensionRunningI ...@@ -234,14 +246,14 @@ getExtensionRunningInfos(upperLimit: number): Promise\<Array\<[ExtensionRunningI
var upperLimit = 0; 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) +
' error.message: ' + JSON.stringify(paramError.message)); ' error.message: ' + JSON.stringify(paramError.message));
} }
``` ```
...@@ -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值。 |
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册