diff --git a/en/application-dev/reference/apis/js-apis-abilityrunninginfo.md b/en/application-dev/reference/apis/js-apis-abilityrunninginfo.md new file mode 100644 index 0000000000000000000000000000000000000000..58673b2285ee51d3c952af4b14e9ede1137b909d --- /dev/null +++ b/en/application-dev/reference/apis/js-apis-abilityrunninginfo.md @@ -0,0 +1,47 @@ +# AbilityRunningInfo + +> ![icon-note.gif](public_sys-resources/icon-note.gif) **NOTE** +> The initial APIs of this module are supported since API version 8. Newly added APIs will be marked with a superscript to indicate their earliest API version. + + +Provides ability running information. + + +## Usage + + +The ability running information is obtained by using the **getAbilityRunningInfos** method in **abilityManager**. + + + +``` +import abilitymanager from '@ohos.application.abilityManager'; +abilitymanager.getAbilityRunningInfos((err,data) => { + console.log("getAbilityRunningInfos err: " + err + " data: " + JSON.stringify(data)); +}); +``` + + +## Attributes + + | Name| Type| Readable| Writable| Description| +| -------- | -------- | -------- | -------- | -------- | +| ability | ElementName | Yes| No| Information that matches an ability.| +| pid | number | Yes| No| Process ID.| +| uid | number | Yes| No| User ID.| +| processName | string | Yes| No| Process name.| +| startTime | number | Yes| No| Ability start time.| +| abilityState | [abilityManager.AbilityState](#abilitymanager-abilitystate) | Yes| No| Ability state.| + + +## abilityManager.AbilityState + +Enumerates the ability states. + + | 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 foregrounding state.| +| BACKGROUNDING | 12 | The ability is in the backgrounding state.| diff --git a/en/application-dev/reference/apis/js-apis-abilitystagecontext.md b/en/application-dev/reference/apis/js-apis-abilitystagecontext.md new file mode 100644 index 0000000000000000000000000000000000000000..c41326589ba67c9297b8326ab10085f18863f48e --- /dev/null +++ b/en/application-dev/reference/apis/js-apis-abilitystagecontext.md @@ -0,0 +1,32 @@ +# AbilityStageContext + +> ![icon-note.gif](public_sys-resources/icon-note.gif) **NOTE** +> The initial APIs of this module are supported since API version 9. Newly added APIs will be marked with a superscript to indicate their earliest API version. + + +Implements the context of an ability stage. This module is inherited from [Context](js-apis-application-context.md). + + +## Usage + + +The ability stage context is obtained through an **AbilityStage** instance. + + + +``` +import AbilityStage from '@ohos.application.AbilityStage'; +class MyAbilityStage extends AbilityStage { + onCreate() { + let abilityStageContext = this.context; + } +} +``` + + +## Attributes + + | Name| Type| Readable| Writable| Description| +| -------- | -------- | -------- | -------- | -------- | +| currentHapModuleInfo | HapModuleInfo | Yes| No| **ModuleInfo** object corresponding to the **AbilityStage**.| +| config | [Configuration](js-apis-configuration.md) | Yes| No| Configuration for the environment where the application is running.| diff --git a/en/application-dev/reference/apis/js-apis-application-ability.md b/en/application-dev/reference/apis/js-apis-application-ability.md new file mode 100644 index 0000000000000000000000000000000000000000..230d2a73f61aa324c547ec0819a234a6603d4b24 --- /dev/null +++ b/en/application-dev/reference/apis/js-apis-application-ability.md @@ -0,0 +1,499 @@ +# Ability + +> ![icon-note.gif](public_sys-resources/icon-note.gif) **NOTE** +> The APIs of this module are supported since API version 8. Newly added APIs will be marked with a superscript to indicate their earliest API version. + + +Manages the ability lifecycle and context. + + +## Modules to Import + + +``` +import Ability from '@ohos.application.Ability'; +``` + + +## Attributes + + | Name| Type| Readable| Writable| Description| +| -------- | -------- | -------- | -------- | -------- | +| context | [AbilityContext](js-apis-ability-context.md) | Yes| No| Context of an ability.| +| launchWant | [Want](js-apis-featureAbility.md#Want)| Yes| No| Parameters for starting the ability.| +| lastRequestWant | [Want](js-apis-featureAbility.md#Want)| Yes| No| Parameters used when the ability was started last time.| + + +## onCreate + +onCreate(want: Want, param: LaunchParam): void + +Called to initialize the service logic when an ability is created. + +- Parameters + | Name| Type| Mandatory| Description| + | -------- | -------- | -------- | -------- | + | want | [Want](js-apis-featureAbility.md#Want)| Yes| Information related to this ability, including the ability name and bundle name.| + | param | LaunchParam | Yes| Parameters for starting the ability, and the reason for the last abnormal exit.| + +- Example + + ``` + class myAbility extends Ability { + onCreate(want, param) { + console.log('onCreate, want:' + want.abilityName); + } + } + ``` + + +## onWindowStageCreate + +onWindowStageCreate(windowStage: window.WindowStage): void + +Called when a **WindowStage** is created for this ability. + +- Parameters + | Name| Type| Mandatory| Description| + | -------- | -------- | -------- | -------- | + | windowStage | window.WindowStage | Yes| **WindowStage** information.| + +- Example + + ``` + class myAbility extends Ability { + onWindowStageCreate(windowStage) { + console.log('onWindowStageCreate'); + } + } + ``` + + +## onWindowStageDestroy + +onWindowStageDestroy(): void + +Called when the **WindowStage** is destroyed for this ability. + +- Example + + ``` + class myAbility extends Ability { + onWindowStageDestroy() { + console.log('onWindowStageDestroy'); + } + } + ``` + + +## onWindowStageRestore + +onWindowStageRestore(windowStage: window.WindowStage): void + +Called when the **WindowStage** is restored during the migration of this ability, which is a multi-instance ability. + +- Parameters + | Name| Type| Mandatory| Description| + | -------- | -------- | -------- | -------- | + | windowStage | window.WindowStage | Yes| **WindowStage** information.| + +- Example + + ``` + class myAbility extends Ability { + onWindowStageRestore(windowStage) { + console.log('onWindowStageRestore'); + } + } + ``` + + +## onDestroy + +onDestroy(): void; + +Called when this ability is destroyed to clear resources. + +- Example + + ``` + class myAbility extends Ability { + onDestroy() { + console.log('onDestroy'); + } + } + ``` + + +## onForeground + +onForeground(): void; + +Called when this ability is running in the foreground. + +- Example + + ``` + class myAbility extends Ability { + onForeground() { + console.log('onForeground'); + } + } + ``` + + +## onBackground + +onBackground(): void; + +Callback when this ability is switched to the background. + +- Example + + ``` + class myAbility extends Ability { + onBackground() { + console.log('onBackground'); + } + } + ``` + + +## onContinue + +onContinue(wantParam : {[key: string]: any}): boolean; + +Called to save data during the ability migration preparation process. + +- Parameters + | Name| Type| Mandatory| Description| + | -------- | -------- | -------- | -------- | + | wantParam | {[key: string]: any} | Yes| **want** parameter.| + +- Return value + | Type| Description| + | -------- | -------- | + | boolean | Returns **true** if the migration is accepted; returns **false** otherwise.| + +- Example + + ``` + class myAbility extends Ability { + onContinue(wantParams) { + console.log('onContinue'); + wantParams["myData"] = "my1234567"; + return true; + } + } + ``` + + +## onNewWant + +onNewWant(want: Want): void; + +Called when the ability startup mode is set to singleton. + +- Parameters + | Name| Type| Mandatory| Description| + | -------- | -------- | -------- | -------- | + | want | [Want](js-apis-featureAbility.md#Want)| Yes| Want parameters, such as the ability name and bundle name.| + +- Example + + ``` + class myAbility extends Ability { + onNewWant(want) { + console.log('onNewWant, want:' + want.abilityName); + } + } + ``` + + +## onConfigurationUpdated + +onConfigurationUpdated(config: Configuration): void; + +Called when the configuration of the environment where the ability is running is updated. + +- Parameters + | Name| Type| Mandatory| Description| + | -------- | -------- | -------- | -------- | + | config | [Configuration](#section188911144124715) | Yes| New configuration.| + +- Example + + ``` + class myAbility extends Ability { + onConfigurationUpdated(config) { + console.log('onConfigurationUpdated, config:' + JSON.stringify(config)); + } + } + ``` + + +## Caller + +Implements sending of sequenceable data to the target ability when an ability (caller) invokes the target ability (callee). + + +### call + +call(method, data: rpc.Sequenceable): Promise<void>; + +Sends sequenceable data to the target ability. + +- Parameters + | Name| Type| Mandatory| Description| + | -------- | -------- | -------- | -------- | + | method | string | Yes| Notification message string negotiated between the two abilities. The message is used to instruct the callee to register a function to receive the sequenceable data.| + | data | rpc.Sequenceable | Yes| Sequenceable data. You need to customize the data.| + +- Return value + | Type| Description| + | -------- | -------- | + | Promise<void> | Promise used to return a response.| + +- Example + + ``` + import Ability from '@ohos.application.Ability'; + class MyMessageAble{ // Custom sequenceable data structure + num: 0 + str: '' + constructor() {} + marshalling(messageParcel) { + messageParcel.writeInt(this.num); + messageParcel.writeString(this.str); + console.log('MyMessageAble marshalling num[' + this.num + '] str[' + this.str + ']'); + return true; + } + unmarshalling(messageParcel) { + this.num = messageParcel.readInt(); + this.str = messageParcel.readString(); + console.log('MyMessageAble unmarshalling num[' + this.num + '] str[' + this.str + ']'); + return true; + } + }; + var method = 'call_Function'; // Notification message string negotiated by the two abilities + var caller; + export default class MainAbility extends Ability { + onWindowStageCreate(windowStage) { + caller = await this.context.startAbilityByCall({ + bundleName: "com.example.myservice", + abilityName: "com.example.myservice.MainAbility", + deviceId: "" + }); + let msg = new MyMessageAble(1, "world"); // See the definition of Sequenceable. + caller.call(method, msg) + .then(() => { + console.log('Caller call() called'); + }).catch((e) => { + console.log('Caller call() catch error ' + e); + }); + } + } + ``` + + +### callWithResult + +callWithResult(method, data: rpc.Sequenceable): Promise<rpc.MessageParcel>; + +Sends sequenceable data to the target ability and obtains the sequenceable data returned by the target ability. + +- Parameters + | Name| Type| Mandatory| Description| + | -------- | -------- | -------- | -------- | + | method | string | Yes| Notification message string negotiated between the two abilities. The message is used to instruct the callee to register a function to receive the sequenceable data.| + | data | rpc.Sequenceable | Yes| Sequenceable data. You need to customize the data.| + +- Return value + | Type| Description| + | -------- | -------- | + | Promise<rpc.MessageParcel> | Promise used to return the sequenceable data from the target ability.| + +- Example + + ``` + import Ability from '@ohos.application.Ability'; + class MyMessageAble{ + num: 0 + str: '' + constructor() {} + marshalling(messageParcel) { + messageParcel.writeInt(this.num); + messageParcel.writeString(this.str); + console.log('MyMessageAble marshalling num[' + this.num + '] str[' + this.str + ']'); + return true; + } + unmarshalling(messageParcel) { + this.num = messageParcel.readInt(); + this.str = messageParcel.readString(); + console.log('MyMessageAble unmarshalling num[' + this.num + '] str[' + this.str + ']'); + return true; + } + }; + var method = 'call_Function'; + var caller; + export default class MainAbility extends Ability { + onWindowStageCreate(windowStage) { + caller = await this.context.startAbilityByCall({ + bundleName: "com.example.myservice", + abilityName: "com.example.myservice.MainAbility", + deviceId: "" + }); + let msg = new MyMessageAble(1, "world"); + caller.callWithResult(method, msg) + .then((data) => { + console.log('Caller call() called'); + let retmsg = new MyMessageAble(0, ""); + data.readSequenceable(retmsg); + }).catch((e) => { + console.log('Caller call() catch error ' + e); + }); + } + } + ``` + + +### release + +release(): void; + +Releases the caller interface of the target ability. + +- Example + + ``` + import Ability from '@ohos.application.Ability'; + var caller; + export default class MainAbility extends Ability { + onWindowStageCreate(windowStage) { + caller = await this.context.startAbilityByCall({ + bundleName: "com.example.myservice", + abilityName: "com.example.myservice.MainAbility", + deviceId: "" + }); + try { + caller.release(); + } catch (e) { + console.log('Caller Release error ' + e); + } + } + } + ``` + + +### onRelease + +onRelease(callback: function): void; + +Registers a callback that is invoked when the Stub on the target ability is disconnected. + +- Parameters + | Name| Type| Mandatory| Description| + | -------- | -------- | -------- | -------- | + | callback | function | Yes| Callback used for the **onRelease** method.| + +- Example + + ``` + import Ability from '@ohos.application.Ability'; + var caller; + export default class MainAbility extends Ability { + onWindowStageCreate(windowStage) { + caller = await this.context.startAbilityByCall({ + bundleName: "com.example.myservice", + abilityName: "com.example.myservice.MainAbility", + deviceId: "" + }); + try { + caller.onRelease((str) => { + console.log(' Caller OnRelease CallBack is called ' + str); + }); + } catch (e) { + console.log('Caller Release error ' + e); + } + } + } + ``` + + +## Callee + +Implements callbacks for caller notification registration and unregistration. + + +### on + +on(method: string, callback: function): void; + +Registers a caller notification callback, which is invoked when the target ability registers a function. + +- Parameters + | Name| Type| Mandatory| Description| + | -------- | -------- | -------- | -------- | + | method | string | Yes| Notification message string negotiated between the two abilities.| + | callback | function | Yes| JS notification synchronization callback of the **rpc.MessageParcel** type. The callback must return at least one empty **rpc.Sequenceable** object. Otherwise, the function execution fails.| + +- Example + + ``` + import Ability from '@ohos.application.Ability'; + class MyMessageAble{ + num: 0 + str: '' + constructor() {} + marshalling(messageParcel) { + messageParcel.writeInt(this.num); + messageParcel.writeString(this.str); + console.log('MyMessageAble marshalling num[' + this.num + '] str[' + this.str + ']'); + return true; + } + unmarshalling(messageParcel) { + this.num = messageParcel.readInt(); + this.str = messageParcel.readString(); + console.log('MyMessageAble unmarshalling num[' + this.num + '] str[' + this.str + ']'); + return true; + } + }; + var method = 'call_Function'; + function funcCallBack(pdata) { + console.log('Callee funcCallBack is called ' + pdata); + let msg = new MyMessageAble(0, ""); + pdata.readSequenceable(msg); + return new MyMessageAble(10, "Callee test"); + } + export default class MainAbility extends Ability { + onCreate(want, launchParam) { + console.log('Callee onCreate is called'); + this.callee.on(method, funcCallBack); + } + } + ``` + + +### off + +off(method: string): void; + +Unregisters a caller notification callback, which is invoked when the target ability registers a function. + +- Parameters + | Name| Type| Mandatory| Description| + | -------- | -------- | -------- | -------- | + | method | string | Yes| Registered notification message string.| + +- Example + + ``` + import Ability from '@ohos.application.Ability'; + var method = 'call_Function'; + export default class MainAbility extends Ability { + onCreate(want, launchParam) { + console.log('Callee onCreate is called'); + this.callee.off(method); + } + } + ``` diff --git a/en/application-dev/reference/apis/js-apis-application-abilitystage.md b/en/application-dev/reference/apis/js-apis-application-abilitystage.md new file mode 100644 index 0000000000000000000000000000000000000000..15b3acce30aed572a1deaf316c042739c5ec63ed --- /dev/null +++ b/en/application-dev/reference/apis/js-apis-application-abilitystage.md @@ -0,0 +1,82 @@ +# AbilityStage + +> ![icon-note.gif](public_sys-resources/icon-note.gif) **NOTE** +> The initial APIs of this module are supported since API 9. Newly added APIs will be marked with a superscript to indicate their earliest API version. + + +Runtime class for HAP files. It provides methods to notify you when a HAP file starts loading. You can then initialize the HAP file, for example, pre-load resources and create threads. + + +## Modules to Import + + +``` +import AbilityStage from '@ohos.application.AbilityStage'; +``` + + +## onCreate + +onCreate(): void + +Called when the application is created. + +- Example + + ``` + class MyAbilityStage extends AbilityStage { + onCreate() { + console.log("MyAbilityStage.onCreate is called") + } + } + ``` + + +## onAcceptWant + +onAcceptWant(want: Want): string; + +Called when a specified ability is started. + +- Parameters + | Name| Type| Mandatory| Description| + | -------- | -------- | -------- | -------- | + | want | [Want](js-apis-featureAbility.md#Want)| Yes| Information about the ability to start, such as the ability name and bundle name.| + +- Return value + | Type| Description| + | -------- | -------- | + | string | Returns an ability ID. If this ability has been started, no new instance is created and the ability is placed at the top of the stack. Otherwise, a new instance is created and started.| + +- Example + + ``` + class MyAbilityStage extends AbilityStage { + onAcceptWant(want) { + console.log("MyAbilityStage.onAcceptWant called"); + return "com.example.test"; + } + } + ``` + + +## onConfigurationUpdated + +onConfigurationUpdated(config: Configuration): void; + +Called when the global configuration is updated. + +- Parameters + | Name| Type| Mandatory| Description| + | -------- | -------- | -------- | -------- | + | config | [Configuration](js-apis-configuration.md) | Yes| Callback invoked when the global configuration is updated. The global configuration indicates the configuration of the environment where the application is running and includes the language and color mode.| + +- Example + + ``` + class MyAbilityStage extends AbilityStage { + onConfigurationUpdated(config) { + console.log('onConfigurationUpdated, language:' + config.language); + } + } + ``` diff --git a/en/application-dev/reference/apis/js-apis-application-context.md b/en/application-dev/reference/apis/js-apis-application-context.md new file mode 100644 index 0000000000000000000000000000000000000000..864f1a6d2815dbc154bba4d85679988806f2e55b --- /dev/null +++ b/en/application-dev/reference/apis/js-apis-application-context.md @@ -0,0 +1,72 @@ +# Context + +> ![icon-note.gif](public_sys-resources/icon-note.gif) **NOTE** +> The initial APIs of this module are supported since API version 9. Newly added APIs will be marked with a superscript to indicate their earliest API version. + + +Provides the context for running code, including **applicationInfo** and **resourceManager**. + + +## Usage + + +You must extend **AbilityContext** to implement this module. + + +## Attributes + + | Name| Type| Readable| Writable| Description| +| -------- | -------- | -------- | -------- | -------- | +| resourceManager | ResourceManager | Yes| No| **ResourceManager** object.| +| applicationInfo | ApplicationInfo | Yes| No| Information about the application.| +| cacheDir | string | Yes| No| Cache directory of the application on the internal storage.| +| tempDir | string | Yes| No| Temporary file directory of the application.| +| filesDir | string | Yes| No| File directory of the application on the internal storage.| +| databaseDir | string | Yes| No| Storage directory of local data.| +| storageDir | string | Yes| No| Storage directory of lightweight data.| +| bundleCodeDir | string | Yes| No| Application installation path.| +| distributedFilesDir | string | Yes| No| Storage directory of distributed application data files.| +| eventHub | [EventHub](js-apis-eventhub.md) | Yes| No| Event hub information.| + + +## createBundleContext + +createBundleContext(bundleName: string): Context; + +Creates an application context. + +- **Parameters** + | Name| Type| Mandatory| Description| + | -------- | -------- | -------- | -------- | + | bundleName | string | Yes| Application bundle name.| + +- Return value + | Type| Description| + | -------- | -------- | + | Context | Context of the application created.| + +- Example + + ``` + let test = "com.huawei.test"; + let context = this.context.createBundleContext(test); + ``` + + +## getApplicationContext + +getApplicationContext(): Context; + +Obtains the context of this application. + +- Return value + | Type| Description| + | -------- | -------- | + | Context | Context obtained.| + +- Example + + ``` + // This part is mandatory. + let context = this.context.getApplicationContext(); + ``` diff --git a/en/application-dev/reference/apis/js-apis-appmanager.md b/en/application-dev/reference/apis/js-apis-appmanager.md new file mode 100644 index 0000000000000000000000000000000000000000..b592185ea98594defd19faf7652e02f556c7edbf --- /dev/null +++ b/en/application-dev/reference/apis/js-apis-appmanager.md @@ -0,0 +1,59 @@ +# appManager + +> ![icon-note.gif](public_sys-resources/icon-note.gif) **NOTE** +> The initial APIs of this module are supported since API 8. Newly added APIs will be marked with a superscript to indicate their earliest API version. + + +Implements application management. + + +## Modules to Import + + +``` +import app from '@ohos.application.appManager'; +``` + + +## isRunningInStabilityTest + +static isRunningInStabilityTest(callback: AsyncCallback<boolean>): void + +Checks whether this application is undergoing a stability test. This method uses a callback to return the result. + +- Parameters + | Name| Type| Mandatory| Description| + | -------- | -------- | -------- | -------- | + | callback | AsyncCallback<boolean> | No| Callback used to return the result.| + +- Example + + ``` + import app from '@ohos.application.appManager'; + app.isRunningInStabilityTest((err, flag) => { + console.log('startAbility result:' + JSON.stringfy(err); + } + ``` + + +## isRunningInStabilityTest + +static isRunningInStabilityTest(): Promise<boolean> + +Checks whether this application is undergoing a stability test. This method uses a promise to return the result. + +- Return value + | Type| Description| + | -------- | -------- | + | Promise<boolean> | Promise used to return the result.| + +- Example + + ``` + import app from '@ohos.application.appManager'; + app.isRunningInStabilityTest().then((flag) => { + console.log('success:' + JSON.stringfy(flag)); + )).catch((error) => { + console.log('failed:' + JSON.stringfy(error)); + }); + ``` diff --git a/en/application-dev/reference/apis/js-apis-configuration.md b/en/application-dev/reference/apis/js-apis-configuration.md new file mode 100644 index 0000000000000000000000000000000000000000..e4199544636c77103197529f72de34145756ae5c --- /dev/null +++ b/en/application-dev/reference/apis/js-apis-configuration.md @@ -0,0 +1,26 @@ +# Configuration + +> ![icon-note.gif](public_sys-resources/icon-note.gif) **NOTE** +> The initial APIs of this module are supported since API version 8. Newly added APIs will be marked with a superscript to indicate their earliest API version. + + +Provides the configuration for the environment where the ability is running. + + +## Modules to Import + + +``` +import Configuration from '@ohos.application.Configuration'; +``` + + +## Attributes + + | Name| Type| Readable| Writable| Description| +| -------- | -------- | -------- | -------- | -------- | +| language | string | Yes| Yes| Language of the application.| +| colorMode | [ColorMode](js-apis-configurationconstant.md) | Yes| Yes| Color mode, which can be **COLOR_MODE_LIGHT** or **COLOR_MODE_DARK**. The default value is **COLOR_MODE_LIGHT**.| +| direction | Direction | Yes| No| Screen orientation, which can be **DIRECTION_HORIZONTAL** or **DIRECTION_VERTICAL**.| +| screenDensity | ScreenDensity | Yes| No| Screen resolution, which can be **SCREEN_DENSITY_SDPI** (120), **SCREEN_DENSITY_MDPI** (160), **SCREEN_DENSITY_LDPI** (240), **SCREEN_DENSITY_XLDPI** (320), **SCREEN_DENSITY_XXLDPI** (480), or **SCREEN_DENSITY_XXXLDPI** (640).| +| displayId | number | Yes| No| ID of the display where the application is located.| diff --git a/en/application-dev/reference/apis/js-apis-configurationconstant.md b/en/application-dev/reference/apis/js-apis-configurationconstant.md new file mode 100644 index 0000000000000000000000000000000000000000..0e480eafe47e691044f6eb5095285962322e4a51 --- /dev/null +++ b/en/application-dev/reference/apis/js-apis-configurationconstant.md @@ -0,0 +1,55 @@ +# ConfigurationConstant + +> ![icon-note.gif](public_sys-resources/icon-note.gif) **NOTE** +> The initial APIs of this module are supported since API version 8. Newly added APIs will be marked with a superscript to indicate their earliest API version. + + +Defines enumerated values of the configuration for the environment where the ability is running. + + +## Modules to Import + + +``` +import ConfigurationConstant from '@ohos.application.ConfigurationConstant'; +``` + + +## ColorMode + +To obtain the value, use **ConfigurationConstant.ColorMode**, for example, **ConfigurationConstant.ColorMode.COLOR_MODE_LIGHT**. + + + | Name| Value| Description| +| -------- | -------- | -------- | +| COLOR_MODE_NOT_SET | -1 | Unspecified color mode.| +| COLOR_MODE_DARK | 0 | Dark mode.| +| COLOR_MODE_LIGHT | 1 | Light mode.| + + +## Direction + +To obtain the value, use **ConfigurationConstant.Direction**, for example, **ConfigurationConstant.Direction.DIRECTION_VERTICAL**. + + + | Name| Value| Description| +| -------- | -------- | -------- | +| DIRECTION_NOT_SET | -1 | Unspecified direction.| +| DIRECTION_VERTICAL | 0 | Vertical direction.| +| DIRECTION_HORIZONTAL | 1 | Horizontal direction.| + + +## ScreenDensity + +To obtain the value, use **ConfigurationConstant.ScreenDensity**, for example, **ConfigurationConstant.ScreenDensity.SCREEN_DENSITY_NOT_SET**. + + + | Name| Value| Description| +| -------- | -------- | -------- | +| SCREEN_DENSITY_NOT_SET | 0 | Unspecified screen resolution.| +| SCREEN_DENSITY_SDPI | 120 | The screen resolution is sdpi.| +| SCREEN_DENSITY_MDPI | 160 | The screen resolution is mdpi.| +| SCREEN_DENSITY_LDPI | 240 | The screen resolution is ldpi.| +| SCREEN_DENSITY_XLDPI | 320 | The screen resolution is xldpi.| +| SCREEN_DENSITY_XXLDPI | 480 | The screen resolution is xxldpi.| +| SCREEN_DENSITY_XXXLDPI | 640 | The screen resolution is xxxldpi.| diff --git a/en/application-dev/reference/apis/js-apis-eventhub.md b/en/application-dev/reference/apis/js-apis-eventhub.md new file mode 100644 index 0000000000000000000000000000000000000000..cafe92672be24e015bdd1aeea1a520f70dbf542f --- /dev/null +++ b/en/application-dev/reference/apis/js-apis-eventhub.md @@ -0,0 +1,143 @@ +# EventHub + +> ![icon-note.gif](public_sys-resources/icon-note.gif) **NOTE** +> The initial APIs of this module are supported since API 9. Newly added APIs will be marked with a superscript to indicate their earliest API version. + + +Implements event subscription, unsubscription, and triggering. + + +## Usage + + +Before using any methods in the **EventHub**, you must obtain an **EventHub** instance through the member variable **context** of the **Ability** instance. + + + +``` +import Ability from '@ohos.application.Ability' +export default class MainAbility extends Ability { + onForeground() { + this.context.eventHub.on("123", this.func1); + } +} +``` + + +## on + +on(event: string, callback: Function): void; + +Subscribes to an event. + +**System capabilities**: + +SystemCapability.Ability.AbilityRuntime.Core + +- Parameters + | Name| Type| Mandatory| Description| + | -------- | -------- | -------- | -------- | + | event | string | Yes| Event name.| + | callback | Function | Yes| Callback invoked when the event is triggered.| + +- Example + + ``` + import Ability from '@ohos.application.Ability' + + export default class MainAbility extends Ability { + onForeground() { + this.context.eventHub.on("123", this.func1); + this.context.eventHub.on("123", () => { + console.log("call anonymous func 1"); + }); + // Result + // func1 is called + // call anonymous func 1 + this.context.eventHub.emit("123"); + } + func1() { + console.log("func1 is called"); + } + } + ``` + + +## off + +off(event: string, callback?: Function): void; + +Unsubscribes from an event. If **callback** is specified, this method unsubscribes from the specified callback. If **callback** is not specified, this method unsubscribes from all callbacks in the event. + +**System capabilities**: + +SystemCapability.Ability.AbilityRuntime.Core + +- Parameters + | Name| Type| Mandatory| Description| + | -------- | -------- | -------- | -------- | + | event | string | Yes| Event name.| + | callback | Function | No| Callback for the event. If **callback** is unspecified, all callbacks of the event are unsubscribed.| + +- Example + + ``` + import Ability from '@ohos.application.Ability' + + export default class MainAbility extends Ability { + onForeground() { + this.context.eventHub.on("123", this.func1); + this.context.eventHub.off("123", this.func1); // Unsubscribe from func1. + this.context.eventHub.on("123", this.func1); + this.context.eventHub.on("123", this.func2); + this.context.eventHub.off("123"); // Unsubscribe from func1 and func2. + } + func1() { + console.log("func1 is called"); + } + func2() { + console.log("func2 is called"); + } + } + ``` + + +## emit + +emit(event: string, ...args: Object[]): void; + +Triggers an event. + +**System capabilities**: + +SystemCapability.Ability.AbilityRuntime.Core + +- Parameters + | Name| Type| Mandatory| Description| + | -------- | -------- | -------- | -------- | + | event | string | Yes| Event name.| + | ...args | Object[] | Yes| Variable parameters, which are passed to the callback when the event is triggered.| + +- Example + + ``` + import Ability from '@ohos.application.Ability' + + export default class MainAbility extends Ability { + onForeground() { + this.context.eventHub.on("123", this.func1); + // Result + // func1 is called,undefined,undefined + this.context.eventHub.emit("123"); + // Result + // func1 is called,1,undefined + this.context.eventHub.emit("123", 1); + // Result + // func1 is called,1,2 + this.context.eventHub.emit("123", 1, 2); + } + func1(a: string, b: string) { + console.log("func1 is called," + a + "," + b); + } + } + ``` diff --git a/en/application-dev/reference/apis/js-apis-extensionrunninginfo.md b/en/application-dev/reference/apis/js-apis-extensionrunninginfo.md new file mode 100644 index 0000000000000000000000000000000000000000..ccd1e1f60d41db6c4ebc7978983d27218d044f36 --- /dev/null +++ b/en/application-dev/reference/apis/js-apis-extensionrunninginfo.md @@ -0,0 +1,53 @@ +# ExtensionRunningInfo + +> ![icon-note.gif](public_sys-resources/icon-note.gif) **NOTE** +> The initial APIs of this module are supported since API 8. Newly added APIs will be marked with a superscript to indicate their earliest API version. + + +Provides extension running information. + + +## Usage + + +The extension running information is obtained through an **abilityManager** instance. + + + +``` +import abilitymanager from '@ohos.application.abilityManager'; +abilitymanager.getExtensionRunningInfos(upperLimit, (err,data) => { + console.log("getExtensionRunningInfos err: " + err + " data: " + JSON.stringify(data)); +}); +``` + + +### Attributes + + | Name| Type| Readable| Writable| Description| +| -------- | -------- | -------- | -------- | -------- | +| extension | ElementName | Yes| No| Information that matches an extension.
System capabilities: SystemCapability.Ability.AbilityRuntime.Core| +| pid | number | Yes| No| Process ID.
System capabilities: SystemCapability.Ability.AbilityRuntime.Core| +| uid | number | Yes| No| User ID.
System capabilities: SystemCapability.Ability.AbilityRuntime.Core| +| processName | string | Yes| No| Process name.
System capabilities: SystemCapability.Ability.AbilityRuntime.Core| +| startTime | number | Yes| No| Extension start time.
System capabilities: SystemCapability.Ability.AbilityRuntime.Core| +| clientPackage | Array<String> | Yes| No| Names of all packages in the process.
System capabilities: SystemCapability.Ability.AbilityRuntime.Core| +| type | [bundle.ExtensionAbilityType](#bundle-extensionabilitytype) | Yes| No| Extension type.
System capabilities: SystemCapability.Ability.AbilityRuntime.Core| + + +## bundle.ExtensionAbilityType + +Enumerates the extension types. + + | Name| Value| Description| +| -------- | -------- | -------- | +| FORM | 0 | Extension information of the form type.
System capabilities: SystemCapability.BundleManager.BundleFramework| +| WORK_SCHEDULER | 1 | Extension information of the work scheduler type.
System capabilities: SystemCapability.BundleManager.BundleFramework| +| INPUT_METHOD | 2 | Extension information of the input method type.
System capabilities: SystemCapability.BundleManager.BundleFramework| +| SERVICE | 3 | Extension information of the service type.
System capabilities: SystemCapability.BundleManager.BundleFramework| +| ACCESSIBILITY | 4 | Extension information of the accessibility type.
System capabilities: SystemCapability.BundleManager.BundleFramework| +| DATA_SHARE | 5 | Extension information of the data share type.
System capabilities: SystemCapability.BundleManager.BundleFramework| +| FILE_SHARE | 6 | Extension information of the file share type.
System capabilities: SystemCapability.BundleManager.BundleFramework| +| STATIC_SUBSCRIBER | 7 | Extension information of the static subscriber type.
System capabilities: SystemCapability.BundleManager.BundleFramework| +| WALLPAPER | 8 | Extension information of the wallpaper type.
System capabilities: SystemCapability.BundleManager.BundleFramework| +| UNSPECIFIED | 9 | Extension information of the unspecified type.
System capabilities: SystemCapability.BundleManager.BundleFramework| diff --git a/en/application-dev/reference/apis/js-apis-permissionrequestresult.md b/en/application-dev/reference/apis/js-apis-permissionrequestresult.md new file mode 100644 index 0000000000000000000000000000000000000000..7b598b01680c6044c6238b46e87dad5014151001 --- /dev/null +++ b/en/application-dev/reference/apis/js-apis-permissionrequestresult.md @@ -0,0 +1,15 @@ +# PermissionRequestResult + +> ![icon-note.gif](public_sys-resources/icon-note.gif) **NOTE** +> The initial APIs of this module are supported since API 9. Newly added APIs will be marked with a superscript to indicate their earliest API version. + + +Provides the permission request result. + + +## Attributes + + | Name| Type| Readable| Writable| Description| +| -------- | -------- | -------- | -------- | -------- | +| permissions | Array<string> | Yes| No| Permissions requested.
System capabilities: SystemCapability.Ability.AbilityRuntime.Core| +| authResults | Array<number> | Yes| No| Whether the requested permissions are granted or denied. The value **0** means that the requests permissions are granted, and **-1** means the opposite.
System capabilities: SystemCapability.Ability.AbilityRuntime.Core| diff --git a/en/application-dev/reference/apis/js-apis-processrunninginfo.md b/en/application-dev/reference/apis/js-apis-processrunninginfo.md new file mode 100644 index 0000000000000000000000000000000000000000..06085f7626aafb3091eca98b9ff2f23b903e98cb --- /dev/null +++ b/en/application-dev/reference/apis/js-apis-processrunninginfo.md @@ -0,0 +1,32 @@ +# ProcessRunningInfo + +> ![icon-note.gif](public_sys-resources/icon-note.gif) **NOTE** +> The initial APIs of this module are supported since API 8. Newly added APIs will be marked with a superscript to indicate their earliest API version. + + +Provides process running information. + + +## Usage + + +The process running information is obtained through an **appManager** instance. + + + +``` +import appManager from '@ohos.application.appManager'; +appManager.getProcessRunningInfos((error,data) => { + console.log("getProcessRunningInfos error: " + error.code + " data: " + JSON.stringify(data)); +}); +``` + + +## Attributes + + | Name| Type| Readable| Writable| Description| +| -------- | -------- | -------- | -------- | -------- | +| pid | number | Yes| No| Process ID.
System capabilities: SystemCapability.Ability.AbilityRuntime.Core| +| uid | number | Yes| No| User ID.
System capabilities: SystemCapability.Ability.AbilityRuntime.Core| +| processName | string | Yes| No| Process name.
System capabilities: SystemCapability.Ability.AbilityRuntime.Core| +| bundleNames | Array<string> | Yes| No| Names of all bundles running in the process.
System capabilities: SystemCapability.Ability.AbilityRuntime.Core| diff --git a/en/application-dev/reference/apis/js-apis-uripermissionmanager.md b/en/application-dev/reference/apis/js-apis-uripermissionmanager.md new file mode 100644 index 0000000000000000000000000000000000000000..c3b7e18f36ca6cd1f7746291c68556ddcba5a360 --- /dev/null +++ b/en/application-dev/reference/apis/js-apis-uripermissionmanager.md @@ -0,0 +1,78 @@ +# UriPermissionManager + +> ![icon-note.gif](public_sys-resources/icon-note.gif) **NOTE** +> The initial APIs of this module are supported since API 9. Newly added APIs will be marked with a superscript to indicate their earliest API version. + + +Implements URI permission management. + + +## Modules to Import + + +``` +import UriPermissionManager from '@@ohos.application.UriPermissionManager'; +``` + + +## verifyUriPermission + +verifyUriPermission(uri: string, flag: wantConstant.Flags, accessTokenId: number, callback: AsyncCallback<number>): void + +Checks whether an application has the permission specified by **flag** for an URI. This method uses a callback to return the result. + +**System capabilities**: + +SystemCapability.Ability.AbilityRuntime.Core + +- Parameters + | Name| Type| Mandatory| Description| + | -------- | -------- | -------- | -------- | + | uri | string | Yes| URI of a file, for example, **fileshare:///com.samples.filesharetest.FileShare/person/10**.| + | flag | wantConstant.Flags | Yes| Read or write permission on the file specified by the URI.| + | accessTokenId | number | Yes| Unique ID of an application, which is obtained through the **BundleManager** API.| + | callback | AsyncCallback<number> | Yes| Callback used to return the check result. The value **0** means that the application has the specified permission, and **-1** means the opposite.| + +- Example + + ``` + let uri = "fileshare:///com.samples.filesharetest.FileShare/person/10" + UriPermissionManager.verifyUriPermission(uri, wantConstant.Flags.FLAG_AUTH_READ_URI_PERMISSION, accessTokenId, (result) => { + console.log("result.code = " + result.code) + }) // accessTokenId is obtained through the **BundleManager** API. + ``` + + +## verifyUriPermission + +verifyUriPermission(uri: string, flag: wantConstant.Flags, accessTokenId: number): Promise<number> + +Checks whether an application has the permission specified by **flag** for an URI. This method uses a promise to return the result. + +**System capabilities**: + +SystemCapability.Ability.AbilityRuntime.Core + +- Parameters + | Name| Type| Mandatory| Description| + | -------- | -------- | -------- | -------- | + | uri | string | Yes| URI of a file, for example, **fileshare:///com.samples.filesharetest.FileShare/person/10**.| + | flag | wantConstant.Flags | Yes| Read or write permission on the file specified by the URI.| + | accessTokenId | number | Yes| Unique ID of an application, which is obtained through the **BundleManager** API.| + +- Return value + | Type| Description| + | -------- | -------- | + | Promise<number> | Promise used to return the check result. The value **0** means that the application has the specified permission, and **-1** means the opposite.| + +- Example + + ``` + let uri = "fileshare:///com.samples.filesharetest.FileShare/person/10" + UriPermissionManager.verifyUriPermission(uri, wantConstant.Flags.FLAG_AUTH_READ_URI_PERMISSION, accessTokenId) + .then((data) => { + console.log('Verification succeeded.' + data) + }).catch((error) => { + console.log('Verification failed.'); + }) + ```