diff --git a/en/application-dev/reference/apis/js-apis-app-ability-abilityConstant.md b/en/application-dev/reference/apis/js-apis-app-ability-abilityConstant.md index 766636a7c7d4cda38cb2b71395fd3f2575e2f784..ab791ee67694f8c2b7974d009c61ff4a548a2238 100644 --- a/en/application-dev/reference/apis/js-apis-app-ability-abilityConstant.md +++ b/en/application-dev/reference/apis/js-apis-app-ability-abilityConstant.md @@ -48,7 +48,7 @@ import UIAbility from '@ohos.app.ability.UIAbility'; class MyAbility extends UIAbility { onCreate(want, launchParam) { if (launchParam.launchReason === AbilityConstant.LaunchReason.START_ABILITY) { - console.log("The ability has been started by the way of startAbility."); + console.log('The ability has been started by the way of startAbility.'); } } } @@ -74,7 +74,7 @@ import UIAbility from '@ohos.app.ability.UIAbility'; class MyAbility extends UIAbility { onCreate(want, launchParam) { if (launchParam.lastExitReason === AbilityConstant.LastExitReason.ABILITY_NOT_RESPONDING) { - console.log("The ability has exit last because the ability was not responding."); + console.log('The ability has exit last because the ability was not responding.'); } } } @@ -110,20 +110,22 @@ Enumerates the window modes in which an ability can be displayed at startup. It **System capability**: SystemCapability.Ability.AbilityRuntime.Core +**System API**: This is a system API and cannot be called by third-party applications. + | Name | Value| Description | | --- | --- | --- | | WINDOW_MODE_UNDEFINED | 0 | Undefined window mode. | | WINDOW_MODE_FULLSCREEN | 1 | The ability is displayed in full screen. | -| WINDOW_MODE_SPLIT_PRIMARY | 100 | The ability is displayed in the primary window in split-screen mode. | -| WINDOW_MODE_SPLIT_SECONDARY | 101 | The ability is displayed in the secondary window in split-screen mode. | +| WINDOW_MODE_SPLIT_PRIMARY | 100 | The left screen in horizontal direction or the upper screen in vertical direction is the primary window. | +| WINDOW_MODE_SPLIT_SECONDARY | 101 | The right screen in horizontal direction or the lower screen in vertical direction is the secondary window. | | WINDOW_MODE_FLOATING | 102 | The ability is displayed in a floating window.| **Example** ```ts let want = { - bundleName: "com.example.myapplication", - abilityName: "EntryAbility" + bundleName: 'com.test.example', + abilityName: 'MainAbility' }; let option = { windowMode: AbilityConstant.WindowMode.WINDOW_MODE_FULLSCREEN @@ -131,9 +133,9 @@ let option = { // Ensure that the context is obtained. this.context.startAbility(want, option).then(()={ - console.log("Succeed to start ability."); + console.log('Succeed to start ability.'); }).catch((error)=>{ - console.log("Failed to start ability with error: " + JSON.stringify(error)); + console.log('Failed to start ability with error: ' + JSON.stringify(error)); }); ``` @@ -157,7 +159,7 @@ import UIAbility from '@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."); + console.log('The memory of device is critical, please release some memory.'); } } } @@ -209,7 +211,7 @@ import UIAbility from '@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."); + console.log('Save the ability data when the ability continuation.'); } return AbilityConstant.OnSaveResult.ALL_AGREE; } diff --git a/en/application-dev/reference/apis/js-apis-app-ability-abilityDelegatorRegistry.md b/en/application-dev/reference/apis/js-apis-app-ability-abilityDelegatorRegistry.md index 5cfa437047868a9183ae4bb4f41ff42eec47f5d7..3eb05e659aba4b2516dbeb86858fb07481f733db 100644 --- a/en/application-dev/reference/apis/js-apis-app-ability-abilityDelegatorRegistry.md +++ b/en/application-dev/reference/apis/js-apis-app-ability-abilityDelegatorRegistry.md @@ -49,14 +49,14 @@ import AbilityDelegatorRegistry from '@ohos.app.ability.abilityDelegatorRegistry let abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator(); let want = { - bundleName: "com.example.myapplication", - abilityName: "EntryAbility" + bundleName: 'com.ohos.example', + abilityName: 'MainAbility' }; abilityDelegator.startAbility(want, (err) => { if (err.code !== 0) { - console.log("Success start ability."); + console.log('Success start ability.'); } else { - console.log("Failed start ability, error: " + JSON.stringify(err)); + console.log('Failed start ability, error: ' + JSON.stringify(err)); } }) ``` @@ -81,8 +81,8 @@ Obtains an [AbilityDelegatorArgs](js-apis-inner-application-abilityDelegatorArgs import AbilityDelegatorRegistry from '@ohos.app.ability.abilityDelegatorRegistry'; let 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); +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); ``` diff --git a/en/application-dev/reference/apis/js-apis-app-ability-abilityLifecycleCallback.md b/en/application-dev/reference/apis/js-apis-app-ability-abilityLifecycleCallback.md index 84be19350707fee37328ff8040b2986588afd2f8..4d47822bfbcba1bb35258525973e4ebe211d72c6 100644 --- a/en/application-dev/reference/apis/js-apis-app-ability-abilityLifecycleCallback.md +++ b/en/application-dev/reference/apis/js-apis-app-ability-abilityLifecycleCallback.md @@ -11,7 +11,7 @@ The **AbilityLifecycleCallback** module defines the callbacks to receive lifecyc ## Modules to Import ```ts -import AbilityLifecycleCallback from "@ohos.app.ability.AbilityLifecycleCallback"; +import AbilityLifecycleCallback from '@ohos.app.ability.AbilityLifecycleCallback'; ``` @@ -25,15 +25,15 @@ Called when an ability is created. **Parameters** -| Name| Type| Mandatory| Description| -| -------- | -------- | -------- | -------- | -| ability | [UIAbility](js-apis-app-ability-uiAbility.md) | Yes| **Ability** object.| + | Name| Type| Mandatory| Description| + | -------- | -------- | -------- | -------- | + | ability | [UIAbility](js-apis-app-ability-uiAbility.md) | Yes| **Ability** object.| **Example** ```ts let abilityLifecycleCallback = { onAbilityCreate(ability){ - console.log("AbilityLifecycleCallback onAbilityCreate."); + console.log('AbilityLifecycleCallback onAbilityCreate.'); } }; ``` @@ -48,16 +48,16 @@ Called when the window stage of an ability is created. **Parameters** -| Name| Type| Mandatory| Description| -| -------- | -------- | -------- | -------- | -| ability | [UIAbility](js-apis-app-ability-uiAbility.md) | Yes| **Ability** object.| -| windowStage | [window.WindowStage](js-apis-window.md#windowstage9) | Yes| **WindowStage** object.| + | Name| Type| Mandatory| Description| + | -------- | -------- | -------- | -------- | + | ability | [UIAbility](js-apis-app-ability-uiAbility.md) | Yes| **Ability** object.| + | windowStage | [window.WindowStage](js-apis-window.md#windowstage9) | Yes| **WindowStage** object.| **Example** ```ts let abilityLifecycleCallback = { onWindowStageCreate(ability, windowStage){ - console.log("AbilityLifecycleCallback onWindowStageCreate."); + console.log('AbilityLifecycleCallback onWindowStageCreate.'); } }; ``` @@ -72,16 +72,16 @@ Called when the window stage of an ability gains focus. **Parameters** -| Name| Type| Mandatory| Description| -| -------- | -------- | -------- | -------- | -| ability | [UIAbility](js-apis-app-ability-uiAbility.md) | Yes| **Ability** object.| -| windowStage | [window.WindowStage](js-apis-window.md#windowstage9) | Yes| **WindowStage** object.| + | Name| Type| Mandatory| Description| + | -------- | -------- | -------- | -------- | + | ability | [UIAbility](js-apis-app-ability-uiAbility.md) | Yes| **Ability** object.| + | windowStage | [window.WindowStage](js-apis-window.md#windowstage9) | Yes| **WindowStage** object.| **Example** ```ts let abilityLifecycleCallback = { onWindowStageActive(ability, windowStage){ - console.log("AbilityLifecycleCallback onWindowStageActive."); + console.log('AbilityLifecycleCallback onWindowStageActive.'); } }; ``` @@ -96,16 +96,16 @@ Called when the window stage of an ability loses focus. **Parameters** -| Name| Type| Mandatory| Description| -| -------- | -------- | -------- | -------- | -| ability | [UIAbility](js-apis-app-ability-uiAbility.md) | Yes| **Ability** object.| -| windowStage | [window.WindowStage](js-apis-window.md#windowstage9) | Yes| **WindowStage** object.| + | Name| Type| Mandatory| Description| + | -------- | -------- | -------- | -------- | + | ability | [UIAbility](js-apis-app-ability-uiAbility.md) | Yes| **Ability** object.| + | windowStage | [window.WindowStage](js-apis-window.md#windowstage9) | Yes| **WindowStage** object.| **Example** ```ts let abilityLifecycleCallback = { onWindowStageInactive(ability, windowStage){ - console.log("AbilityLifecycleCallback onWindowStageInactive."); + console.log('AbilityLifecycleCallback onWindowStageInactive.'); } }; ``` @@ -120,16 +120,16 @@ Called when the window stage of an ability is destroyed. **Parameters** -| Name| Type| Mandatory| Description| -| -------- | -------- | -------- | -------- | -| ability | [UIAbility](js-apis-app-ability-uiAbility.md) | Yes| **Ability** object.| -| windowStage | [window.WindowStage](js-apis-window.md#windowstage9) | Yes| **WindowStage** object.| + | Name| Type| Mandatory| Description| + | -------- | -------- | -------- | -------- | + | ability | [UIAbility](js-apis-app-ability-uiAbility.md) | Yes| **Ability** object.| + | windowStage | [window.WindowStage](js-apis-window.md#windowstage9) | Yes| **WindowStage** object.| **Example** ```ts let abilityLifecycleCallback = { onWindowStageDestroy(ability, windowStage){ - console.log("AbilityLifecycleCallback onWindowStageDestroy."); + console.log('AbilityLifecycleCallback onWindowStageDestroy.'); } }; ``` @@ -144,15 +144,15 @@ Called when an ability is destroyed. **Parameters** -| Name| Type| Mandatory| Description| -| -------- | -------- | -------- | -------- | -| ability | [UIAbility](js-apis-app-ability-uiAbility.md) | Yes| **Ability** object.| + | Name| Type| Mandatory| Description| + | -------- | -------- | -------- | -------- | + | ability | [UIAbility](js-apis-app-ability-uiAbility.md) | Yes| **Ability** object.| **Example** ```ts let abilityLifecycleCallback = { onAbilityDestroy(ability){ - console.log("AbilityLifecycleCallback onAbilityDestroy."); + console.log('AbilityLifecycleCallback onAbilityDestroy.'); } }; ``` @@ -167,15 +167,15 @@ Called when an ability is switched from the background to the foreground. **Parameters** -| Name| Type| Mandatory| Description| -| -------- | -------- | -------- | -------- | -| ability | [UIAbility](js-apis-app-ability-uiAbility.md) | Yes| **Ability** object.| + | Name| Type| Mandatory| Description| + | -------- | -------- | -------- | -------- | + | ability | [UIAbility](js-apis-app-ability-uiAbility.md) | Yes| **Ability** object.| **Example** ```ts let abilityLifecycleCallback = { onAbilityForeground(ability){ - console.log("AbilityLifecycleCallback onAbilityForeground."); + console.log('AbilityLifecycleCallback onAbilityForeground.'); } }; ``` @@ -190,15 +190,15 @@ Called when an ability is switched from the foreground to the background. **Parameters** -| Name| Type| Mandatory| Description| -| -------- | -------- | -------- | -------- | -| ability | [UIAbility](js-apis-app-ability-uiAbility.md) | Yes| **Ability** object.| + | Name| Type| Mandatory| Description| + | -------- | -------- | -------- | -------- | + | ability | [UIAbility](js-apis-app-ability-uiAbility.md) | Yes| **Ability** object.| **Example** ```ts let abilityLifecycleCallback = { onAbilityBackground(ability){ - console.log("AbilityLifecycleCallback onAbilityBackground."); + console.log('AbilityLifecycleCallback onAbilityBackground.'); } }; ``` @@ -213,15 +213,15 @@ Called when an ability is continued on another device. **Parameters** -| Name| Type| Mandatory| Description| -| -------- | -------- | -------- | -------- | -| ability | [UIAbility](js-apis-app-ability-uiAbility.md) | Yes| **Ability** object.| + | Name| Type| Mandatory| Description| + | -------- | -------- | -------- | -------- | + | ability | [UIAbility](js-apis-app-ability-uiAbility.md) | Yes| **Ability** object.| **Example** ```ts let abilityLifecycleCallback = { onAbilityContinue(ability){ - console.log("AbilityLifecycleCallback onAbilityContinue."); + console.log('AbilityLifecycleCallback onAbilityContinue.'); } }; ``` @@ -232,52 +232,52 @@ let abilityLifecycleCallback = { MyFirstAbility.ts ```ts -import AbilityLifecycleCallback from "@ohos.app.ability.AbilityLifecycleCallback"; -import AbilityStage from "@ohos.app.ability.AbilityStage"; +import AbilityLifecycleCallback from '@ohos.app.ability.AbilityLifecycleCallback'; +import AbilityStage from '@ohos.app.ability.AbilityStage'; import UIAbility from '@ohos.app.ability.UIAbility'; // Declare the ability lifecycle callbacks. A listener can be registered in applicationContext only after all the callbacks are configured. let abilityLifecycleCallback = { onAbilityCreate(ability){ - console.log("AbilityLifecycleCallback onAbilityCreate."); + console.log('AbilityLifecycleCallback onAbilityCreate.'); }, onWindowStageCreate(ability, windowStage){ - console.log("AbilityLifecycleCallback onWindowStageCreate."); + console.log('AbilityLifecycleCallback onWindowStageCreate.'); }, onWindowStageActive(ability, windowStage){ - console.log("AbilityLifecycleCallback onWindowStageActive."); + console.log('AbilityLifecycleCallback onWindowStageActive.'); }, onWindowStageInactive(ability, windowStage){ - console.log("AbilityLifecycleCallback onWindowStageInactive."); + console.log('AbilityLifecycleCallback onWindowStageInactive.'); }, onWindowStageDestroy(ability, windowStage){ - console.log("AbilityLifecycleCallback onWindowStageDestroy."); + console.log('AbilityLifecycleCallback onWindowStageDestroy.'); }, onAbilityDestroy(ability){ - console.log("AbilityLifecycleCallback onAbilityDestroy."); + console.log('AbilityLifecycleCallback onAbilityDestroy.'); }, onAbilityForeground(ability){ - console.log("AbilityLifecycleCallback onAbilityForeground."); + console.log('AbilityLifecycleCallback onAbilityForeground.'); }, onAbilityBackground(ability){ - console.log("AbilityLifecycleCallback onAbilityBackground."); + console.log('AbilityLifecycleCallback onAbilityBackground.'); }, onAbilityContinue(ability){ - console.log("AbilityLifecycleCallback onAbilityContinue."); + console.log('AbilityLifecycleCallback onAbilityContinue.'); } }; export default class MyFirstAbility extends UIAbility { onCreate() { - console.log("MyAbilityStage onCreate"); + console.log('MyAbilityStage onCreate'); // 1. Obtain applicationContext through the context attribute. let applicationContext = this.context.getApplicationContext(); // 2. Register the listener for the ability lifecycle changes through the applicationContext object. try { - globalThis.lifecycleId = applicationContext.on("abilityLifecycle", abilityLifecycleCallback); - console.log("registerAbilityLifecycleCallback number: " + JSON.stringify(lifecycleId)); + globalThis.lifecycleId = applicationContext.on('abilityLifecycle', abilityLifecycleCallback); + console.log('registerAbilityLifecycleCallback number: ' + JSON.stringify(lifecycleId)); } catch (paramError) { - console.log("error: " + paramError.code + " ," + paramError.message); + console.log('error: ' + paramError.code + ' ,' + paramError.message); } } } @@ -285,17 +285,17 @@ export default class MyFirstAbility extends UIAbility { MySecondAbility.ts ```ts -import UIAbility from "ohos.app.ability.UIAbility"; +import UIAbility from 'ohos.app.ability.UIAbility'; export default class MySecondAbility extends UIAbility { onDestroy() { let applicationContext = this.context.getApplicationContext(); - // 3. Deregister the listener for the environment changes through the applicationContext object. - applicationContext.off("abilityLifecycle", globalThis.lifecycleId, (error) => { + // 3. Deregister the listener for the ability lifecycle changes through the applicationContext object. + applicationContext.off('abilityLifecycle', globalThis.lifecycleId, (error) => { if (error.code != 0) { - console.log("unregisterAbilityLifecycleCallback failed, error: " + JSON.stringify(error)); + console.log('unregisterAbilityLifecycleCallback failed, error: ' + JSON.stringify(error)); } else { - console.log("unregisterAbilityLifecycleCallback success."); + console.log('unregisterAbilityLifecycleCallback success.'); } }); } diff --git a/en/application-dev/reference/apis/js-apis-app-ability-abilityManager.md b/en/application-dev/reference/apis/js-apis-app-ability-abilityManager.md index f7f9c49a4cdf1c9e8c92ad8b7c8bd977df525477..4f755c8fe2814c4b95e26e106712abc73845fb7d 100644 --- a/en/application-dev/reference/apis/js-apis-app-ability-abilityManager.md +++ b/en/application-dev/reference/apis/js-apis-app-ability-abilityManager.md @@ -21,13 +21,14 @@ Enumerates the ability states. This enum can be used together with [AbilityRunni **System API**: This enum is an internal definition of a system API and cannot be called by third-party applications. -| Name| Value| Description| +| Name| Value| Description| | -------- | -------- | -------- | -| INITIAL | 0 | The ability is in the initial state.| -| FOREGROUND | 9 | The ability is in the foreground state. | -| BACKGROUND | 10 | The ability is in the background state. | -| FOREGROUNDING | 11 | The ability is in the state of being switched to the foreground. | -| BACKGROUNDING | 12 | The ability is in the state of being switched to the background. | +| INITIAL | 0 | The ability is in the initial state.| +| FOCUS | 2 | The ability has the focus.| +| FOREGROUND | 9 | The ability is in the foreground state. | +| BACKGROUND | 10 | The ability is in the background state. | +| FOREGROUNDING | 11 | The ability is in the state of being switched to the foreground. | +| BACKGROUNDING | 12 | The ability is in the state of being switched to the background. | ## updateConfiguration @@ -38,7 +39,7 @@ Updates the configuration. This API uses an asynchronous callback to return the **Permission required**: ohos.permission.UPDATE_CONFIGURATION **System capability**: SystemCapability.Ability.AbilityRuntime.Core - + **Parameters** | Name | Type | Mandatory | Description | @@ -71,9 +72,9 @@ const config = { try { abilityManager.updateConfiguration(config, (err) => { if (err.code !== 0) { - console.log("updateConfiguration fail, err: " + JSON.stringify(err)); + console.log('updateConfiguration fail, err: ' + JSON.stringify(err)); } else { - console.log("updateConfiguration success."); + console.log('updateConfiguration success.'); } }) } catch (paramError) { @@ -142,7 +143,7 @@ try { getAbilityRunningInfos(callback: AsyncCallback\>): void -Obtains the ability running information. This API uses an asynchronous callback to return the result. +Obtains the UIAbility running information. This API uses an asynchronous callback to return the result. **Required permissions**: ohos.permission.GET_RUNNING_INFO @@ -152,7 +153,7 @@ Obtains the ability running information. This API uses an asynchronous callback | Name | Type | Mandatory | Description | | --------- | ---------------------------------------- | ---- | -------------- | -| callback | AsyncCallback\> | Yes | Callback used to return the API call result and the ability running information. You can perform error handling or custom processing in this callback. | +| callback | AsyncCallback\> | Yes | Callback used to return the API call result and the UIAbility running information. You can perform error handling or custom processing in this callback. | **Error codes** @@ -170,9 +171,9 @@ import abilityManager from '@ohos.app.ability.abilityManager'; try { abilityManager.getAbilityRunningInfos((err, data) => { if (err.code !== 0) { - console.log("getAbilityRunningInfos fail, error: " + JSON.stringify(err)); + console.log('getAbilityRunningInfos fail, error: ' + JSON.stringify(err)); } else { - console.log("getAbilityRunningInfos success, data: " + JSON.stringify(data)); + console.log('getAbilityRunningInfos success, data: ' + JSON.stringify(data)); } }); } catch (paramError) { @@ -185,7 +186,7 @@ try { getAbilityRunningInfos(): Promise\> -Obtains the ability running information. This API uses a promise to return the result. +Obtains the UIAbility running information. This API uses a promise to return the result. **Required permissions**: ohos.permission.GET_RUNNING_INFO @@ -195,7 +196,7 @@ Obtains the ability running information. This API uses a promise to return the r | Type | Description | | ---------------------------------------- | ------- | -| Promise\> | Callback used to return the API call result and the ability running information. You can perform error handling or custom processing in this callback.| +| Promise\> | Promise used to return the API call result and the UIAbility running information. You can perform error handling or custom processing in this callback.| **Error codes** @@ -212,9 +213,9 @@ import abilityManager from '@ohos.app.ability.abilityManager'; try { abilityManager.getAbilityRunningInfos().then((data) => { - console.log("getAbilityRunningInfos success, data: " + JSON.stringify(data)) + console.log('getAbilityRunningInfos success, data: ' + JSON.stringify(data)); }).catch((err) => { - console.log("getAbilityRunningInfos fail, err: " + JSON.stringify(err)); + console.log('getAbilityRunningInfos fail, err: ' + JSON.stringify(err)); }); } catch (paramError) { console.log('error.code: ' + JSON.stringify(paramError.code) @@ -257,9 +258,9 @@ let upperLimit = 10; try { abilityManager.getExtensionRunningInfos(upperLimit, (err, data) => { if (err.code !== 0) { - console.log("getExtensionRunningInfos fail, err: " + JSON.stringify(err)); + console.log('getExtensionRunningInfos fail, err: ' + JSON.stringify(err)); } else { - console.log("getExtensionRunningInfos success, data: " + JSON.stringify(data)); + console.log('getExtensionRunningInfos success, data: ' + JSON.stringify(data)); } }); } catch (paramError) { @@ -273,7 +274,7 @@ try { getExtensionRunningInfos(upperLimit: number): Promise\> Obtains the ExtensionAbility running information. This API uses a promise to return the result. - + **Required permissions**: ohos.permission.GET_RUNNING_INFO **System capability**: SystemCapability.Ability.AbilityRuntime.Core @@ -307,9 +308,9 @@ let upperLimit = 10; try { abilityManager.getExtensionRunningInfos(upperLimit).then((data) => { - console.log("getExtensionRunningInfos success, data: " + JSON.stringify(data)); + console.log('getExtensionRunningInfos success, data: ' + JSON.stringify(data)); }).catch((err) => { - console.log("getExtensionRunningInfos fail, err: " + JSON.stringify(err)); + console.log('getExtensionRunningInfos fail, err: ' + JSON.stringify(err)); }) } catch (paramError) { console.log('error.code: ' + JSON.stringify(paramError.code) @@ -346,9 +347,9 @@ import abilityManager from '@ohos.app.ability.abilityManager'; abilityManager.getTopAbility((err, data) => { if (err.code !== 0) { - console.log("getTopAbility fail, err: " + JSON.stringify(err)); + console.log('getTopAbility fail, err: ' + JSON.stringify(err)); } else { - console.log("getTopAbility success, data: " + JSON.stringify(data)); + console.log('getTopAbility success, data: ' + JSON.stringify(data)); } }); ``` @@ -358,7 +359,7 @@ abilityManager.getTopAbility((err, data) => { getTopAbility(): Promise\; Obtains the top ability, which is the ability that has the window focus. This API uses a promise to return the result. - + **System capability**: SystemCapability.Ability.AbilityRuntime.Core **Return value** @@ -381,8 +382,8 @@ For details about the error codes, see [Ability Error Codes](../errorcodes/error import abilityManager from '@ohos.app.ability.abilityManager'; abilityManager.getTopAbility().then((data) => { - console.log("getTopAbility success, data: " + JSON.stringify(data)); + console.log('getTopAbility success, data: ' + JSON.stringify(data)); }).catch((err) => { - console.log("getTopAbility fail, err: " + JSON.stringify(err)); + console.log('getTopAbility fail, err: ' + JSON.stringify(err)); }) ``` diff --git a/en/application-dev/reference/apis/js-apis-app-ability-abilityStage.md b/en/application-dev/reference/apis/js-apis-app-ability-abilityStage.md index 50feb82791f8992894641a296d6cb831fdc86680..b9f749344fe94ffc886205b281bd88379a0c5f48 100644 --- a/en/application-dev/reference/apis/js-apis-app-ability-abilityStage.md +++ b/en/application-dev/reference/apis/js-apis-app-ability-abilityStage.md @@ -30,7 +30,7 @@ import AbilityStage from '@ohos.app.ability.AbilityStage'; class MyAbilityStage extends AbilityStage { onCreate() { - console.log("MyAbilityStage.onCreate is called"); + console.log('MyAbilityStage.onCreate is called'); } } ``` @@ -63,8 +63,8 @@ import AbilityStage from '@ohos.app.ability.AbilityStage'; class MyAbilityStage extends AbilityStage { onAcceptWant(want) { - console.log("MyAbilityStage.onAcceptWant called"); - return "com.example.test"; + console.log('MyAbilityStage.onAcceptWant called'); + return 'com.example.test'; } } ``` diff --git a/en/application-dev/reference/apis/js-apis-app-ability-appManager.md b/en/application-dev/reference/apis/js-apis-app-ability-appManager.md index 840a395eac9e17558918dd7466aa9e0b178b1c4d..760fb188206cca471e89af5f9788a23e6e32c9a2 100644 --- a/en/application-dev/reference/apis/js-apis-app-ability-appManager.md +++ b/en/application-dev/reference/apis/js-apis-app-ability-appManager.md @@ -41,9 +41,9 @@ import appManager from '@ohos.app.ability.appManager'; appManager.isRunningInStabilityTest((err, flag) => { if (err.code !== 0) { - console.log("isRunningInStabilityTest faile, err: " + JSON.stringify(err)); + console.log('isRunningInStabilityTest faile, err: ' + JSON.stringify(err)); } else { - console.log("The result of isRunningInStabilityTest is:" + JSON.stringify(flag)); + console.log('The result of isRunningInStabilityTest is:' + JSON.stringify(flag)); } }) ``` @@ -77,9 +77,9 @@ For details about the error codes, see [Ability Error Codes](../errorcodes/error import appManager from '@ohos.app.ability.appManager'; 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)); }); ``` @@ -112,9 +112,9 @@ For details about the error codes, see [Ability Error Codes](../errorcodes/error import appManager from '@ohos.app.ability.appManager'; 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)); }); ``` @@ -147,9 +147,9 @@ import appManager from '@ohos.app.ability.appManager'; appManager.isRamConstrainedDevice((err, data) => { if (err.code !== 0) { - console.log("isRamConstrainedDevice faile, err: " + JSON.stringify(err)); + console.log('isRamConstrainedDevice faile, err: ' + JSON.stringify(err)); } else { - console.log("The result of isRamConstrainedDevice is:" + JSON.stringify(data)); + console.log('The result of isRamConstrainedDevice is:' + JSON.stringify(data)); } }) ``` @@ -182,9 +182,9 @@ For details about the error codes, see [Ability Error Codes](../errorcodes/error import appManager from '@ohos.app.ability.appManager'; 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)); }); ``` @@ -217,16 +217,16 @@ import appManager from '@ohos.app.ability.appManager'; appManager.getAppMemorySize((err, data) => { if (err.code !== 0) { - console.log("getAppMemorySize faile, err: " + JSON.stringify(err)); + console.log('getAppMemorySize faile, err: ' + JSON.stringify(err)); } else { - console.log("The size of app memory is:" + JSON.stringify(data)); + console.log('The size of app memory is:' + JSON.stringify(data)); } }) ``` -## appManager.getProcessRunningInformation +## appManager.getRunningProcessInformation -getProcessRunningInformation(): Promise\>; +getRunningProcessInformation(): Promise\>; Obtains information about the running processes. This API uses a promise to return the result. @@ -234,13 +234,11 @@ Obtains information about the running processes. This API uses a promise to retu **System capability**: SystemCapability.Ability.AbilityRuntime.Core -**System API**: This is a system API and cannot be called by third-party applications. - **Return value** | Type| Description| | -------- | -------- | -| Promise\> | Promise used to return the API call result and the process running information. You can perform error handling or custom processing in this callback.| +| Promise\> | Promise used to return the API call result and the process running information. You can perform error handling or custom processing in this callback.| **Error codes** @@ -255,16 +253,16 @@ For details about the error codes, see [Ability Error Codes](../errorcodes/error ```ts import appManager from '@ohos.app.ability.appManager'; -appManager.getProcessRunningInformation().then((data) => { - console.log("The process running information is:" + JSON.stringify(data)); +appManager.getRunningProcessInformation().then((data) => { + console.log('The running process information is:' + JSON.stringify(data)); }).catch((error) => { - console.log("error:" + JSON.stringify(error)); + console.log('error:' + JSON.stringify(error)); }); ``` -## appManager.getProcessRunningInformation9+ +## appManager.getRunningProcessInformation9+ -getProcessRunningInformation(callback: AsyncCallback\>): void; +getRunningProcessInformation(callback: AsyncCallback\>): void; Obtains information about the running processes. This API uses an asynchronous callback to return the result. @@ -272,13 +270,11 @@ Obtains information about the running processes. This API uses an asynchronous c **System capability**: SystemCapability.Ability.AbilityRuntime.Core -**System API**: This is a system API and cannot be called by third-party applications. - **Parameters** | Type| Description| | -------- | -------- | -|AsyncCallback\> | Callback used to return the API call result and the process running information. You can perform error handling or custom processing in this callback.| +|AsyncCallback\> | Callback used to return the API call result and the process running information. You can perform error handling or custom processing in this callback.| **Error codes** @@ -293,18 +289,18 @@ For details about the error codes, see [Ability Error Codes](../errorcodes/error ```ts import appManager from '@ohos.app.ability.appManager'; -appManager.getProcessRunningInformation((err, data) => { +appManager.getRunningProcessInformation((err, data) => { if (err.code !== 0) { - console.log("getProcessRunningInformation faile, err: " + JSON.stringify(err)); + console.log('getRunningProcessInformation faile, err: ' + JSON.stringify(err)); } else { - console.log("The process running information is:" + JSON.stringify(data)); + console.log('The process running information is:' + JSON.stringify(data)); } }) ``` ## appManager.on -on(type: "applicationState", observer: ApplicationStateObserver): number; +on(type: 'applicationState', observer: ApplicationStateObserver): number; Registers an observer to listen for the state changes of all applications. @@ -318,7 +314,7 @@ Registers an observer to listen for the state changes of all applications. | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | -| type | string | Yes| Type of the API to call. It is fixed at **"applicationState"**.| +| type | string | Yes| Type of the API to call. It is fixed at **'applicationState'**.| | observer | [ApplicationStateObserver](./js-apis-inner-application-applicationStateObserver.md) | Yes| Application state observer, which is used to observe the lifecycle change of an application.| **Return value** @@ -367,7 +363,7 @@ try { ## appManager.on -on(type: "applicationState", observer: ApplicationStateObserver, bundleNameList: Array\): number; +on(type: 'applicationState', observer: ApplicationStateObserver, bundleNameList: Array\): number; Registers an observer to listen for the state changes of a specified application. @@ -381,7 +377,7 @@ Registers an observer to listen for the state changes of a specified application | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | -| type | string | Yes| Type of the API to call. It is fixed at **"applicationState"**.| +| type | string | Yes| Type of the API to call. It is fixed at **'applicationState'**.| | observer | [ApplicationStateObserver](./js-apis-inner-application-applicationStateObserver.md) | Yes| Application state observer, which is used to observe the lifecycle change of an application.| | bundleNameList | `Array` | Yes| **bundleName** array of the application. A maximum of 128 bundle names can be passed.| @@ -423,7 +419,7 @@ let applicationStateObserver = { } let bundleNameList = ['bundleName1', 'bundleName2']; try { - const observerId = appManager.on("applicationState", applicationStateObserver, bundleNameList); + const observerId = appManager.on('applicationState', applicationStateObserver, bundleNameList); console.log(`[appManager] observerCode: ${observerId}`); } catch (paramError) { console.log(`[appManager] error: ${paramError.code}, ${paramError.message} `); @@ -432,7 +428,7 @@ try { ## appManager.off -off(type: "applicationState", observerId: number, callback: AsyncCallback\): void; +off(type: 'applicationState', observerId: number, callback: AsyncCallback\): void; Deregisters the application state observer. This API uses an asynchronous callback to return the result. @@ -446,7 +442,7 @@ Deregisters the application state observer. This API uses an asynchronous callba | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | -| type | string | Yes| Type of the API to call. It is fixed at **"applicationState"**.| +| type | string | Yes| Type of the API to call. It is fixed at **'applicationState'**.| | observerId | number | Yes| Digital code of the observer.| | callback | AsyncCallback\ | Yes| Callback used to return the API call result. You can perform error handling or custom processing in this callback.| @@ -485,7 +481,7 @@ let applicationStateObserver = { } let bundleNameList = ['bundleName1', 'bundleName2']; try { - observerId = appManager.on("applicationState", applicationStateObserver, bundleNameList); + observerId = appManager.on('applicationState', applicationStateObserver, bundleNameList); console.log(`[appManager] observerCode: ${observerId}`); } catch (paramError) { console.log(`[appManager] error: ${paramError.code}, ${paramError.message} `); @@ -494,13 +490,13 @@ try { // 2. Deregister the application state observer. function unregisterApplicationStateObserverCallback(err) { if (err.code !== 0) { - console.log("unregisterApplicationStateObserverCallback faile, err: " + JSON.stringify(err)); + console.log('unregisterApplicationStateObserverCallback faile, err: ' + JSON.stringify(err)); } else { - console.log("unregisterApplicationStateObserverCallback success."); + console.log('unregisterApplicationStateObserverCallback success.'); } } try { - appManager.off("applicationState", observerId, unregisterApplicationStateObserverCallback); + appManager.off('applicationState', observerId, unregisterApplicationStateObserverCallback); } catch (paramError) { console.log('error: ' + paramError.code + ', ' + paramError.message); } @@ -508,7 +504,7 @@ try { ## appManager.off -off(type: "applicationState", observerId: number): Promise\; +off(type: 'applicationState', observerId: number): Promise\; Deregisters the application state observer. This API uses an asynchronous callback to return the result. @@ -522,7 +518,7 @@ Deregisters the application state observer. This API uses an asynchronous callba | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | -| type | string | Yes| Type of the API to call. It is fixed at **"applicationState"**.| +| type | string | Yes| Type of the API to call. It is fixed at **'applicationState'**.| | observerId | number | Yes| Digital code of the observer.| **Return value** @@ -566,7 +562,7 @@ let applicationStateObserver = { } let bundleNameList = ['bundleName1', 'bundleName2']; try { - observerId = appManager.on("applicationState", applicationStateObserver, bundleNameList); + observerId = appManager.on('applicationState', applicationStateObserver, bundleNameList); console.log(`[appManager] observerCode: ${observerId}`); } catch (paramError) { console.log(`[appManager] error: ${paramError.code}, ${paramError.message} `); @@ -574,10 +570,10 @@ try { // 2. Deregister the application state observer. try { - appManager.off("applicationState", observerId).then((data) => { - console.log("unregisterApplicationStateObserver success, data: " + JSON.stringify(data)); + appManager.off('applicationState', observerId).then((data) => { + console.log('unregisterApplicationStateObserver success, data: ' + JSON.stringify(data)); }).catch((err) => { - console.log("unregisterApplicationStateObserver faile, err: " + JSON.stringify(err)); + console.log('unregisterApplicationStateObserver faile, err: ' + JSON.stringify(err)); }) } catch (paramError) { console.log('error: ' + paramError.code + ', ' + paramError.message); @@ -617,15 +613,15 @@ import appManager from '@ohos.app.ability.appManager'; function getForegroundApplicationsCallback(err, data) { if (err.code !== 0) { - console.log("getForegroundApplicationsCallback fail, err: " + JSON.stringify(err)); + console.log('getForegroundApplicationsCallback fail, err: ' + JSON.stringify(err)); } else { - console.log("getForegroundApplicationsCallback success, data: " + JSON.stringify(data)); + console.log('getForegroundApplicationsCallback success, data: ' + JSON.stringify(data)); } } try { appManager.getForegroundApplications(getForegroundApplicationsCallback); } catch (paramError) { - console.log("error: " + paramError.code + ", " + paramError.message); + console.log('error: ' + paramError.code + ', ' + paramError.message); } ``` @@ -661,9 +657,9 @@ For details about the error codes, see [Ability Error Codes](../errorcodes/error import appManager from '@ohos.app.ability.appManager'; appManager.getForegroundApplications().then((data) => { - console.log("getForegroundApplications success, data: " + JSON.stringify(data)); + console.log('getForegroundApplications success, data: ' + JSON.stringify(data)); }).catch((err) => { - console.log("getForegroundApplications fail, err: " + JSON.stringify(err)); + console.log('getForegroundApplications fail, err: ' + JSON.stringify(err)); }) ``` @@ -703,12 +699,12 @@ let bundleName = 'bundleName'; let accountId = 0; try { appManager.killProcessWithAccount(bundleName, accountId).then(() => { - console.log("killProcessWithAccount success"); + console.log('killProcessWithAccount success'); }).catch((err) => { - console.log("killProcessWithAccount fail, err: " + JSON.stringify(err)); + console.error('killProcessWithAccount fail, err: ' + JSON.stringify(err)); }) } catch (paramError) { - console.log("error: " + paramError.code + ", " + paramError.message); + console.error('error: ' + paramError.code + ', ' + paramError.message); } ``` @@ -750,9 +746,9 @@ let bundleName = 'bundleName'; let accountId = 0; function killProcessWithAccountCallback(err, data) { if (err.code !== 0) { - console.log("killProcessWithAccountCallback fail, err: " + JSON.stringify(err)); + console.log('killProcessWithAccountCallback fail, err: ' + JSON.stringify(err)); } else { - console.log("killProcessWithAccountCallback success."); + console.log('killProcessWithAccountCallback success.'); } } appManager.killProcessWithAccount(bundleName, accountId, killProcessWithAccountCallback); @@ -793,15 +789,15 @@ import appManager from '@ohos.app.ability.appManager'; let bundleName = 'bundleName'; function killProcessesByBundleNameCallback(err, data) { if (err.code !== 0) { - console.log("killProcessesByBundleNameCallback fail, err: " + JSON.stringify(err)); + console.log('killProcessesByBundleNameCallback fail, err: ' + JSON.stringify(err)); } else { - console.log("killProcessesByBundleNameCallback success."); + console.log('killProcessesByBundleNameCallback success.'); } } try { appManager.killProcessesByBundleName(bundleName, killProcessesByBundleNameCallback); } catch (paramError) { - console.log("error: " + paramError.code + ", " + paramError.message); + console.log('error: ' + paramError.code + ', ' + paramError.message); } ``` @@ -845,12 +841,12 @@ import appManager from '@ohos.app.ability.appManager'; let bundleName = 'bundleName'; try { appManager.killProcessesByBundleName(bundleName).then((data) => { - console.log("killProcessesByBundleName success."); + console.log('killProcessesByBundleName success.'); }).catch((err) => { - console.log("killProcessesByBundleName fail, err: " + JSON.stringify(err)); + console.log('killProcessesByBundleName fail, err: ' + JSON.stringify(err)); }) } catch (paramError) { - console.log("error: " + paramError.code + ", " + paramError.message); + console.log('error: ' + paramError.code + ', ' + paramError.message); } ``` @@ -889,15 +885,15 @@ import appManager from '@ohos.app.ability.appManager'; let bundleName = 'bundleName'; function clearUpApplicationDataCallback(err, data) { if (err) { - console.log("clearUpApplicationDataCallback fail, err: " + JSON.stringify(err)); + console.log('clearUpApplicationDataCallback fail, err: ' + JSON.stringify(err)); } else { - console.log("clearUpApplicationDataCallback success."); + console.log('clearUpApplicationDataCallback success.'); } } try { appManager.clearUpApplicationData(bundleName, clearUpApplicationDataCallback); } catch (paramError) { - console.log("error: " + paramError.code + ", " + paramError.message); + console.log('error: ' + paramError.code + ', ' + paramError.message); } ``` @@ -941,12 +937,12 @@ import appManager from '@ohos.app.ability.appManager'; let bundleName = 'bundleName'; try { appManager.clearUpApplicationData(bundleName).then((data) => { - console.log("clearUpApplicationData success."); + console.log('clearUpApplicationData success.'); }).catch((err) => { - console.log("clearUpApplicationData fail, err: " + JSON.stringify(err)); + console.log('clearUpApplicationData fail, err: ' + JSON.stringify(err)); }) } catch (paramError) { - console.log("error: " + paramError.code + ", " + paramError.message); + console.log('error: ' + paramError.code + ', ' + paramError.message); } ``` diff --git a/en/application-dev/reference/apis/js-apis-app-ability-appRecovery.md b/en/application-dev/reference/apis/js-apis-app-ability-appRecovery.md index e066ac119344842ffce617fd7934efa3712d895f..8a5a840b0c6d9723c03ccdb988927f0f296e2971 100644 --- a/en/application-dev/reference/apis/js-apis-app-ability-appRecovery.md +++ b/en/application-dev/reference/apis/js-apis-app-ability-appRecovery.md @@ -18,13 +18,12 @@ Enumerates the application restart flags. This enum is used as an input paramete **System capability**: SystemCapability.Ability.AbilityRuntime.Core -| Name | Value | Description | -| ----------------------------- | ---- | ------------------------------------------------------------ | -| ALWAYS_RESTART | 0 | The application is restarted in all cases.| -| CPP_CRASH_NO_RESTART | 0x0001 | The application is not restarted in the case of CPP_CRASH.| -| JS_CRASH_NO_RESTART | 0x0002 | The application is not restarted in the case of JS_CRASH.| -| APP_FREEZE_NO_RESTART | 0x0004 | The application is not restarted in the case of APP_FREEZE.| -| NO_RESTART | 0xFFFF | The application is not restarted in any case.| +| Name | Value | Description | +| ---------- | ---- | ---------- | +| ALWAYS_RESTART | 0 | The application is restarted in all cases.| +| RESTART_WHEN_JS_CRASH | 0x0001 | The application is restarted in the case of JS_CRASH.| +| RESTART_WHEN_APP_FREEZE | 0x0002 | The application is restarted in the case of APP_FREEZE.| +| NO_RESTART | 0xFFFF | The application is not restarted in any case.| ## appRecovery.SaveOccasionFlag @@ -69,9 +68,8 @@ Enables application recovery. ```ts import appRecovery from '@ohos.app.ability.appRecovery'; import AbilityStage from '@ohos.app.ability.AbilityStage'; -import UIAbility from '@ohos.app.ability.UIAbility'; -export default class MyAbility extends UIAbility { +export default class MyAbilityStage extends AbilityStage { onCreate() { appRecovery.enableAppRecovery( appRecovery.RestartFlag::ALWAYS_RESTART, @@ -99,15 +97,15 @@ import errorManager from '@ohos.app.ability.errorManager'; let observer = { onUnhandledException(errorMsg) { - console.log('onUnhandledException, errorMsg: ', errorMsg) + console.log('onUnhandledException, errorMsg: ', errorMsg); appRecovery.restartApp(); } }; try { - errorManager.on("error", observer); + errorManager.on('error', observer); } catch (paramError) { - console.log("error: " + paramError.code + ", " + paramError.message); + console.log('error: ' + paramError.code + ', ' + paramError.message); } ``` @@ -133,14 +131,14 @@ import errorManager from '@ohos.app.ability.errorManager'; let observer = { onUnhandledException(errorMsg) { - console.log('onUnhandledException, errorMsg: ', errorMsg) + console.log('onUnhandledException, errorMsg: ', errorMsg); appRecovery.saveAppState(); } }; try { - errorManager.on("error", observer); + errorManager.on('error', observer); } catch (paramError) { - console.log("error: " + paramError.code + ", " + paramError.message); + console.log('error: ' + paramError.code + ', ' + paramError.message); } ``` diff --git a/en/application-dev/reference/apis/js-apis-app-ability-startOptions.md b/en/application-dev/reference/apis/js-apis-app-ability-startOptions.md index 3e95fbf541e7ed79834673c2ca97b1398bc73989..b750094435503f6b54a5826fcab9995ca5aa33be 100644 --- a/en/application-dev/reference/apis/js-apis-app-ability-startOptions.md +++ b/en/application-dev/reference/apis/js-apis-app-ability-startOptions.md @@ -1,6 +1,6 @@ # @ohos.app.ability.StartOptions (StartOptions) -**StartOptions** is used as an input parameter of [startAbility()](js-apis-inner-application-uiAbilityContext.md#uiabilitycontextstartability-1) to specify the window mode of an ability. +The **StartOptions** module implements ability startup options. > **NOTE** > @@ -18,7 +18,38 @@ import StartOptions from '@ohos.app.ability.StartOptions'; **System capability**: SystemCapability.Ability.AbilityRuntime.Core +**System API**: This is a system API and cannot be called by third-party applications. + | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | -| [windowMode](js-apis-application-abilityConstant.md#abilityconstantwindowmode) | number | No| Window mode.| -| displayId | number | No| Display ID. The default value is **0**, indicating the current display.| +| [windowMode](js-apis-app-ability-abilityConstant.md#abilityconstantwindowmode) | number | No| Window mode.| +| displayId | number | No| Display ID.| + +**Example** + + ```ts + import missionManager from '@ohos.app.ability.missionManager'; + + try { + missionManager.getMissionInfos('', 10, (error, missions) => { + if (error.code) { + console.log('getMissionInfos failed, error.code:' + JSON.stringify(error.code) + + 'error.message:' + JSON.stringify(error.message)); + return; + } + console.log('size = ' + missions.length); + console.log('missions = ' + JSON.stringify(missions)); + let id = missions[0].missionId; + + let startOptions = { + windowMode : 101, + displayId: 0 + }; + missionManager.moveMissionToFront(id, startOptions).then(() => { + console.log('moveMissionToFront is called '); + }); + }); + } catch (paramError) { + console.log('error: ' + paramError.code + ', ' + paramError.message); + } + ``` diff --git a/en/application-dev/reference/apis/js-apis-application-appManager.md b/en/application-dev/reference/apis/js-apis-application-appManager.md index 591f5ec77a34ef2eb36979a00b9553241b33ddb3..8e8547985ddc883c7643eab6f3f3e25412eebf4a 100644 --- a/en/application-dev/reference/apis/js-apis-application-appManager.md +++ b/en/application-dev/reference/apis/js-apis-application-appManager.md @@ -9,7 +9,7 @@ The **appManager** module implements application management. You can use the API ## Modules to Import ```ts -import appManager from '@ohos.application.appManager'; +import app from '@ohos.application.appManager'; ``` ## appManager.isRunningInStabilityTest8+ @@ -22,17 +22,17 @@ Checks whether this application is undergoing a stability test. This API uses an **Parameters** - | Name| Type| Mandatory| Description| - | -------- | -------- | -------- | -------- | - | callback | AsyncCallback<boolean> | Yes| Callback used to return the result. If the application is undergoing a stability test, **true** will be returned; otherwise, **false** will be returned.| +| Name| Type| Mandatory| Description| +| -------- | -------- | -------- | -------- | +| callback | AsyncCallback<boolean> | Yes| Callback used to return the result. If the application is undergoing a stability test, **true** will be returned; otherwise, **false** will be returned.| **Example** ```ts - appManager.isRunningInStabilityTest((err, flag) => { - console.log('error:' + JSON.stringfy(err)); - console.log('The result of isRunningInStabilityTest is:' + JSON.stringify(flag)); - }) + import app from '@ohos.application.appManager'; + app.isRunningInStabilityTest((err, flag) => { + console.log('startAbility result:' + JSON.stringify(err)); + }); ``` @@ -46,17 +46,18 @@ Checks whether this application is undergoing a stability test. This API uses a **Return value** - | Type| Description| - | -------- | -------- | - | Promise<boolean> | Promise used to return the result. If the application is undergoing a stability test, **true** will be returned; otherwise, **false** will be returned.| +| Type| Description| +| -------- | -------- | +| Promise<boolean> | Promise used to return the result. If the application is undergoing a stability test, **true** will be returned; otherwise, **false** will be returned.| **Example** ```ts - appManager.isRunningInStabilityTest().then((flag) => { - console.log('The result of isRunningInStabilityTest is:' + JSON.stringify(flag)); + import app from '@ohos.application.appManager'; + app.isRunningInStabilityTest().then((flag) => { + console.log('success:' + JSON.stringify(flag)); }).catch((error) => { - console.log('error:' + JSON.stringify(error)); + console.log('failed:' + JSON.stringify(error)); }); ``` @@ -71,17 +72,17 @@ Checks whether this application is running on a RAM constrained device. This API **Return value** - | Type| Description| - | -------- | -------- | - | Promise<boolean> | Promise used to return whether the application is running on a RAM constrained device. If the application is running on a RAM constrained device, **true** will be returned; otherwise, **false** will be returned.| +| Type| Description| +| -------- | -------- | +| Promise<boolean> | Promise used to return whether the application is running on a RAM constrained device. If the application is running on a RAM constrained device, **true** will be returned; otherwise, **false** will be returned.| **Example** ```ts - appManager.isRamConstrainedDevice().then((data) => { - console.log('The result of isRamConstrainedDevice is:' + JSON.stringify(data)); + app.isRamConstrainedDevice().then((data) => { + console.log('success:' + JSON.stringify(data)); }).catch((error) => { - console.log('error:' + JSON.stringify(error)); + console.log('failed:' + JSON.stringify(error)); }); ``` @@ -95,17 +96,17 @@ Checks whether this application is running on a RAM constrained device. This API **Parameters** - | Name| Type| Mandatory| Description| - | -------- | -------- | -------- | -------- | - | callback | AsyncCallback<boolean> | Yes| Callback used to return whether the application is running on a RAM constrained device. If the application is running on a RAM constrained device, **true** will be returned; otherwise, **false** will be returned.| +| Name| Type| Mandatory| Description| +| -------- | -------- | -------- | -------- | +| callback | AsyncCallback<boolean> | Yes| Callback used to return whether the application is running on a RAM constrained device. If the application is running on a RAM constrained device, **true** will be returned; otherwise, **false** will be returned.| **Example** ```ts - appManager.isRamConstrainedDevice((err, data) => { - console.log('error:' + JSON.stringify(err)); - console.log('The result of isRamConstrainedDevice is:' + JSON.stringify(data)); - }) + app.isRamConstrainedDevice((err, data) => { + console.log('startAbility result failed:' + JSON.stringify(err)); + console.log('startAbility result success:' + JSON.stringify(data)); + }); ``` ## appManager.getAppMemorySize @@ -118,17 +119,17 @@ Obtains the memory size of this application. This API uses a promise to return t **Return value** - | Type| Description| - | -------- | -------- | - | Promise<number> | Size of the application memory.| +| Type| Description| +| -------- | -------- | +| Promise<number> | Promise used to return the memory size, in MB.| **Example** ```ts - appManager.getAppMemorySize().then((data) => { - console.log('The size of app memory is:' + JSON.stringify(data)); + app.getAppMemorySize().then((data) => { + console.log('success:' + JSON.stringify(data)); }).catch((error) => { - console.log('error:' + JSON.stringify(error)); + console.log('failed:' + JSON.stringify(error)); }); ``` @@ -142,17 +143,17 @@ Obtains the memory size of this application. This API uses an asynchronous callb **Parameters** - | Name| Type| Mandatory| Description| - | -------- | -------- | -------- | -------- | - | callback | AsyncCallback<number> | Yes| Size of the application memory.| +| Name| Type| Mandatory| Description| +| -------- | -------- | -------- | -------- | +| callback | AsyncCallback<number> | Yes| Callback used to return the memory size, in MB.| **Example** ```ts - appManager.getAppMemorySize((err, data) => { - console.log('error:' + JSON.stringify(err)); - console.log('The size of app memory is:' + JSON.stringify(data)); - }) + app.getAppMemorySize((err, data) => { + console.log('startAbility result failed :' + JSON.stringify(err)); + console.log('startAbility result success:' + JSON.stringify(data)); + }); ``` ## appManager.getProcessRunningInfos(deprecated) @@ -160,7 +161,7 @@ getProcessRunningInfos(): Promise\>; Obtains information about the running processes. This API uses a promise to return the result. -> This API is deprecated since API version 9. You are advised to use [appManager.getProcessRunningInformation9+](#appmanagergetprocessrunninginformation9) instead. +> This API is deprecated since API version 9. You are advised to use [appManager.getRunningProcessInformation9+](js-apis-app-ability-appManager.md#appmanagergetrunningprocessinformation) instead. **Required permissions**: ohos.permission.GET_RUNNING_INFO @@ -175,10 +176,10 @@ Obtains information about the running processes. This API uses a promise to retu **Example** ```ts - appManager.getProcessRunningInfos().then((data) => { - console.log('The process running infos is:' + JSON.stringify(data)); + app.getProcessRunningInfos().then((data) => { + console.log('success:' + JSON.stringify(data)); }).catch((error) => { - console.log('error:' + JSON.stringify(error)); + console.log('failed:' + JSON.stringify(error)); }); ``` @@ -188,7 +189,7 @@ getProcessRunningInfos(callback: AsyncCallback\>): vo Obtains information about the running processes. This API uses an asynchronous callback to return the result. -> This API is deprecated since API version 9. You are advised to use [appManager.getProcessRunningInformation9+](#appmanagergetprocessrunninginformation9-1) instead. +> This API is deprecated since API version 9. You are advised to use [appManager.getRunningProcessInformation9+](js-apis-app-ability-appManager.md#appmanagergetrunningprocessinformation9) instead. **Required permissions**: ohos.permission.GET_RUNNING_INFO @@ -203,63 +204,12 @@ Obtains information about the running processes. This API uses an asynchronous c **Example** ```ts - appManager.getProcessRunningInfos((err, data) => { - console.log('error:' + JSON.stringify(err)); - console.log('The process running infos is:' + JSON.stringify(data)); - }) - ``` - -## appManager.getProcessRunningInformation9+ - -getProcessRunningInformation(): Promise\>; - -Obtains information about the running processes. This API uses a promise to return the result. - -**Required permissions**: ohos.permission.GET_RUNNING_INFO - -**System capability**: SystemCapability.Ability.AbilityRuntime.Core - -**Return value** - -| Type| Description| -| -------- | -------- | -| Promise\> | Obtains information about the running processes. This API uses a promise to return the result.| - -**Example** - - ```ts - appManager.getProcessRunningInformation().then((data) => { - console.log('The process running info is:' + JSON.stringify(data)); - }).catch((error) => { - console.log('error:' + JSON.stringify(error)); + app.getProcessRunningInfos((err, data) => { + console.log('startAbility result failed :' + JSON.stringify(err)); + console.log('startAbility result success:' + JSON.stringify(data)); }); ``` -## appManager.getProcessRunningInformation9+ - -getProcessRunningInformation(callback: AsyncCallback\>): void; - -Obtains information about the running processes. This API uses an asynchronous callback to return the result. - -**Required permissions**: ohos.permission.GET_RUNNING_INFO - -**System capability**: SystemCapability.Ability.AbilityRuntime.Core - -**Parameters** - -| Name| Type| Mandatory| Description| -| -------- | -------- | -------- | -------- | -| callback | AsyncCallback\> | Yes| Obtains information about the running processes. This API uses a promise to return the result.| - -**Example** - - ```ts - appManager.getProcessRunningInformation((err, data) => { - console.log('error:' + JSON.stringify(err)); - console.log('The process running info is:' + JSON.stringify(data)); - }) - ``` - ## appManager.registerApplicationStateObserver8+ registerApplicationStateObserver(observer: ApplicationStateObserver): number; @@ -281,7 +231,7 @@ Registers an observer to listen for the state changes of all applications. **Example** ```ts - var applicationStateObserver = { + let applicationStateObserver = { onForegroundApplicationChanged(appStateData) { console.log('------------ onForegroundApplicationChanged -----------', appStateData); }, @@ -297,8 +247,8 @@ Registers an observer to listen for the state changes of all applications. onProcessStateChanged(processData) { console.log('------------ onProcessStateChanged -----------', processData); } - } - const observerCode = appManager.registerApplicationStateObserver(applicationStateObserver); + }; + const observerCode = app.registerApplicationStateObserver(applicationStateObserver); console.log('-------- observerCode: ---------', observerCode); ``` @@ -324,7 +274,7 @@ Registers an observer to listen for the state changes of a specified application **Example** ```ts - var applicationStateObserver = { + let applicationStateObserver = { onForegroundApplicationChanged(appStateData) { console.log('------------ onForegroundApplicationChanged -----------', appStateData); }, @@ -340,9 +290,9 @@ Registers an observer to listen for the state changes of a specified application onProcessStateChanged(processData) { console.log('------------ onProcessStateChanged -----------', processData); } - } - var bundleNameList = ['bundleName1', 'bundleName2']; - const observerCode = appManager.registerApplicationStateObserver(applicationStateObserver, bundleNameList); + }; + let bundleNameList = ['bundleName1', 'bundleName2']; + const observerCode = app.registerApplicationStateObserver(applicationStateObserver, bundleNameList); console.log('-------- observerCode: ---------', observerCode); ``` ## appManager.unregisterApplicationStateObserver8+ @@ -367,14 +317,14 @@ Deregisters the application state observer. This API uses an asynchronous callba **Example** ```ts - var observerId = 100; + let observerId = 100; function unregisterApplicationStateObserverCallback(err) { if (err) { console.log('------------ unregisterApplicationStateObserverCallback ------------', err); } } - appManager.unregisterApplicationStateObserver(observerId, unregisterApplicationStateObserverCallback); + app.unregisterApplicationStateObserver(observerId, unregisterApplicationStateObserverCallback); ``` ## appManager.unregisterApplicationStateObserver8+ @@ -404,15 +354,15 @@ Deregisters the application state observer. This API uses a promise to return th **Example** ```ts - var observerId = 100; + let observerId = 100; - appManager.unregisterApplicationStateObserver(observerId) + app.unregisterApplicationStateObserver(observerId) .then((data) => { console.log('----------- unregisterApplicationStateObserver success ----------', data); }) .catch((err) => { console.log('----------- unregisterApplicationStateObserver fail ----------', err); - }) + }); ``` ## appManager.getForegroundApplications8+ @@ -420,7 +370,7 @@ Deregisters the application state observer. This API uses a promise to return th getForegroundApplications(callback: AsyncCallback\>): void; Obtains information about the applications that are running in the foreground. This API uses an asynchronous callback to return the result. The application information is defined by [AppStateData](js-apis-inner-application-appStateData.md). - + **Required permissions**: ohos.permission.GET_RUNNING_INFO **System capability**: SystemCapability.Ability.AbilityRuntime.Core @@ -443,7 +393,7 @@ Obtains information about the applications that are running in the foreground. T console.log('--------- getForegroundApplicationsCallback success ---------', data) } } - appManager.getForegroundApplications(getForegroundApplicationsCallback); + app.getForegroundApplications(getForegroundApplicationsCallback); ``` ## appManager.getForegroundApplications8+ @@ -467,13 +417,13 @@ Obtains information about the applications that are running in the foreground. T **Example** ```ts - appManager.getForegroundApplications() + app.getForegroundApplications() .then((data) => { console.log('--------- getForegroundApplications success -------', data); }) .catch((err) => { console.log('--------- getForegroundApplications fail -------', err); - }) + }); ``` ## appManager.killProcessWithAccount8+ @@ -482,7 +432,7 @@ killProcessWithAccount(bundleName: string, accountId: number): Promise\ Kills a process by bundle name and account ID. This API uses a promise to return the result. -**Required permissions**: ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS (required only when the account ID is not the current user) and ohos.permission.CLEAN_BACKGROUND_PROCESSES +**Required permissions**: ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS and ohos.permission.CLEAN_BACKGROUND_PROCESSES **System capability**: SystemCapability.Ability.AbilityRuntime.Core @@ -498,15 +448,15 @@ Kills a process by bundle name and account ID. This API uses a promise to return **Example** ```ts -var bundleName = 'bundleName'; -var accountId = 0; -appManager.killProcessWithAccount(bundleName, accountId) +let bundleName = 'bundleName'; +let accountId = 0; +app.killProcessWithAccount(bundleName, accountId) .then((data) => { console.log('------------ killProcessWithAccount success ------------', data); }) .catch((err) => { console.log('------------ killProcessWithAccount fail ------------', err); - }) + }); ``` @@ -520,7 +470,7 @@ Kills a process by bundle name and account ID. This API uses an asynchronous cal **System API**: This is a system API and cannot be called by third-party applications. -**Required permissions**: ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS (required only when the account ID is not the current user) and ohos.permission.CLEAN_BACKGROUND_PROCESSES +**Required permissions**: ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS and ohos.permission.CLEAN_BACKGROUND_PROCESSES **Parameters** @@ -533,8 +483,8 @@ Kills a process by bundle name and account ID. This API uses an asynchronous cal **Example** ```ts -var bundleName = 'bundleName'; -var accountId = 0; +let bundleName = 'bundleName'; +let accountId = 0; function killProcessWithAccountCallback(err, data) { if (err) { console.log('------------- killProcessWithAccountCallback fail, err: --------------', err); @@ -542,7 +492,7 @@ function killProcessWithAccountCallback(err, data) { console.log('------------- killProcessWithAccountCallback success, data: --------------', data); } } -appManager.killProcessWithAccount(bundleName, accountId, killProcessWithAccountCallback); +app.killProcessWithAccount(bundleName, accountId, killProcessWithAccountCallback); ``` ## appManager.killProcessesByBundleName8+ @@ -567,7 +517,7 @@ Kills a process by bundle name. This API uses an asynchronous callback to return **Example** ```ts - var bundleName = 'bundleName'; + let bundleName = 'bundleName'; function killProcessesByBundleNameCallback(err, data) { if (err) { console.log('------------- killProcessesByBundleNameCallback fail, err: --------------', err); @@ -575,7 +525,7 @@ Kills a process by bundle name. This API uses an asynchronous callback to return console.log('------------- killProcessesByBundleNameCallback success, data: --------------', data); } } - appManager.killProcessesByBundleName(bundleName, killProcessesByBundleNameCallback); + app.killProcessesByBundleName(bundleName, killProcessesByBundleNameCallback); ``` ## appManager.killProcessesByBundleName8+ @@ -603,16 +553,16 @@ Kills a process by bundle name. This API uses a promise to return the result. | Promise\ | Promise used to return the result.| **Example** - + ```ts - var bundleName = 'com.example.myapplication'; - appManager.killProcessesByBundleName(bundleName) + let bundleName = 'bundleName'; + app.killProcessesByBundleName(bundleName) .then((data) => { console.log('------------ killProcessesByBundleName success ------------', data); }) .catch((err) => { console.log('------------ killProcessesByBundleName fail ------------', err); - }) + }); ``` ## appManager.clearUpApplicationData8+ @@ -637,7 +587,7 @@ Clears application data by bundle name. This API uses an asynchronous callback t **Example** ```ts - var bundleName = 'bundleName'; + let bundleName = 'bundleName'; function clearUpApplicationDataCallback(err, data) { if (err) { console.log('------------- clearUpApplicationDataCallback fail, err: --------------', err); @@ -645,7 +595,7 @@ Clears application data by bundle name. This API uses an asynchronous callback t console.log('------------- clearUpApplicationDataCallback success, data: --------------', data); } } - appManager.clearUpApplicationData(bundleName, clearUpApplicationDataCallback); + app.clearUpApplicationData(bundleName, clearUpApplicationDataCallback); ``` ## appManager.clearUpApplicationData8+ @@ -675,40 +625,12 @@ Clears application data by bundle name. This API uses a promise to return the re **Example** ```ts - var bundleName = 'bundleName'; - appManager.clearUpApplicationData(bundleName) + let bundleName = 'bundleName'; + app.clearUpApplicationData(bundleName) .then((data) => { console.log('------------ clearUpApplicationData success ------------', data); }) .catch((err) => { console.log('------------ clearUpApplicationData fail ------------', err); - }) + }); ``` - -## ApplicationState9+ - -**System capability**: SystemCapability.Ability.AbilityRuntime.Core - -**System API**: This is a system API and cannot be called by third-party applications. - -| Name | Value | Description | -| -------------------- | --- | --------------------------------- | -| STATE_CREATE | 1 | State indicating that the application is being created. | -| STATE_FOREGROUND | 2 | State indicating that the application is running in the foreground. | -| STATE_ACTIVE | 3 | State indicating that the application is active. | -| STATE_BACKGROUND | 4 | State indicating that the application is running in the background. | -| STATE_DESTROY | 5 | State indicating that the application is destroyed. | - -## ProcessState9+ - -**System capability**: SystemCapability.Ability.AbilityRuntime.Core - -**System API**: This is a system API and cannot be called by third-party applications. - -| Name | Value | Description | -| -------------------- | --- | --------------------------------- | -| STATE_CREATE | 1 | State indicating that the process is being created. | -| STATE_FOREGROUND | 2 | State indicating that the process is running in the foreground. | -| STATE_ACTIVE | 3 | State indicating that the process is active. | -| STATE_BACKGROUND | 4 | State indicating that the process is running in the background. | -| STATE_DESTROY | 5 | State indicating that the process is destroyed. |