提交 87cc5d2e 编写于 作者: 关明月 提交者: Gitee

Merge branch 'OpenHarmony-3.1-Release' of gitee.com:openharmony/docs into OpenHarmony-3.1-Release

Signed-off-by: N关明月 <guanmingyue@huawei.com>
# Data Ability Development
## When to Use
A Data ability helps applications manage access to data stored by themselves and other applications. It also provides APIs for sharing data with other applications either on the same device or across devices.
Data ability providers can customize data access-related APIs such as data inserting, deleting, updating, and querying, as well as file opening, and share data with other applications through these open APIs.
## Available APIs
**Table 1** Data ability lifecycle APIs
......@@ -18,7 +21,7 @@ Data ability providers can customize data access-related APIs such as data inser
|denormalizeUri?(uri: string, callback: AsyncCallback\<string>): void|Converts a normalized URI generated by **normalizeUri** into a denormalized URI.|
|insert?(uri: string, valueBucket: rdb.ValuesBucket, callback: AsyncCallback\<number>): void|Inserts a data record into the database.|
|openFile?(uri: string, mode: string, callback: AsyncCallback\<number>): void|Opens a file.|
|getFileTypes?(uri: string, mimeTypeFilter: string, callback: AsyncCallback\<Array\<string>>): void|Obtains the MIME type of a file.|
|getFileTypes?(uri: string, mimeTypeFilter: string, callback: AsyncCallback<Array\<string>>): void|Obtains the MIME type of a file.|
|getType?(uri: string, callback: AsyncCallback\<string>): void|Obtains the MIME type matching the data specified by the URI.|
|executeBatch?(ops: Array\<DataAbilityOperation>, callback: AsyncCallback\<Array\<DataAbilityResult>>): void|Operates data in the database in batches.|
|call?(method: string, arg: string, extras: PacMap, callback: AsyncCallback\<PacMap>): void|Calls a custom API.|
......@@ -115,7 +118,7 @@ Import the basic dependency packages and obtain the URI string for communicating
The basic dependency packages include:
- @ohos.ability.featureAbility
- @ohos.data.dataability
- @ohos.data.dataAbility
- @ohos.data.rdb
#### Data Ability API Development
......
# Ability Development
## When to Use
Unlike the FA model, the [stage model](stage-brief.md) requires you to declare the application package structure in the `module.json` and `app.json` files during application development. For details about the configuration file, see [Application Package Structure Configuration File](../quick-start/stage-structure.md). To develop abilities based on the stage model, implement the following logic:
- Create abilities for an application that involves screen viewing and human-machine interaction. You must implement the following scenarios: ability lifecycle callbacks, obtaining ability configuration, requesting permissions, and notifying environment changes.
Ability development in the [stage model](stage-brief.md) is significantly different from that in the FA model. The stage model requires you to declare the application package structure in the `module.json` and `app.json` files during application development. For details about the configuration file, see [Application Package Structure Configuration File](../quick-start/stage-structure.md). To develop an ability based on the stage model, implement the following logic:
- Create an ability that supports screen viewing and human-machine interaction. You must implement the following scenarios: ability lifecycle callbacks, obtaining ability configuration, requesting permissions, and notifying environment changes.
- Start an ability. You need to implement ability startup on the same device, on a remote device, or with a specified UI page.
- Call abilities. For details, see [Call Development](stage-call.md).
- Connect to and disconnect from a Service Extension ability. For details, see [Service Extension Ability Development](stage-serviceextension.md).
- Continue the ability on another device. For details, see [Ability Continuation Development](stage-ability-continuation.md).
### Launch Type
The ability supports three launch types: singleton, multi-instance, and instance-specific. Each launch type, specified by `launchType` in the `module.json` file, specifies the action that can be performed when the ability is started.
An ability can be launched in the **standard**, **singleton**, or **specified** mode, as configured by `launchType` in the `module.json` file. Depending on the launch type, the action performed when the ability is started differs, as described below.
| Launch Type | Description |Description |
| Launch Type | Description |Action |
| ----------- | ------- |---------------- |
| standard | Multi-instance | A new instance is started each time an ability starts.|
| singleton | Singleton | Only one instance exists in the system. If an instance already exists when an ability is started, that instance is reused.|
| singleton | Singleton | The ability has only one instance in the system. If an instance already exists when an ability is started, that instance is reused.|
| specified | Instance-specific| The internal service of an ability determines whether to create multiple instances during running.|
By default, the singleton mode is used. The following is an example of the `module.json` file:
......@@ -58,7 +58,7 @@ To create Page abilities for an application in the stage model, you must impleme
```
import AbilityStage from "@ohos.application.AbilityStage"
```
2. Implement the `AbilityStage` class.
2. Implement the `AbilityStage` class. The default relative path generated by the APIs is **entry\src\main\ets\Application\AbilityStage.ts**.
```ts
export default class MyAbilityStage extends AbilityStage {
onCreate() {
......@@ -70,7 +70,7 @@ To create Page abilities for an application in the stage model, you must impleme
```js
import Ability from '@ohos.application.Ability'
```
4. Implement the lifecycle callbacks of the `Ability` class.
4. Implement the lifecycle callbacks of the `Ability` class. The default relative path generated by the APIs is **entry\src\main\ets\MainAbility\MainAbility.ts**.
In the `onWindowStageCreate(windowStage)` API, use `loadContent` to set the application page to be loaded. For details about how to use the `Window` APIs, see [Window Development](../windowmanager/window-guidelines.md).
```ts
......@@ -86,8 +86,8 @@ To create Page abilities for an application in the stage model, you must impleme
onWindowStageCreate(windowStage) {
console.log("MainAbility onWindowStageCreate")
windowStage.loadContent("pages/index").then((data) => {
console.log("MainAbility load content succeed with data: " + JSON.stringify(data))
windowStage.loadContent("pages/index").then(() => {
console.log("MainAbility load content succeed")
}).catch((error) => {
console.error("MainAbility load content failed with error: "+ JSON.stringify(error))
})
......@@ -140,14 +140,14 @@ export default class MainAbility extends Ability {
console.log("MainAbility ability name" + abilityInfo.name)
let config = this.context.config
console.log("MyAbilityStage config language" + config.language)
console.log("MainAbility config language" + config.language)
}
}
```
### Requesting Permissions
If an application needs to obtain user privacy information or use system capabilities, for example, obtaining location information or using the camera to take photos or record videos, it must request the permission from consumers. During application development, you need to specify the involved sensitive permissions, declare the required permissions in `module.json`, and use the `requestPermissionsFromUser` API to request the permission from consumers in the form of a dialog box. The following uses the permissions for calendar access as an example.
If an application needs to obtain user privacy information or use system capabilities, for example, obtaining location information or using the camera to take photos or record videos, it must request the respective permission from consumers. During application development, you need to specify the involved sensitive permissions, declare the required permissions in `module.json`, and use the `requestPermissionsFromUser` API to request the permission from consumers in the form of a dialog box. The following uses the permission for calendar access as an example.
Declare the required permissions in the `module.json` file.
Declare the required permission in the `module.json` file.
```json
"requestPermissions": [
{
......@@ -155,7 +155,7 @@ Declare the required permissions in the `module.json` file.
}
]
```
Request the permissions from consumers in the form of a dialog box:
Request the permission from consumers in the form of a dialog box:
```ts
let context = this.context
let permissions: Array<string> = ['ohos.permission.READ_CALENDAR']
......@@ -166,11 +166,11 @@ context.requestPermissionsFromUser(permissions).then((data) => {
})
```
### Notifying of Environment Changes
Environment changes include changes of global configurations and ability configurations. Currently, the global configurations include the system language and color mode. The change of global configurations is generally triggered by the configuration item in **Settings** or the icon in **Control Panel**. The ability configuration is specific to a single `Ability` instance, including the display ID, screen resolution, and screen orientation. The configuration is related to the display where the ability is located, and the change is generally triggered by the window. For details on the configuration, see [Configuration](../reference/apis/js-apis-configuration.md).
Environment changes include changes of global configurations and ability configurations. Currently, the global configurations include the system language and color mode. The change of global configurations is generally triggered by configuration items in **Settings** or icons in **Control Panel**. The ability configuration is specific to a single `Ability` instance, including the display ID, screen resolution, and screen orientation. The configuration is related to the display where the ability is located, and the change is generally triggered by the window. For details on the configuration, see [Configuration](../reference/apis/js-apis-configuration.md).
For an application in the stage model, when the configuration changes, its abilities are not restarted, but the `onConfigurationUpdated(config: Configuration)` callback is triggered. If the application needs to perform processing based on the change, you can overwrite `onConfigurationUpdated`. Note that the `Configuration` object in the callback contains all the configurations of the current ability, not only the changed configurations.
The following example shows the implement of the `onConfigurationUpdated` callback in the `AbilityStage` class. The callback is triggered when the system language and color mode are changed.
The following example shows the implementation of the `onConfigurationUpdated` callback in the `AbilityStage` class. The callback is triggered when the system language and color mode are changed.
```ts
import Ability from '@ohos.application.Ability'
import ConfigurationConstant from '@ohos.application.ConfigurationConstant'
......@@ -184,7 +184,7 @@ export default class MyAbilityStage extends AbilityStage {
}
```
The following example shows the implement of the `onConfigurationUpdated` callback in the `Ability` class. The callback is triggered when the system language, color mode, or display parameters (such as the direction and density) change.
The following example shows the implementation of the `onConfigurationUpdated` callback in the `Ability` class. The callback is triggered when the system language, color mode, or display parameters (such as the direction and density) change.
```ts
import Ability from '@ohos.application.Ability'
import ConfigurationConstant from '@ohos.application.ConfigurationConstant'
......@@ -205,7 +205,7 @@ export default class MainAbility extends Ability {
```
## Starting an Ability
### Available APIs
The `Ability` class has the `context` attribute, which belongs to the `AbilityContext` class. The `AbilityContext` class has the `abilityInfo`, `currentHapModuleInfo`, and other attributes and the APIs used for starting abilities. For details, see [AbilityContext](../reference/apis/js-apis-ability-context.md).
The `Ability` class has the `context` attribute, which belongs to the `AbilityContext` class. The `AbilityContext` class has the `abilityInfo`, `currentHapModuleInfo`, and other attributes as well as the APIs used for starting abilities. For details, see [AbilityContext](../reference/apis/js-apis-ability-context.md).
**Table 3** AbilityContext APIs
|API|Description|
......@@ -227,17 +227,16 @@ var want = {
"bundleName": "com.example.MyApplication",
"abilityName": "MainAbility"
};
context.startAbility(want).then((data) => {
console.log("Succeed to start ability with data: " + JSON.stringify(data))
context.startAbility(want).then(() => {
console.log("Succeed to start ability")
}).catch((error) => {
console.error("Failed to start ability with error: "+ JSON.stringify(error))
})
```
### Starting an Ability on a Remote Device
This feature applies only to system applications, since the `getTrustedDeviceListSync` API of the `DeviceManager` class is open only to system applications.
>This feature applies only to system applications, since the `getTrustedDeviceListSync` API of the `DeviceManager` class is open only to system applications.
In the cross-device scenario, you must specify the ID of the remote device. The sample code is as follows:
```ts
let context = this.context
var want = {
......@@ -245,8 +244,8 @@ var want = {
"bundleName": "com.example.MyApplication",
"abilityName": "MainAbility"
};
context.startAbility(want).then((data) => {
console.log("Succeed to start remote ability with data: " + JSON.stringify(data))
context.startAbility(want).then(() => {
console.log("Succeed to start remote ability")
}).catch((error) => {
console.error("Failed to start remote ability with error: " + JSON.stringify(error))
})
......@@ -268,9 +267,9 @@ function getRemoteDeviceId() {
}
}
```
Request the permission `ohos.permission.DISTRIBUTED_DATASYNC ` from consumers. This permission is used for data synchronization. For details about the sample code for requesting the permission, see [Requesting Permissions](##requesting-permissions).
Request the permission `ohos.permission.DISTRIBUTED_DATASYNC` from consumers. This permission is used for data synchronization. For details about the sample code for requesting the permission, see [Requesting Permissions](##requesting-permissions).
### Starting an Ability with the Specified Page
If the launch type of an ability is set to `singleton` and the ability has been started, the `onNewWant` callback is triggered when the ability is started again. You can pass start options through the `want`. For example, to start an ability with the specified page, use the `uri` or `parameters` parameter in the `want` to pass the page information. Currently, the ability in the stage model cannot directly use the `router` capability. You must pass the start options to the custom component and invoke the `router` method to display the specified page during the custom component lifecycle management. The sample code is as follows:
If the launch type of an ability is set to `singleton` and the ability has been started, the `onNewWant` callback rather than the `onCreate` callback is triggered when the ability is started again. You can pass start options through the `want`. For example, to start an ability with the specified page, use the `uri` or `parameters` parameter in the `want` to pass the page information. Currently, the ability in the stage model cannot directly use the `router` capability. You must pass the start options to the custom component and invoke the `router` method to display the specified page during the custom component lifecycle management. The sample code is as follows:
When using `startAbility` to start an ability again, use the `uri` parameter in the `want` to pass the page information.
```ts
......@@ -312,7 +311,7 @@ struct Index {
console.info('Index onPageShow')
let newWant = globalThis.newWant
if (newWant.hasOwnProperty("uri")) {
router.push({ uri: newWant.uri });
router.push({ url: newWant.uri });
globalThis.newWant = undefined
}
}
......
......@@ -26,7 +26,7 @@ OpenHarmony does not support creation of a Service Extension ability for third-p
1. Create a Service Extension ability.
2. Customize a class that inherits from **ServiceExtensionAbility** in the .ts file in the directory where the Service Extension ability is defined and override the lifecycle callbacks of the base class. The code sample is as follows:
2. Customize a class that inherits from **ServiceExtensionAbility** in the .ts file in the directory where the Service Extension ability is defined (**entry\src\main\ets\ServiceExtAbility\ServiceExtAbility.ts** by default) and override the lifecycle callbacks of the base class. The code sample is as follows:
```js
import rpc from '@ohos.rpc'
......
......@@ -37,7 +37,7 @@
"reqPermissions":[
{
"name":"ohos.permission.ACCELEROMETER",
"reason"":"",
"reason":"",
"usedScene":{
"ability": ["sensor.index.MainAbility",".MainAbility"],
"when":"inuse"
......@@ -45,7 +45,7 @@
},
{
"name":"ohos.permission.GYROSCOPE",
"reason"":"",
"reason":"",
"usedScene":{
"ability": ["sensor.index.MainAbility",".MainAbility"],
"when":"inuse"
......@@ -53,7 +53,7 @@
},
{
"name":"ohos.permission.ACTIVITY_MOTION",
"reason"":"ACTIVITY_MOTION_TEST",
"reason":"ACTIVITY_MOTION_TEST",
"usedScene":{
"ability": ["sensor.index.MainAbility",".MainAbility"],
"when":"inuse"
......@@ -61,7 +61,7 @@
},
{
"name":"ohos.permission.READ_HEALTH_DATA",
"reason"":"HEALTH_DATA_TEST",
"reason":"HEALTH_DATA_TEST",
"usedScene":{
"ability": ["sensor.index.MainAbility",".MainAbility"],
"when":"inuse"
......
......@@ -1141,8 +1141,8 @@ SystemCapability.BundleManager.BundleFramework
**Example**
```js
let bundleName = com.example.myapplication;
let abilityName = com.example.myapplication.MainAbility;
let bundleName = "com.example.myapplication";
let abilityName = "com.example.myapplication.MainAbility";
bundle.getAbilityIcon(bundleName, abilityName)
.then((data) => {
console.info('Operation successful. Data: ' + JSON.stringify(data));
......@@ -1176,8 +1176,8 @@ SystemCapability.BundleManager.BundleFramework
**Example**
```js
let bundleName = com.example.myapplication;
let abilityName = com.example.myapplication.MainAbility;
let bundleName = "com.example.myapplication";
let abilityName = "com.example.myapplication.MainAbility";
bundle.getAbilityIcon(bundleName, abilityName, (err, data) => {
if (err) {
console.error('Operation failed. Cause: ' + JSON.stringify(err));
......
......@@ -126,7 +126,7 @@ var options = {
windowMode: 0,
};
this.context.startAbility(want, options)
.then((data) => {
.then(() => {
console.log('Operation successful.')
}).catch((error) => {
console.log('Operation failed.');
......@@ -273,7 +273,7 @@ var options = {
};
var accountId = 11;
this.context.startAbility(want, accountId, options)
.then((data) => {
.then(() => {
console.log('Operation successful.')
}).catch((error) => {
console.log('Operation failed.');
......@@ -352,7 +352,7 @@ Starts an ability with **options** specified. This API uses a promise to return
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| want | [Want](js-apis-featureAbility.md#Want) | Yes| Information about the **Want** used for starting an ability.|
| options | StartOptions | Yes| Parameters used for starting the ability.|
| options | StartOptions | No | Parameters used for starting the ability.|
**Return value**
......@@ -511,8 +511,8 @@ Terminates this ability. This API uses a promise to return the result.
**Example**
```js
this.context.terminateSelf(want).then((data) => {
console.log('success:' + JSON.stringify(data));
this.context.terminateSelf(want).then(() => {
console.log('success:');
}).catch((error) => {
console.log('failed:' + JSON.stringify(error));
});
......@@ -571,7 +571,7 @@ this.context.terminateSelfWithResult(
{
want: {bundleName: "com.extreme.myapplication", abilityName: "MainAbilityDemo"},
resultCode: 100
}).then((result) => {
}).then(() => {
console.log("terminateSelfWithResult")
})
```
......@@ -595,7 +595,7 @@ Uses the **AbilityInfo.AbilityType.SERVICE** template to connect this ability to
| Type| Description|
| -------- | -------- |
| number | ID of the connection between the two abilities.|
| number | Result code of the ability connection.|
**Example**
```js
......@@ -606,7 +606,7 @@ var want = {
}
var options = {
onConnect: (elementName, remote) => {
console.log('connectAbility onConnect, elementName: ' + elementName + ', remote: ' remote)
console.log('connectAbility onConnect, elementName: ' + elementName + ', remote: ' + remote)
},
onDisconnect: (elementName) => {
console.log('connectAbility onDisconnect, elementName: ' + elementName)
......@@ -615,8 +615,8 @@ var options = {
console.log('connectAbility onFailed, code: ' + code)
}
}
this.context.connectAbility(want, options) {
console.log('code: ' + code)
let result = this.context.connectAbility(want, options) {
console.log('code: ' + result)
}
```
......@@ -652,7 +652,7 @@ var want = {
var accountId = 111;
var options = {
onConnect: (elementName, remote) => {
console.log('connectAbility onConnect, elementName: ' + elementName + ', remote: ' remote)
console.log('connectAbility onConnect, elementName: ' + elementName + ', remote: ' + remote)
},
onDisconnect: (elementName) => {
console.log('connectAbility onDisconnect, elementName: ' + elementName)
......@@ -768,8 +768,8 @@ Sets the label of the ability in the mission. This API uses a promise to return
**Example**
```js
this.context.setMissionLabel("test").then((data) => {
console.log('success:' + JSON.stringify(data));
this.context.setMissionLabel("test").then(() => {
console.log('success:');
}).catch((error) => {
console.log('failed:' + JSON.stringify(error));
});
......
# Want
> ![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.
**Want** is the basic communication component of the system.
The **Want** module provides the basic communication component of the system.
> **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.
## Modules to Import
```
import Want from '@ohos.application.Want';
```
......@@ -20,11 +19,55 @@ import Want from '@ohos.application.Want';
| Name | Readable/Writable| Type | Mandatory| Description |
| ----------- | -------- | -------------------- | ---- | ------------------------------------------------------------ |
| deviceId | Read only | string | No | ID of the device running the ability. |
| bundleName | Read only | string | No | Bundle name of the ability. If both **bundleName** and **abilityName** are specified in a **Want** object, the **Want** object can directly match the specified ability.|
| abilityName | Read only | string | No | Name of the ability. If both **bundleName** and **abilityName** are specified in a **Want** object, the **Want** object can directly match the specified ability.|
| bundleName | Read only | string | No | Bundle name of the ability. If both **bundleName** and **abilityName** are specified in a **Want** object, the **Want** object can match a specific ability.|
| abilityName | Read only | string | No | Name of the ability. If both **bundleName** and **abilityName** are specified in a **Want** object, the **Want** object can match a specific ability.|
| uri | Read only | string | No | URI information to match. If **uri** is specified in a **Want** object, the **Want** object will match the specified URI information, including **scheme**, **schemeSpecificPart**, **authority**, and **path**.|
| type | Read only | string | No | MIME type, for example, **text/plain** or **image/***. |
| flags | Read only | number | No | How the **Want** object will be handled. By default, numbers are passed in. For details, see [flags](js-apis-featureAbility.md#flags).|
| flags | Read only | number | No | How the **Want** object will be handled. For details, see [flags](js-apis-featureAbility.md#flags).|
| action | Read only | string | No | Action option. |
| parameters | Read only | {[key: string]: any} | No | List of parameters in the **Want** object. |
| entities | Read only | Array\<string> | No | List of entities. | |
| entities | Read only | Array\<string> | No | List of entities. |
| extensionAbilityType<sup>9+</sup> | Read only | bundle.ExtensionAbilityType | No | Type of the Extension ability. |
| extensionAbilityName<sup>9+<sup> | Read only | string | No | Description of the Extension ability name in the **Want** object. |
**Example**
- Basic usage
```js
var want = {
"deviceId": "", // An empty deviceId indicates the local device.
"bundleName": "com.extreme.test",
"abilityName": "MainAbility",
"uri": "pages/second" // uri is optional and can be used to pass the destination URI.
};
this.context.startAbility(want, (error) => {
// Start an ability explicitly. The bundleName, abilityName, and moduleName parameters work together to uniquely identify an ability.
console.log("error.code = " + error.code)
})
```
- Passing a file descriptor (FD)
```js
var fd;
try {
fd = fileio.openSync("/data/storage/el2/base/haps/pic.png");
} catch(e) {
console.log("openSync fail:" + JSON.stringify(e));
}
var want = {
"deviceId": "", // An empty deviceId indicates the local device.
"bundleName": "com.extreme.test",
"abilityName": "MainAbility",
"parameters": {
"keyFd":{"type":"FD", "value":fd}
}
};
this.context.startAbility(want, (error) => {
// Start an ability explicitly. The bundleName, abilityName, and moduleName parameters work together to uniquely identify an ability.
console.log("error.code = " + error.code)
})
```
\ No newline at end of file
......@@ -21,8 +21,8 @@ import Ability from '@ohos.application.Ability';
| 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.|
| launchWant | [Want](js-apis-application-want.md)| Yes| No| Parameters for starting the ability.|
| lastRequestWant | [Want](js-apis-application-want.md)| Yes| No| Parameters used when the ability was started last time.|
## Ability.onCreate
......@@ -37,7 +37,7 @@ Called to initialize the service logic when an ability is created.
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| want | [Want](js-apis-featureAbility.md#Want)| Yes| Information related to this ability, including the ability name and bundle name.|
| want | [Want](js-apis-application-want.md)| Yes| Information related to this ability, including the ability name and bundle name.|
| param | AbilityConstant.LaunchParam | Yes| Parameters for starting the ability, and the reason for the last abnormal exit.|
**Example**
......@@ -222,7 +222,7 @@ Called when the ability startup mode is set to singleton.
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| want | [Want](js-apis-featureAbility.md#Want)| Yes| Want parameters, such as the ability name and bundle name.|
| want | [Want](js-apis-application-want.md)| Yes| Want parameters, such as the ability name and bundle name.|
**Example**
......
# AbilityInfo
Unless otherwise specified, ability information is obtained through **GET_BUNDLE_DEFAULT**.
> **NOTE**
>
> The initial APIs of this module are supported since API version 7. Newly added APIs will be marked with a superscript to indicate their earliest API version.
>
> API version 9 is a canary version for trial use. The APIs of this version may be unstable.
Provides the ability information.
## AbilityInfo
**System capability**: SystemCapability.BundleManager.BundleFramework
**System capability**: SystemCapability.BundleManager.BundleFramework
| Name | Type | Readable| Writable| Description |
| --------------------- | -------------------------------------------------------- | ---- | ---- | ----------------------------------------- |
......@@ -30,15 +30,16 @@ Provides the ability information.
| type | AbilityType | Yes | No | Ability type. |
| orientation | DisplayOrientation | Yes | No | Ability display orientation. |
| launchMode | LaunchMode | Yes | No | Ability launch mode. |
| permissions | Array\<string> | Yes | No | Permissions required for other applications to call the ability.|
| permissions | Array\<string> | Yes | No | Permissions required for other applications to call the ability.<br>The value is obtained by passing **GET_ABILITY_INFO_WITH_PERMISSION**.|
| deviceTypes | Array\<string> | Yes | No | Device types supported by the ability. |
| deviceCapabilities | Array\<string> | Yes | No | Device capabilities required for the ability. |
| readPermission | string | Yes | No | Permission required for reading the ability data. |
| writePermission | string | Yes | No | Permission required for writing data to the ability. |
| applicationInfo | ApplicationInfo | Yes | No | Application configuration information. |
| applicationInfo | ApplicationInfo | Yes | No | Application configuration information.<br>The value is obtained by passing **GET_ABILITY_INFO_WITH_APPLICATION**.|
| uri | string | Yes | No | URI of the ability. |
| labelId | number | Yes | No | Ability label ID. |
| subType | AbilitySubType | Yes | No | Subtype of the template that can be used by the ability. |
| metaData<sup>8+</sup> | Array\<[CustomizeData](js-apis-bundle-CustomizeData.md)> | Yes | No | Custom metadata of the ability. |
| metadata<sup>9+</sup> | Array\<[Metadata](js-apis-bundle-Metadata.md)> | Yes | No | Metadata of the ability. |
| metaData<sup>8+</sup> | Array\<[CustomizeData](js-apis-bundle-CustomizeData.md)> | Yes | No | Custom metadata of the ability.<br>The value is obtained by passing **GET_ABILITY_INFO_WITH_METADATA**.|
| metadata<sup>9+</sup> | Array\<[Metadata](js-apis-bundle-Metadata.md)> | Yes | No | Metadata of the ability.<br>The value is obtained by passing **GET_ABILITY_INFO_WITH_METADATA**.|
| enabled<sup>8+</sup> | boolean | Yes | No | Whether the ability is enabled. |
# ApplicationInfo
The **ApplicationInfo** module provides application information. Unless otherwise specified, all attributes are obtained through **GET_BUNDLE_DEFAULT**.
> **NOTE**
>
> The initial APIs of this module are supported since API version 7. Newly added APIs will be marked with a superscript to indicate their earliest API version.
>
> API version 9 is a canary version for trial use. The APIs of this version may be unstable.
Provides the application information.
## ApplicationInfo
**System capability**: SystemCapability.BundleManager.BundleFramework
| Name | Type | Readable| Writable| Description |
| -------------------------- | ------------------------------------------------------------ | ---- | ---- | ------------------------------------------ |
| -------------------------- | ------------------------------------------------------------ | ---- | ---- | ------------------------------------------------------------ |
| name | string | Yes | No | Application name. |
| description | string | Yes | No | Application description. |
| descriptionId | number | Yes | No | Application description ID. |
......@@ -23,15 +23,15 @@ Provides the application information.
| labelId | string | Yes | No | Application label ID. |
| icon | string | Yes | No | Application icon. |
| iconId | string | Yes | No | Application icon ID. |
| process | string | Yes | No | Process in which the application runs. If this parameter is not set, the bundle name is used.|
| process | string | Yes | No | Process in which the application runs. If this parameter is not set, the bundle name is used. |
| supportedModes | number | Yes | No | Running modes supported by the application. |
| moduleSourceDirs | Array\<string> | Yes | No | Relative paths for storing application resources. |
| permissions | Array\<string> | Yes | No | Permissions required for accessing the application. |
| permissions | Array\<string> | Yes | No | Permissions required for accessing the application.<br>The value is obtained by passing **GET_APPLICATION_INFO_WITH_PERMISSION**.|
| moduleInfos | Array\<[ModuleInfo](js-apis-bundle-ModuleInfo.md)> | Yes | No | Application module information. |
| entryDir | string | Yes | No | Path for storing application files. |
| codePath<sup>8+</sup> | string | Yes | No | Installation directory of the application. |
| metaData<sup>8+</sup> | Map\<string, Array\<[CustomizeData](js-apis-bundle-CustomizeData.md)>> | Yes | No | Custom metadata of the application. |
| metadata<sup>9+</sup> | Map\<string, Array\<[Metadata](js-apis-bundle-Metadata.md)>> | Yes | No | Metadata of the application. |
| metaData<sup>8+</sup> | Map\<string, Array\<[CustomizeData](js-apis-bundle-CustomizeData.md)>> | Yes | No | Custom metadata of the application.<br>The value is obtained by passing **GET_APPLICATION_INFO_WITH_METADATA**.|
| metadata<sup>9+</sup> | Map\<string, Array\<[Metadata](js-apis-bundle-Metadata.md)>> | Yes | No | Metadata of the application.<br>The value is obtained by passing **GET_APPLICATION_INFO_WITH_METADATA**.|
| removable<sup>8+</sup> | boolean | Yes | No | Whether the application is removable. |
| accessTokenId<sup>8+</sup> | number | Yes | No | Access token ID of the application. |
| uid<sup>8+</sup> | number | Yes | No | UID of the application. |
......
# BundleInfo
The **BundleInfo** module provides bundle information. Unless otherwise specified, all attributes are obtained through **GET_BUNDLE_DEFAULT**.
> **NOTE**
>
> The initial APIs of this module are supported since API version 7. Newly added APIs will be marked with a superscript to indicate their earliest API version.
>
> API version 9 is a canary version for trial use. The APIs of this version may be unstable.
Provides the application bundle information.
## BundleInfo
**System capability**: SystemCapability.BundleManager.BundleFramework
| Name | Type | Readable| Writable| Description |
| --------------------------------- | ------------------------------------------------------------ | ---- | ---- | ------------------------------------------ |
| --------------------------------- | ------------------------------------------------------------ | ---- | ---- | ------------------------------------------------------------ |
| name | string | Yes | No | Bundle name. |
| type | string | Yes | No | Bundle type. |
| appId | string | Yes | No | ID of the application to which the bundle belongs. |
......@@ -21,9 +21,9 @@ Provides the application bundle information.
| installTime | number | Yes | No | Time when the HAP file was installed. |
| updateTime | number | Yes | No | Time when the HAP file was updated. |
| appInfo | ApplicationInfo | Yes | No | Application configuration information. |
| abilityInfos | Array\<[AbilityInfo](js-apis-bundle-AbilityInfo.md)> | Yes | No | Ability configuration information. |
| reqPermissions | Array\<string> | Yes | No | Permissions to request from the system for running the application. |
| reqPermissionDetails | Array\<[ReqPermissionDetail](#reqpermissiondetail)> | Yes | No | Detailed information of the permissions to request from the system.|
| abilityInfos | Array\<[AbilityInfo](js-apis-bundle-AbilityInfo.md)> | Yes | No | Ability configuration information.<br>The value is obtained by passing **GET_BUNDLE_WITH_ABILITIES**.|
| reqPermissions | Array\<string> | Yes | No | Permissions to request from the system for running the application.<br>The value is obtained by passing **GET_BUNDLE_WITH_REQUESTED_PERMISSION**.|
| reqPermissionDetails | Array\<[ReqPermissionDetail](#reqpermissiondetail)> | Yes | No | Detailed information of the permissions to request from the system.<br>The value is obtained by passing **GET_BUNDLE_WITH_REQUESTED_PERMISSION**.|
| vendor | string | Yes | No | Vendor of the bundle. |
| versionCode | number | Yes | No | Version number of the bundle. |
| versionName | string | Yes | No | Version description of the bundle. |
......@@ -32,12 +32,14 @@ Provides the application bundle information.
| isCompressNativeLibs | boolean | Yes | No | Whether to compress the native library of the bundle. The default value is **true**. |
| hapModuleInfos | Array\<[HapModuleInfo](js-apis-bundle-HapModuleInfo.md)> | Yes | No | Module configuration information. |
| entryModuleName | string | Yes | No | Name of the entry module. |
| cpuAbi | string | Yes | No | cpuAbi information of the bundle. |
| cpuAbi | string | Yes | No | CPU and ABI information of the bundle. |
| isSilentInstallation | string | Yes | No | Whether the application can be installed in silent mode. |
| minCompatibleVersionCode | number | Yes | No | Earliest version compatible with the bundle in the distributed scenario. |
| entryInstallationFree | boolean | Yes | No | Whether installation-free is supported for the entry module. |
| reqPermissionStates<sup>8+</sup> | Array\<number> | Yes | No | Permission grant state. |
| extensionAbilityInfo<sup>9+</sup> | Array\<[ExtensionAbilityInfo](js-apis-bundle-ExtensionAbilityInfo.md)> | Yes | No | Extension ability information. |
| extensionAbilityInfo<sup>9+</sup> | Array\<[ExtensionAbilityInfo](js-apis-bundle-ExtensionAbilityInfo.md)> | Yes | No | Extension ability information.<br>The value is obtained by passing **GET_BUNDLE_WITH_EXTENSION_ABILITY**.|
## ReqPermissionDetail
......@@ -51,6 +53,8 @@ Provides the detailed information of the permissions to request from the system.
| reason | string | Yes | Yes | Reason for requesting the permission. |
| usedScene | [UsedScene](#usedscene) | Yes | Yes | Application scenario and timing for using the permission.|
## UsedScene
Describes the application scenario and timing for using the permission.
......
# ExtensionAbilityInfo
The **ExtensionAbilityInfo** module provides Extension ability information. Unless otherwise specified, all attributes are obtained through **GET_BUNDLE_DEFAULT**.
> **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.
>
> API version 9 is a canary version for trial use. The APIs of this version may be unstable.
Provides the Extension ability information.
## ExtensionAbilityInfo
**System capability**: SystemCapability.BundleManager.BundleFramework
......@@ -24,7 +24,7 @@ Provides the Extension ability information.
| extensionAbilityType | bundle.ExtensionAbilityType | Yes | No | Type of the Extension ability. |
| permissions | Array\<string> | Yes | No | Permissions required for other applications to call the Extension ability.|
| applicationInfo | ApplicationInfo | Yes | No | Application information of the Extension ability. |
| metaData | Array\<[Metadata](js-apis-bundle-Metadata.md)> | Yes | No | Metadata of the Extension ability. |
| metadata | Array\<[Metadata](js-apis-bundle-Metadata.md)> | Yes | No | Metadata of the Extension ability. |
| enabled | boolean | Yes | No | Whether the Extension ability is enabled. |
| readPermission | string | Yes | No | Permission required for reading the Extension ability data. |
| readPermission | string | Yes | No | Permission required for reading data from the Extension ability. |
| writePermission | string | Yes | No | Permission required for writing data to the Extension ability. |
# HapModuleInfo
The **HapModuleInfo** module provides module information. Unless otherwise specified, all attributes are obtained through **GET_BUNDLE_DEFAULT**.
> **NOTE**
>
> The initial APIs of this module are supported since API version 7. Newly added APIs will be marked with a superscript to indicate their earliest API version.
>
> API version 9 is a canary version for trial use. The APIs of this version may be unstable.
Provides the HAP module information.
## HapModuleInfo
**System capability**: SystemCapability.BundleManager.BundleFramework
......
......@@ -1438,4 +1438,4 @@ Defines the **HuksResult** structure.
| errorCode | number | Yes | Error code. |
| outData | Uint8Array | No | Output data.|
| properties | Array\<HuksParam> | No | Properties. |
| certChains | Array\<string> | No | Certificate chain. |
| certChains | Array\<string> | No | Reserved. |
......@@ -60,7 +60,7 @@ Creates a **VideoPlayer** instance in asynchronous mode. This API uses a callbac
let videoPlayer
media.createVideoPlayer((error, video) => {
if (typeof(video) != 'undefined') {
if (video != null) {
videoPlayer = video;
console.info('video createVideoPlayer success');
} else {
......@@ -89,7 +89,7 @@ Creates a **VideoPlayer** instance in asynchronous mode. This API uses a promise
let videoPlayer
media.createVideoPlayer().then((video) => {
if (typeof(video) != 'undefined') {
if (video != null) {
videoPlayer = video;
console.info('video createVideoPlayer success');
} else {
......@@ -307,7 +307,7 @@ Seeks to the specified playback position.
```js
audioPlayer.on('timeUpdate', (seekDoneTime) => { // Set the 'timeUpdate' event callback.
if (typeof (seekDoneTime) == 'undefined') {
if (seekDoneTime == null) {
console.info('audio seek fail');
return;
}
......@@ -380,7 +380,7 @@ function printfDescription(obj) {
}
audioPlayer.getTrackDescription((error, arrlist) => {
if (typeof (arrlist) != 'undefined') {
if (arrlist != null) {
for (let i = 0; i < arrlist.length; i++) {
printfDescription(arrlist[i]);
}
......@@ -416,7 +416,7 @@ function printfDescription(obj) {
}
audioPlayer.getTrackDescription().then((arrlist) => {
if (typeof (arrlist) != 'undefined') {
if (arrlist != null) {
arrayDescription = arrlist;
} else {
console.log('audio getTrackDescription fail');
......@@ -491,7 +491,7 @@ audioPlayer.on('reset', () => { // Set the 'reset' event callback.
audioPlayer = undefined;
});
audioPlayer.on('timeUpdate', (seekDoneTime) => { // Set the 'timeUpdate' event callback.
if (typeof(seekDoneTime) == "undefined") {
if (seekDoneTime == null) {
console.info('audio seek fail');
return;
}
......@@ -546,7 +546,7 @@ Subscribes to the 'timeUpdate' event.
```js
audioPlayer.on('timeUpdate', (seekDoneTime) => { // Set the 'timeUpdate' event callback.
if (typeof (seekDoneTime) == 'undefined') {
if (seekDoneTime == null) {
console.info('audio seek fail');
return;
}
......@@ -595,7 +595,6 @@ Enumerates the audio playback states. You can obtain the state through the **sta
| stopped | string | Audio playback is stopped. |
| error<sup>8+</sup> | string | Audio playback is in the error state. |
## VideoPlayer<sup>8+</sup>
Provides APIs to manage and play video. Before calling an API of **VideoPlayer**, you must call [createVideoPlayer()](#mediacreatevideoplayer8) to create a [VideoPlayer](#videoplayer8) instance.
......@@ -635,7 +634,7 @@ Sets **SurfaceId**. This API uses a callback to return the result.
```js
videoPlayer.setDisplaySurface(surfaceId, (err) => {
if (typeof (err) == 'undefined') {
if (err == null) {
console.info('setDisplaySurface success!');
} else {
console.info('setDisplaySurface fail!');
......@@ -691,7 +690,7 @@ Prepares for video playback. This API uses a callback to return the result.
```js
videoPlayer.prepare((err) => {
if (typeof (err) == 'undefined') {
if (err == null) {
console.info('prepare success!');
} else {
console.info('prepare fail!');
......@@ -741,7 +740,7 @@ Starts to play video resources. This API uses a callback to return the result.
```js
videoPlayer.play((err) => {
if (typeof (err) == 'undefined') {
if (err == null) {
console.info('play success!');
} else {
console.info('play fail!');
......@@ -791,7 +790,7 @@ Pauses video playback. This API uses a callback to return the result.
```js
videoPlayer.pause((err) => {
if (typeof (err) == 'undefined') {
if (err == null) {
console.info('pause success!');
} else {
console.info('pause fail!');
......@@ -841,7 +840,7 @@ Stops video playback. This API uses a callback to return the result.
```js
videoPlayer.stop((err) => {
if (typeof (err) == 'undefined') {
if (err == null) {
console.info('stop success!');
} else {
console.info('stop fail!');
......@@ -891,7 +890,7 @@ Switches the video resource to be played. This API uses a callback to return the
```js
videoPlayer.reset((err) => {
if (typeof (err) == 'undefined') {
if (err == null) {
console.info('reset success!');
} else {
console.info('reset fail!');
......@@ -942,7 +941,7 @@ Seeks to the specified playback position. The next key frame at the specified po
```js
videoPlayer.seek((seekTime, err) => {
if (typeof (err) == 'undefined') {
if (err == null) {
console.info('seek success!');
} else {
console.info('seek fail!');
......@@ -970,7 +969,7 @@ Seeks to the specified playback position. This API uses a callback to return the
```js
videoPlayer.seek((seekTime, seekMode, err) => {
if (typeof (err) == 'undefined') {
if (err == null) {
console.info('seek success!');
} else {
console.info('seek fail!');
......@@ -1034,7 +1033,7 @@ Sets the volume. This API uses a callback to return the result.
```js
videoPlayer.setVolume((vol, err) => {
if (typeof (err) == 'undefined') {
if (err == null) {
console.info('setVolume success!');
} else {
console.info('setVolume fail!');
......@@ -1090,7 +1089,7 @@ Releases the video playback resource. This API uses a callback to return the res
```js
videoPlayer.release((err) => {
if (typeof (err) == 'undefined') {
if (err == null) {
console.info('release success!');
} else {
console.info('release fail!');
......@@ -1148,7 +1147,7 @@ function printfDescription(obj) {
}
videoPlayer.getTrackDescription((error, arrlist) => {
if (typeof (arrlist) != 'undefined') {
if (arrlist != null) {
for (let i = 0; i < arrlist.length; i++) {
printfDescription(arrlist[i]);
}
......@@ -1185,7 +1184,7 @@ function printfDescription(obj) {
let arrayDescription;
videoPlayer.getTrackDescription().then((arrlist) => {
if (typeof (arrlist) != 'undefined') {
if (arrlist != null) {
arrayDescription = arrlist;
} else {
console.log('video getTrackDescription fail');
......@@ -1217,7 +1216,7 @@ Sets the video playback speed. This API uses a callback to return the result.
```js
videoPlayer.setSpeed((speed:number, err) => {
if (typeof (err) == 'undefined') {
if (err == null) {
console.info('setSpeed success!');
} else {
console.info('setSpeed fail!');
......@@ -1438,7 +1437,7 @@ function printfItemDescription(obj, key) {
}
audioPlayer.getTrackDescription((error, arrlist) => {
if (typeof (arrlist) != 'undefined') {
if (arrlist != null) {
for (let i = 0; i < arrlist.length; i++) {
printfItemDescription(arrlist[i], MD_KEY_TRACK_TYPE); // Print the MD_KEY_TRACK_TYPE value of each track.
}
......
......@@ -115,7 +115,7 @@ Returns to the previous page or a specified page.
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| options | [RouterOptions](#routeroptions) | Yes| Description of the page. The **url** parameter indicates the URL of the page to return to. If the specified page does not exist in the page stack, the application does not respond. If this parameter is not set, the application returns to the previous page.|
| options | [RouterOptions](#routeroptions) | Yes| Description of the page. The **url** parameter indicates the URL of the page to return to. If the specified page does not exist in the page stack, the application does not respond. If no URL is set, the previous page is returned, and the page in the page stack is not reclaimed. It will be reclaimed after being popped up.|
**Example**
```js
......
......@@ -7,6 +7,8 @@ This module provides WebGL APIs that correspond to the OpenGL ES 2.0 feature set
> **NOTE**
>
> The initial APIs of this module are supported since API version 7. Newly added APIs will be marked with a superscript to indicate their earliest API version.
>
> WebGL complies with the OpenGL protocol and does not support multi-thread calling.
## Invoking Method
......@@ -90,7 +92,7 @@ gl.clearColor(0.0, 0.0, 0.0, 1.0);
WebGLContextAttributes
| Name| Type| Mandatory|
| Name| Type| Mandatory|
| -------- | -------- | -------- |
| alpha | boolean | No|
| depth | boolean | No|
......@@ -107,7 +109,7 @@ WebGLContextAttributes
WebGLActiveInfo
| Name| Type| Mandatory|
| Name| Type| Mandatory|
| -------- | -------- | -------- |
| size | GLint | Yes|
| type | GLenum | Yes|
......@@ -118,7 +120,7 @@ WebGLActiveInfo
WebGLShaderPrecisionFormat
| Name| Type| Mandatory|
| Name| Type| Mandatory|
| -------- | -------- | -------- |
| rangeMin | GLint | Yes|
| rangeMax | GLint | Yes|
......@@ -132,7 +134,7 @@ WebGLRenderingContextBase
### Attributes
| Name| Type| Mandatory|
| Name| Type| Mandatory|
| -------- | -------- | -------- |
| DEPTH_BUFFER_BIT | GLenum | Yes|
| STENCIL_BUFFER_BIT | GLenum | Yes|
......@@ -435,7 +437,7 @@ WebGLRenderingContextBase
### Methods
| Method| Return Value Type|
| Method| Return Value Type|
| -------- | -------- |
| getContextAttributes() | WebGLContextAttributes \| null |
| isContextLost() | boolean |
......@@ -561,14 +563,14 @@ WebGLRenderingContextBase
WebGLRenderingContextOverloads
| Method| Return Value Type|
| Method| Return Value Type|
| -------- | -------- |
| bufferData(target: GLenum, size: GLsizeiptr, usage: GLenum) | void |
| bufferData(target: GLenum, data: BufferSource \| null, usage: GLenum) | void |
| bufferSubData(target: GLenum, offset: GLintptr, data: BufferSource) | void |
| compressedTexImage2D(target: GLenum, level: GLint, internalformat: GLenum, width: GLsizei, height: GLsizei, border: GLint, data: ArrayBufferView) | void |
| compressedTexSubImage2D(target: GLenum, level: GLint, xoffset: GLint, yoffset: GLint, width: GLsizei, height: GLsizei, format: GLenum, data: ArrayBufferView) | void |
| readPixels(x: GLint, y: GLint, width: GLsizei, height: GLsizei, format: GLenum, type: GLenum, pixels: ArrayBufferView \| null) | void; |
| readPixels(x: GLint, y: GLint, width: GLsizei, height: GLsizei, format: GLenum, type: GLenum, pixels: ArrayBufferView \| null) | void |
| texImage2D(target: GLenum, level: GLint, internalformat: GLint, width: GLsizei, height: GLsizei, border: GLint, format: GLenum, type: GLenum, pixels: ArrayBufferView \| null) | void |
| texImage2D(target: GLenum, level: GLint, internalformat: GLint, format: GLenum, type: GLenum, source: TexImageSource) | void |
| texSubImage2D(target: GLenum, level: GLint, xoffset: GLint, yoffset: GLint, width: GLsizei, height: GLsizei, format: GLenum, type: GLenum, pixels: ArrayBufferView \| null) | void |
......
......@@ -7,6 +7,8 @@ This module provides WebGL APIs that correspond to the OpenGL ES 3.0 feature set
> **NOTE**
>
> The initial APIs of this module are supported since API version 7. Newly added APIs will be marked with a superscript to indicate their earliest API version.
>
> WebGL2 complies with the OpenGL protocol and does not support multi-thread calling.
## Invoking Method
......
......@@ -10,7 +10,6 @@
- [Focus Event](ts-universal-focus-event.md)
- [Mouse Event](ts-universal-mouse-key.md)
- [Component Area Change Event](ts-universal-component-area-change-event.md)
- [Visible Area Change Event](ts-universal-component-visible-area-change-event.md)
- Universal Attributes
- [Size](ts-universal-attributes-size.md)
- [Location](ts-universal-attributes-location.md)
......
# Swiper
The **<Swiper\>** component provides a container that allows users to switch among child components through swiping.
The **\<Swiper>** component provides a container that allows users to switch among child components using swipe gestures.
> **NOTE**
>
......@@ -23,49 +22,94 @@ This component can contain child components.
Swiper(value:{controller?: SwiperController})
- Parameters
| Name | Type | Mandatory | Default Value | Description |
| -------- | -------- | -------- | -------- | -------- |
| controller | [SwiperController](#swipercontroller) | No | null | Controller bound to the component to control the page switching. |
**Parameters**
| Name | Type | Mandatory | Description |
| ---------- | ------------------------------------- | ---- | -------------------- |
| controller | [SwiperController](#swipercontroller) | No | Controller bound to the component to control the page switching.<br>Default value: **null** |
## Attributes
| Name | Type | Default Value | Description |
| -------- | -------- | -------- | -------- |
| index | number | 0 | Index of the child component currently displayed in the container. |
| autoPlay | boolean | false | Whether to enable automatic playback for child component switching. If this attribute is **true**, the indicator dots do not take effect. |
| interval | number | 3000 | Interval for automatic playback, in ms. |
| indicator | boolean | true | Whether to enable the navigation dots. |
| loop | boolean | true | Whether to enable loop playback.<br>The value **true** means to enable loop playback. When **LazyForEach** is used, it is recommended that the number of the components to load exceed 5. |
| duration | number | 400 | Duration of the animation for switching child components, in ms. |
| vertical | boolean | false | Whether vertical swiping is used. |
| itemSpace | Length | 0 | Space between child components. |
| cachedCount<sup>8+</sup> | number | 1 | Number of child components to be cached. |
| disableSwipe<sup>8+</sup> | boolean | false | Whether to disable the swipe feature. |
| curve<sup>8+</sup> | [Curve](ts-animatorproperty.md) \| Curves | Curve.Ease | Animation curve. The ease-in/ease-out curve is used by default. For details about common curves, see [Curve enums](ts-animatorproperty.md). You can also create custom curves ([interpolation curve objects](ts-interpolation-calculation.md)) by using APIs provided by the interpolation calculation module. |
| indicatorStyle<sup>8+</sup> | {<br/>left?:&nbsp;Length,<br/>top?:&nbsp;Length,<br/>right?:&nbsp;Length,<br/>bottom?:&nbsp;Length,<br/>size?:&nbsp;Length,<br/>color?:&nbsp;Color,<br/>selectedColor?:&nbsp;Color<br/>} | - | Style of the navigation dots indicator.<br/>- **left**:&nbsp;distance between the navigation dots indicator and the left edge of the **\<Swiper>** component.<br/>- **top**:&nbsp;distance between the navigation dots indicator and the top edge of the **\<Swiper>** component.<br/>- **right**:&nbsp;distance between the navigation dots indicator and the right edge of the **\<Swiper>** component.<br/>- **bottom**:&nbsp;distance between the navigation dots indicator and the right edge of the **\<Swiper>** component.<br/>- **size**:&nbsp;diameter of the navigation dots indicator.<br/>- **color**:&nbsp;color of the navigation dots indicator.<br/>- **selectedColor**:&nbsp;color of the selected navigation dot. |
[Menu control](ts-universal-attributes-menu.md) is not supported.
| Name | Type | Description |
| --------------------------- | ---------------------------------------- | ---------------------------------------- |
| index | number | Index of the child component currently displayed in the container.<br>Default value: **0** |
| autoPlay | boolean | Whether to enable automatic playback for child component switching. If this attribute is **true**, the navigation dots indicator does not take effect.<br>Default value: **false** |
| interval | number | Interval for automatic playback, in ms.<br>Default value: **3000** |
| indicator | boolean | Whether to enable the navigation dots indicator.<br>Default value: **true** |
| loop | boolean | Whether to enable loop playback.<br>The value **true** means to enable loop playback. When LazyForEach is used, it is recommended that the number of the components to load exceed 5.<br>Default value: **true**|
| duration | number | Duration of the animation for switching child components, in ms.<br>Default value: **400** |
| vertical | boolean | Whether vertical swiping is used.<br>Default value: **false** |
| itemSpace | Length | Space between child components.<br>Default value: **0** |
| displayMode | SwiperDisplayMode | Mode in which elements are displayed along the main axis. This attribute takes effect only when **displayCount** is not set.<br>Default value: **SwiperDisplayMode.Stretch**|
| cachedCount<sup>8+</sup> | number | Number of child components to be cached.<br>Default value: **1** |
| disableSwipe<sup>8+</sup> | boolean | Whether to disable the swipe feature.<br>Default value: **false** |
| curve<sup>8+</sup> | [Curve](ts-animatorproperty.md#Curve) \| string | Animation curve. The ease-in/ease-out curve is used by default. For details about common curves, see [Curve enums](ts-animatorproperty.md#curve-enums). You can also create custom curves ([interpolation curve objects](ts-interpolation-calculation.md)) by using the API provided by the interpolation calculation module.<br>Default value: **Curve.Ease**|
| indicatorStyle<sup>8+</sup> | {<br>left?:&nbsp;Length,<br>top?:&nbsp;Length,<br>right?:&nbsp;Length,<br>bottom?:&nbsp;Length,<br>size?:&nbsp;Length,<br>color?:&nbsp;Color,<br>selectedColor?:&nbsp;Color<br>} | Style of the navigation dots indicator.<br>- **left**: distance between the navigation dots indicator and the left edge of the **\<Swiper>** component.<br>- **top**: distance between the navigation dots indicator and the top edge of the **\<Swiper>** component.<br>- **right**: distance between the navigation dots indicator and the right edge of the **\<Swiper>** component.<br>- **bottom**: distance between the navigation dots indicator and the bottom edge of the **\<Swiper>** component.<br>- **size**: diameter of the navigation dots indicator.<br>- **color**: color of the navigation dots indicator.<br>- **selectedColor**: color of the selected navigation dot.|
| displayCount<sup>8+</sup> | number\|string | Number of elements to display.<br>Default value: **1** |
| effectMode<sup>8+</sup> | EdgeEffect | Swipe effect. For details, see **EdgeEffect**.<br>Default value: **EdgeEffect.Spring**|
## SwiperDisplayMode
| Name| Description|
| ----------- | ------------------------------------------ |
| Stretch | The slide width of the **\<Swiper>** component is equal to the width of the component.|
| AutoLinear | The slide width of the **\<Swiper>** component is equal to the maximum width of the child components.|
## EdgeEffect
| Name | Description |
| ------ | ------------------------------------------------------------------------- |
| Spring | Spring effect. When at one of the edges, the component can move beyond the bounds through touches, and produce a bounce effect when the user releases their finger. |
| Fade | Fade effect. When at one of the edges, the component can move beyond the bounds through touches, and produce a fade effect along the way; when the user releases their finger, the fade changes. |
| None | No effect. When at one of the edges, the component cannot move beyond the bounds. |
## SwiperController
Controller of the **<Swiper\>** component. You can bind this object to the **<Swiper\>** component and use it to control page switching.
Controller of the **\<Swiper>** component. You can bind this object to the **<Swiper>** component and use it to control page switching.
| Name | Description |
| -------- | -------- |
| showNext():void | Turns to the next page. |
| showPrevious():void | Turns to the previous page. |
### showNext
showNext(): void
Turns to the next page.
### showPrevious
showPrevious(): void
Turns to the previous page.
### finishAnimation
finishAnimation(callback?: () => void): void
Stops this animation.
**Parameters**
| Name | Type | Mandatory.| Description|
| --------- | ---------- | ------ | -------- |
| callback | () => void | Yes | Callback invoked when the animation stops.|
## Events
| Name | Description |
| -------- | -------- |
| onChange( index: number) =&gt; void | Triggered when the index of the currently displayed component changes. |
### onChange
onChange(&nbsp;index:&nbsp;number)&nbsp;=&gt;&nbsp;void
## Example
Triggered when the index of the currently displayed component changes.
**Parameters**
| Name | Type | Mandatory.| Description|
| --------- | ---------- | ------ | -------- |
| index | number | Yes | Index of the currently displayed element.|
## Example
```ts
// xxx.ets
......@@ -123,7 +167,7 @@ struct SwiperExample {
.duration(1000)
.vertical(false) // Horizontal swiping is enabled by default.
.itemSpace(0)
.curve(Curve.Linear) // Animation curve
.curve(Curve.Linear) // Animation curve.
.onChange((index: number) => {
console.info(index.toString())
})
......
......@@ -25,7 +25,7 @@ None
| Name | Type | Description |
| -------- | -------- | -------- |
| type | [KeyType](#keytype-enums) | Type of a key. |
| [keyCode](../apis/js-apis-keycode.md) | number | Key code. |
| keyCode | number | Key code. |
| keyText | string | Key value. |
| keySource | [KeySource](#keysource-enums) | Type of the input device that triggers the key event. |
| deviceId | number | ID of the input device that triggers the key event. |
......
......@@ -86,7 +86,7 @@ Ability功能如下(Ability类,具体的API详见[接口文档](../reference
onWindowStageCreate(windowStage) {
console.log("MainAbility onWindowStageCreate")
windowStage.loadContent("pages/index").then((data) => {
windowStage.loadContent("pages/index").then(() => {
console.log("MainAbility load content succeed")
}).catch((error) => {
console.error("MainAbility load content failed with error: "+ JSON.stringify(error))
......@@ -228,8 +228,8 @@ var want = {
"bundleName": "com.example.MyApplication",
"abilityName": "MainAbility"
};
context.startAbility(want).then((data) => {
console.log("Succeed to start ability with data: " + JSON.stringify(data))
context.startAbility(want).then(() => {
console.log("Succeed to start ability")
}).catch((error) => {
console.error("Failed to start ability with error: "+ JSON.stringify(error))
})
......@@ -245,8 +245,8 @@ var want = {
"bundleName": "com.example.MyApplication",
"abilityName": "MainAbility"
};
context.startAbility(want).then((data) => {
console.log("Succeed to start remote ability with data: " + JSON.stringify(data))
context.startAbility(want).then(() => {
console.log("Succeed to start remote ability")
}).catch((error) => {
console.error("Failed to start remote ability with error: " + JSON.stringify(error))
})
......
......@@ -88,9 +88,9 @@
context.getFilesDir().then((filePath) => {
path = filePath;
console.info("======================>getFilesDirPromsie====================>");
});
let promise = dataStorage.getStorage(path + '/mystore');
});
```
3. 存入数据。
......@@ -99,7 +99,7 @@
```js
promise.then((storage) => {
let getPromise = storage.put('startup', 'auto'); // 保存数据到缓存的storage示例中。
let getPromise = storage.put('startup', 'auto'); // 保存数据到缓存的storage实例中
getPromise.then(() => {
console.info("Succeeded in putting the value of startup.");
}).catch((err) => {
......
......@@ -17,19 +17,19 @@ USB类开放能力如下,具体请查阅[API参考文档](../reference/apis/js
| 接口名 | 描述 |
| -------- | -------- |
| hasRight(deviceName:&nbsp;string):&nbsp;boolean | 如果“使用者”(如各种App或系统)有权访问设备则返回true;无权访问设备则返回false。 |
| requestRight(deviceName:&nbsp;string):&nbsp;Promise&lt;boolean&gt; | 请求给定软件包的临时权限以访问设备。 |
| connectDevice(device:&nbsp;USBDevice):&nbsp;Readonly&lt;USBDevicePipe&gt; | 根据getDevices()返回的设备信息打开USB设备。 |
| getDevices():&nbsp;Array&lt;Readonly&lt;USBDevice&gt;&gt; | 返回USB设备的列表。 |
| setConfiguration(pipe:&nbsp;USBDevicePipe,&nbsp;config:&nbsp;USBConfig):&nbsp;number | 设置设备的配置。 |
| setInterface(pipe:&nbsp;USBDevicePipe,&nbsp;iface:&nbsp;USBInterface):&nbsp;number | 设置设备的接口。 |
| claimInterface(pipe:&nbsp;USBDevicePipe,&nbsp;iface:&nbsp;USBInterface,&nbsp;force?:&nbsp;boolean):&nbsp;number | 获取接口。 |
|bulkTransfer(pipe:&nbsp;USBDevicePipe,&nbsp;endpoint:&nbsp;USBEndpoint,&nbsp;buffer:&nbsp;Uint8Array,&nbsp;timeout?:&nbsp;number):&nbsp;Promise&lt;number&gt; | 批量传输。 |
| closePipe(pipe:&nbsp;USBDevicePipe):&nbsp;number | 关闭设备消息控制通道。 |
| releaseInterface(pipe:&nbsp;USBDevicePipe,&nbsp;iface:&nbsp;USBInterface):&nbsp;number | 释放接口。 |
| getFileDescriptor(pipe:&nbsp;USBDevicePipe):&nbsp;number | 获取文件描述符。 |
| getRawDescriptor(pipe:&nbsp;USBDevicePipe):&nbsp;Uint8Array | 获取原始的USB描述符。 |
| controlTransfer(pipe:&nbsp;USBDevicePipe,&nbsp;contrlparam:&nbsp;USBControlParams,&nbsp;timeout?:&nbsp;number):&nbsp;Promise&lt;number&gt; | 控制传输。 |
| hasRight(deviceName:string):boolean | 如果“使用者”(如各种App或系统)有权访问设备则返回true;无权访问设备则返回false。 |
| requestRight(deviceName:string):Promise&lt;boolean&gt; | 请求给定软件包的临时权限以访问设备。 |
| connectDevice(device:USBDevice):Readonly&lt;USBDevicePipe&gt; | 根据`getDevices()`返回的设备信息打开USB设备。 |
| getDevices():Array&lt;Readonly&lt;USBDevice&gt;&gt; | 返回USB设备列表。 |
| setConfiguration(pipe:USBDevicePipe,config:USBConfig):number | 设置设备的配置。 |
| setInterface(pipe:USBDevicePipe,iface:USBInterface):number | 设置设备的接口。 |
| claimInterface(pipe:USBDevicePipe,iface:USBInterface,force?:boolean):number | 获取接口。 |
|bulkTransfer(pipe:USBDevicePipe,endpoint:USBEndpoint,buffer:Uint8Array,timeout?:number):Promise&lt;number&gt; | 批量传输。 |
| closePipe(pipe:USBDevicePipe):number | 关闭设备消息控制通道。 |
| releaseInterface(pipe:USBDevicePipe,iface:USBInterface):number | 释放接口。 |
| getFileDescriptor(pipe:USBDevicePipe):number | 获取文件描述符。 |
| getRawDescriptor(pipe:USBDevicePipe):Uint8Array | 获取原始的USB描述符。 |
| controlTransfer(pipe:USBDevicePipe,contrlparam:USBControlParams,timeout?:number):Promise&lt;number&gt; | 控制传输。 |
## 开发步骤
......@@ -115,7 +115,7 @@ USB设备可作为Host设备连接Device设备进行数据传输。开发示例
打开对应接口,在设备信息(deviceList)中选取对应的interface。
interface1为设备配置中的一个接口。
*/
usb.claimInterface(pipe , interface1, true);
usb.claimInterface(pipe, interface1, true);
```
4. 数据传输。
......
......@@ -2,7 +2,7 @@
## 场景介绍
HiTraceMeter为开发者提供系统性能打点接口。开发者通过在自己的业务逻辑中的关键代码位置调用HiTraceMeter提供的API接口,能够有效踪进程轨迹、查看系统性能。
HiTraceMeter为开发者提供系统性能打点接口。开发者通过在自己的业务逻辑中的关键代码位置调用HiTraceMeter提供的API接口,能够有效踪进程轨迹、查看系统性能。
## 接口说明
......@@ -12,15 +12,15 @@ HiTraceMeter为开发者提供系统性能打点接口。开发者通过在自
| 接口名 | 返回值 | 描述 |
| ---------------------------------------------------------------------------- | --------- | ------------ |
| hiTraceMeter.startTrace(name: string, taskId: number, expectedTime?: number) | void | 标记一个预追踪耗时任务的开始。如果有多个相同name的任务需要追踪或者对同一个任务要追踪多次,并且任务同时被执行,则每次调用startTrace的taskId不相同。如果具有相同name的任务是串行执行的,则taskId可以相同。 |
| hiTraceMeter.startTrace(name: string, taskId: number, expectedTime?: number) | void | 标记一个预跟踪耗时任务的开始。如果有多个相同name的任务需要跟踪或者对同一个任务要跟踪多次,并且任务同时被执行,则每次调用startTrace的taskId不相同。如果具有相同name的任务是串行执行的,则taskId可以相同。 |
| hiTraceMeter.finishTrace(name: string, taskId: number) | void | name和taskId必须与流程开始的hiTraceMeter.startTrace对应参数值保持一致。 |
| hiTraceMeter.traceByValue(name: string, value: number) | void | 用来标记一个预踪的数值变量,该变量的数值会不断变化。|
| hiTraceMeter.traceByValue(name: string, value: number) | void | 用来标记一个预踪的数值变量,该变量的数值会不断变化。|
## 开发步骤
在应用启动执行页面加载后,开始分布式跟踪,完成业务之后,停止分布式跟踪。
1. 新建一个JS应用工程,在“Project”窗口点击“entry > src > main > js > default > pages > index”,打开工程中的“index.js”文件,在页面执行加载后,在自己的业务中调用hiTraceMeter的接口,进行性能打点踪,示例代码如下:
1. 新建一个JS应用工程,在“Project”窗口点击“entry > src > main > js > default > pages > index”,打开工程中的“index.js”文件,在页面执行加载后,在自己的业务中调用hiTraceMeter的接口,进行性能打点踪,示例代码如下:
```js
import hiTraceMeter from '@ohos.hiTraceMeter'
......@@ -36,11 +36,11 @@ HiTraceMeter为开发者提供系统性能打点接口。开发者通过在自
hiTraceMeter.startTrace("business", 1);
hiTraceMeter.startTrace("business", 1, 5);
// 踪并行执行的同名任务
// 踪并行执行的同名任务
hiTraceMeter.startTrace("business", 1);
// 业务流程
console.log(`business running`);
hiTraceMeter.startTrace("business", 2); // 第二个追踪的任务开始,同时第一个追踪的同名任务还没结束,出现了并行执行,对应接口的taskId需要不同
hiTraceMeter.startTrace("business", 2); // 第二个跟踪的任务开始,同时第一个跟踪的同名任务还没结束,出现了并行执行,对应接口的taskId需要不同
// 业务流程
console.log(`business running`);
hiTraceMeter.finishTrace("business", 1);
......@@ -48,14 +48,14 @@ HiTraceMeter为开发者提供系统性能打点接口。开发者通过在自
console.log(`business running`);
hiTraceMeter.finishTrace("business", 2);
// 踪串行执行的同名任务
// 踪串行执行的同名任务
hiTraceMeter.startTrace("business", 1);
// 业务流程
console.log(`business running`);
hiTraceMeter.finishTrace("business", 1); // 第一个踪的任务结束
hiTraceMeter.finishTrace("business", 1); // 第一个踪的任务结束
// 业务流程
console.log(`business running`);
hiTraceMeter.startTrace("business", 1); // 第二个追踪的同名任务开始,同名的待追踪任务串行执行
hiTraceMeter.startTrace("business", 1); // 第二个跟踪的同名任务开始,同名的待跟踪任务串行执行
// 业务流程
console.log(`business running`);
......
# 性能打点跟踪概述
hiTraceMeter是用于踪进程轨迹,度量程序执行性能的一种工具,基于内核的ftrace机制,提供给用户态应用代码执行时长度量打点的能力。开发者通过使用hiTraceMeter API在程序中打点,并使用hiTraceMeter提供的命令行工具采集跟踪数据。
hiTraceMeter是用于踪进程轨迹,度量程序执行性能的一种工具,基于内核的ftrace机制,提供给用户态应用代码执行时长度量打点的能力。开发者通过使用hiTraceMeter API在程序中打点,并使用hiTraceMeter提供的命令行工具采集跟踪数据。
## 基本概念
......
# I18n开发指导
I18n开发指导提供了未在ECMA 402中定义的国际化能力接口的使用方法
本模块提供系统相关的或者增强的国际化能力,包括区域管理、电话号码处理、日历等,相关接口为ECMA 402标准中未定义的补充接口。更多接口和使用方式请见[I18N](../reference/apis/js-apis-i18n.md)
[Intl](intl-guidelines.md)模块提供了ECMA 402标准定义的基础国际化接口,与本模块共同使用可提供完整地国际化支持能力。
## 获取系统语言区域信息
调用系统提供的接口访问系统的语言区域信息。
### 接口说明
| 模块 | 接口名称 | 描述 |
......@@ -20,15 +20,13 @@ I18n开发指导提供了未在ECMA 402中定义的国际化能力接口的使
| ohos.i18n | getDisplayLanguage(language:string,locale:string,sentenceCase?:boolean):string | 获取语言的本地化表示。 |
| ohos.i18n | getDisplayCountry(country:string,locale:string,sentenceCase?:boolean):string | 获取国家的本地化表示。 |
### 开发步骤
1. 获取系统语言。
调用getSystemLanguage方法获取当前系统设置的语言(i18n为导入的模块)。
```
```js
var language = i18n.getSystemLanguage();
```
......@@ -36,7 +34,7 @@ I18n开发指导提供了未在ECMA 402中定义的国际化能力接口的使
调用getSystemRegion方法获取当前系统设置的区域
```
```js
var region = i18n.getSystemRegion();
```
......@@ -44,7 +42,7 @@ I18n开发指导提供了未在ECMA 402中定义的国际化能力接口的使
调用getSystemLocale方法获取当前系统设置的Locale
```
```js
var locale = i18n.getSystemLocale();
```
......@@ -52,8 +50,7 @@ I18n开发指导提供了未在ECMA 402中定义的国际化能力接口的使
调用isRTL方法获取Locale的语言是否为从右到左语言。
```
```js
var rtl = i18n.isRTL("zh-CN");
```
......@@ -61,7 +58,7 @@ I18n开发指导提供了未在ECMA 402中定义的国际化能力接口的使
调用is24HourClock方法来判断当前系统的时间是否采用24小时制。
```
```js
var hourClock = i18n.is24HourClock();
```
......@@ -69,7 +66,7 @@ I18n开发指导提供了未在ECMA 402中定义的国际化能力接口的使
调用getDisplayLanguage方法获取某一语言的本地化表示。其中,language表示待本地化显示的语言,locale表示本地化的Locale,sentenceCase结果是否需要首字母大写。
```
```js
var language = "en";
var locale = "zh-CN";
var sentenceCase = false;
......@@ -80,18 +77,16 @@ I18n开发指导提供了未在ECMA 402中定义的国际化能力接口的使
调用getDisplayCountry方法获取某一国家的本地化表示。其中,country表示待本地化显示的国家,locale表示本地化的Locale,sentenceCase结果是否需要首字母大写。
```
```js
var country = "US";
var locale = "zh-CN";
var sentenceCase = false;
var localizedCountry = i18n.getDisplayCountry(country, locale, sentenceCase);
```
## 获取日历信息
调用日历[Calendar](../reference/apis/js-apis-intl.md)相关接口来获取日历的相关信息,例如获取日历的本地化显示、一周起始日、一年中第一周的最小天数等。
调用日历[Calendar](../reference/apis/js-apis-i18n.md#calendar8)相关接口来获取日历的相关信息,例如获取日历的本地化显示、一周起始日、一年中第一周的最小天数等。
### 接口说明
......@@ -110,23 +105,21 @@ I18n开发指导提供了未在ECMA 402中定义的国际化能力接口的使
| ohos.i18n | getDisplayName(locale:string):string<sup>8+</sup> | 获取日历对象的本地化表示。 |
| ohos.i18n | isWeekend(date?:Date):boolean<sup>8+</sup> | 判断给定的日期是否在日历中是周末。 |
### 开发步骤
1. 实例化日历对象。
调用getCalendar方法获取指定locale和type的时区对象(i18n为导入的模块)。其中,type表示合法的日历类型,目前合法的日历类型包括:"buddhist", "chinese", "coptic", "ethiopic", "hebrew", "gregory", "indian", "islamic_civil", "islamic_tbla", "islamic_umalqura", "japanese", "persian"。当type没有给出时,采用区域默认的日历类型。
```
var calendar = i18n.getCalendar("zh-CN", "gregory);
```js
var calendar = i18n.getCalendar("zh-CN", "gregory");
```
2. 设置日历对象的时间。
调用setTime方法设置日历对象的时间。setTime方法接收两种类型的参数。一种是传入一个Date对象,另一种是传入一个数值表示从1970.1.1 00:00:00 GMT逝去的毫秒数。
```
```js
var date1 = new Date();
calendar.setTime(date1);
var date2 = 1000;
......@@ -137,7 +130,7 @@ I18n开发指导提供了未在ECMA 402中定义的国际化能力接口的使
调用set方法设置日历对象的年、月、日、时、分、秒。
```
```js
calendar.set(2021, 12, 21, 6, 0, 0)
```
......@@ -145,8 +138,7 @@ I18n开发指导提供了未在ECMA 402中定义的国际化能力接口的使
调用setTimeZone方法和getTimeZone方法来设置、获取日历对象的时区。其中,setTimeZone方法需要传入一个字符串表示需要设置的时区。
```
```js
calendar.setTimeZone("Asia/Shanghai");
var timezone = calendar.getTimeZone();
```
......@@ -155,8 +147,7 @@ I18n开发指导提供了未在ECMA 402中定义的国际化能力接口的使
调用setFirstDayOfWeek方法和getFirstDayOfWeek方法设置、获取日历对象的一周起始日。其中,setFirstDayOfWeek需要传入一个数值表示一周的起始日,1代表周日,7代表周六。
```
```js
calendar.setFirstDayOfWeek(1);
var firstDayOfWeek = calendar.getFirstDayOfWeek();
```
......@@ -164,7 +155,7 @@ I18n开发指导提供了未在ECMA 402中定义的国际化能力接口的使
6. 设置、获取日历对象第一周的最小天数
调用setMinimalDaysInFirstWeek方法和getMinimalDaysInFirstWeek方法来设置、获取日历对象第一周的最小天数。
```
```js
calendar.setMinimalDaysInFirstWeek(3);
var minimalDaysInFirstWeek = calendar.getMinimalDaysInFirstWeek();
```
......@@ -172,8 +163,7 @@ I18n开发指导提供了未在ECMA 402中定义的国际化能力接口的使
7. 获取日历对象的本地化显示
调用getDisplayName来获取日历对象的本地化显示。
```
```js
var localizedName = calendar.getDisplayName("zh-CN");
```
......@@ -181,17 +171,14 @@ I18n开发指导提供了未在ECMA 402中定义的国际化能力接口的使
调用isWeekend方法来判断输入的Date是否为周末。
```
```js
var date = new Date();
var weekend = calendar.isWeekend(date);
```
## 电话号码格式化
调用电话号码格式化[PhoneNumberFormat](../reference/apis/js-apis-intl.md)的接口,实现对针对不同国家电话号码的格式化以及判断电话号码格式是否正确的功能。
调用电话号码格式化[PhoneNumberFormat](../reference/apis/js-apis-i18n.md#phonenumberformat8)的接口,实现对针对不同国家电话号码的格式化以及判断电话号码格式是否正确的功能。
### 接口说明
......@@ -201,23 +188,21 @@ I18n开发指导提供了未在ECMA 402中定义的国际化能力接口的使
| ohos.i18n | isValidNumber(number:string):boolean<sup>8+</sup> | 判断number是否是一个格式正确的电话号码。 |
| ohos.i18n | format(number:string):string<sup>8+</sup> | 对number按照指定国家及风格进行格式化。 |
### 开发步骤
1. 实例化电话号码格式化对象。
调用PhoneNumberFormat的构造函数来实例化电话号码格式化对象,需要传入电话号码的国家代码及格式化选项。其中,格式化选项是可选的,包括style选项,该选项的取值包括:"E164", "INTERNATIONAL", "NATIONAL", "RFC3966"。
```
var phoneNumberFormat = new i18n.PhoneNubmerFormat("CN", {type: "E164"});
```js
var phoneNumberFormat = new i18n.PhoneNumberFormat("CN", {type: "E164"});
```
2. 判断电话号码格式是否正确。
调用isValidNumber方法来判断输入的电话号码的格式是否正确。
```
```js
var validNumber = phoneNumberFormat.isValidNumber("15812341234");
```
......@@ -225,31 +210,27 @@ I18n开发指导提供了未在ECMA 402中定义的国际化能力接口的使
调用电话号码格式化对象的format方法来对输入的电话号码进行格式化。
```
```js
var formattedNumber = phoneNumberFormat.format("15812341234");
```
## 度量衡转换
度量衡转换接口可以实现度量衡转换的相关功能。
### 接口说明
| 模块 | 接口名称 | 描述 |
| -------- | -------- | -------- |
| ohos.i18n | unitConvert(fromUnit:UnitInfo,toUnit:UnitInfo,value:number,locale:string,style?:string):string<sup>8+</sup> | 将fromUnit的单位转换为toUnit的单位,并根据区域与风格进行格式化。 |
### 开发步骤
1. 度量衡单位转换。
调用[unitConvert](../reference/apis/js-apis-intl.md)方法实现度量衡单位转换,并进行格式化显示的功能。
调用[unitConvert](../reference/apis/js-apis-i18n.md#unitconvert8)方法实现度量衡单位转换,并进行格式化显示的功能。
```
```js
var fromUnit = {unit: "cup", measureSystem: "US"};
var toUnit = {unit: "liter", measureSystem: "SI"};
var number = 1000;
......@@ -258,11 +239,9 @@ I18n开发指导提供了未在ECMA 402中定义的国际化能力接口的使
i18n.Util.unitConvert(fromUtil, toUtil, number, locale, style);
```
## 字母表索引
调用字母表索引[IndexUtil](../reference/apis/js-apis-intl.md)的接口可以获取不同Locale的字母表索引,以及实现计算字符串所属索引的功能。
调用字母表索引[IndexUtil](../reference/apis/js-apis-i18n.md#indexutil8)的接口可以获取不同Locale的字母表索引,以及实现计算字符串所属索引的功能。
### 接口说明
......@@ -273,7 +252,6 @@ I18n开发指导提供了未在ECMA 402中定义的国际化能力接口的使
| ohos.i18n | addLocale(locale:string): void<sup>8+</sup> | 将新的Locale对应的索引加入当前索引列表。 |
| ohos.i18n | getIndex(text:string):string<sup>8+</sup> | 获取text对应的索引。 |
### 开发步骤
1. 实例化字母表索引对象。
......@@ -281,15 +259,15 @@ I18n开发指导提供了未在ECMA 402中定义的国际化能力接口的使
调用getInstance方法来实例化特定locale对应的字母表索引对象。当locale参数为空时,实例化系统默认Locale的字母表索引对象。
```
var indexUtil = getInstance("zh-CN");
```js
var indexUtil = i18n.getInstance("zh-CN");
```
2. 获取索引列表。
调用getIndexList方法来获取当前Locale对应的字母表索引列表。
```
```js
var indexList = indexUtil.getIndexList();
```
......@@ -297,7 +275,7 @@ I18n开发指导提供了未在ECMA 402中定义的国际化能力接口的使
调用addLocale方法,将新的Locale对应的字母表索引添加到当前字母表索引列表中。
```
```js
indexUtil.addLocale("ar")
```
......@@ -305,16 +283,14 @@ I18n开发指导提供了未在ECMA 402中定义的国际化能力接口的使
调用getIndex方法来获取某一字符串对应的字母表索引。
```
```js
var text = "access index";
indexUtil.getIndex(text);
```
## 获取文本断点位置
当文本比较长无法在一行进行显示时,调用文本断点[BreakIterator8](../reference/apis/js-apis-intl.md)的接口,来获取文本可以断行的位置。
当文本比较长无法在一行进行显示时,调用文本断点[BreakIterator8](../reference/apis/js-apis-i18n.md#breakiterator8)的接口,来获取文本可以断行的位置。
### 接口说明
......@@ -331,15 +307,13 @@ I18n开发指导提供了未在ECMA 402中定义的国际化能力接口的使
| ohos.i18n | following(offset:number):number<sup>8+</sup> | 将断行对象移动到offset指定位置的后面一个分割点的位置。 |
| ohos.i18n | isBoundary(offset:number):boolean<sup>8+</sup> | 判断某个位置是否是分割点。 |
### 开发步骤
1. 实例化断行对象。
调用getLineInstance方法来实例化断行对象。
```
```js
var locale = "en-US"
var breakIterator = i18n.getLineInstance(locale);
```
......@@ -348,8 +322,7 @@ I18n开发指导提供了未在ECMA 402中定义的国际化能力接口的使
调用setLineBreakText方法和getLineBreakText方法来设置、访问要断行处理的文本。
```
```js
var text = "Apple is my favorite fruit";
breakIterator.setLineBreakText(text);
var breakText = breakIterator.getLineBreakText();
......@@ -359,8 +332,7 @@ I18n开发指导提供了未在ECMA 402中定义的国际化能力接口的使
调用current方法来获取断行对象在当前处理文本中的位置。
```
```js
var pos = breakIterator.current();
```
......@@ -368,8 +340,7 @@ I18n开发指导提供了未在ECMA 402中定义的国际化能力接口的使
系统提供了很多接口可以用于调整断行对象在处理文本中的位置,包括first, last, next, previous, following。
```
```js
var firstPos = breakIterator.first(); // 将断行对象设置到第一个分割点的位置,即文本的起始位置;
var lastPos = breakIterator.last(); // 将断行对象设置到最后一个分割点的位置,即文本末尾的下一个位置;
// 将断行对象向前或向后移动一定数量的分割点。
......@@ -385,7 +356,6 @@ I18n开发指导提供了未在ECMA 402中定义的国际化能力接口的使
调用isBoundary方法来判断一个方法是否为分割点;如果该位置是分割点,则返回true,并且将断行对象移动到该位置;如果该位置不是分割点,则返回false,并且将断行对象移动到该位置后的一个分割点。
```
```js
var isboundary = breakIterator.isBoundary(5);
```
\ No newline at end of file
# Intl开发指导
Intl开发指导提供了ECMA 402中定义的国际化能力接口的使用方法
本模块提供提供基础的应用国际化能力,包括时间日期格式化、数字格式化、排序等,相关接口在ECMA 402标准中定义。更多接口和使用方式请见[Intl](../reference/apis/js-apis-intl.md)
## 设置区域信息
[I18N](i18n-guidelines.md)模块提供其他非ECMA 402定义的国际化接口,与本模块共同使用可提供完整地国际化支持能力。
调用[Locale](../reference/apis/js-apis-intl.md)的相关接口实现最大化区域信息或最小化区域信息。
## 设置区域信息
调用[Locale](../reference/apis/js-apis-intl.md#locale)的相关接口实现最大化区域信息或最小化区域信息。
### 接口说明
......@@ -17,17 +18,30 @@ Intl开发指导提供了ECMA 402中定义的国际化能力接口的使用方
| ohos.intl | maximize():Locale | 最大化区域信息。 |
| ohos.intl | minimize():Locale | 最小化区域信息。 |
### 开发步骤
1. 实例化Locale对象。
使用Locale的构造函数创建Locale对象,该方法接收一个表示Locale的字符串及可选的[属性](../reference/apis/js-apis-intl.md)列表(intl为导入的模块名)。
使用Locale的构造函数创建Locale对象,该方法接收一个表示Locale的字符串及可选的[属性](../reference/apis/js-apis-intl.md#localeoptions)列表(intl为导入的模块名)。
表示Locale的字符串参数可以分为以下四部分:语言、脚本、地区、扩展参数。各个部分按照顺序使用中划线“-”进行连接。
- 语言:必选,使用2个或3个小写英文字母表示(可参考ISO-639标准),例如英文使用“en”表示,中文使用“zh”表示。
- 脚本:可选,使用4个英文字母表示,其中首字母需要大写,后面3个使用小写字母(可参考ISO-15924)。例如,中文繁体使用脚本“Hant”表示,中文简体使用脚本“Hans”表示。
- 国家或地区:可选,使用两个大写字母表示(可参考ISO-3166),例如中国使用“CN”表示,美国使用“US”表示;
- 扩展参数:可选,由key和value两部分组成,目前支持以下扩展参数(可参考BCP 47扩展)。各个扩展参数之间没有严格的顺序,使用“-key-value”的格式书写。扩展参数整体使用“-u”连接到语言、脚本、地区后面。例如“zh-u-nu-latn-ca-chinese”表示使用“latn”数字系统,“chinese”日历系统。扩展参数也可以通过第二个参数传入。
| 扩展参数ID | 扩展参数说明 |
| -------- | -------- |
| ca | 表示日历系统 |
| co | 表示排序规则 |
| hc | 表示守时惯例 |
| nu | 表示数字系统 |
| kn | 表示字符串排序、比较时是否考虑数字的实际值 |
| kf | 表示字符串排序、比较时是否考虑大小写 |
```
```js
var locale = "zh-CN";
var options = {caseFirst: false, calendar: "chinese", collation: pinyin};
var options = {caseFirst: false, calendar: "chinese", collation: "pinyin"};
var localeObj = new intl.Locale(locale, options);
```
......@@ -35,7 +49,7 @@ Intl开发指导提供了ECMA 402中定义的国际化能力接口的使用方
调用toString方法来获取Locale对象的字符串表示,其中包括了语言、区域及其他选项信息。
```
```js
var localeStr = localeObj.toString();
```
......@@ -43,7 +57,7 @@ Intl开发指导提供了ECMA 402中定义的国际化能力接口的使用方
调用maximize方法来最大化区域信息,即当缺少脚本与地区信息时,对其进行补全。
```
```js
var maximizedLocale = localeObj.maximize();
```
......@@ -51,15 +65,13 @@ Intl开发指导提供了ECMA 402中定义的国际化能力接口的使用方
调用minimize方法来最小化区域信息,即当存在脚本与地区信息时,对其进行删除。
```
```js
var minimizedLocale = localeObj.minimize();
```
## 格式化日期时间
调用日期时间格式化[DateTimeFormat](../reference/apis/js-apis-intl.md)的接口,实现针对特定Locale的日期格式化以及时间段格式化功能。
调用日期时间格式化[DateTimeFormat](../reference/apis/js-apis-intl.md#datetimeformat)的接口,实现针对特定Locale的日期格式化以及时间段格式化功能。
### 接口说明
......@@ -71,21 +83,19 @@ Intl开发指导提供了ECMA 402中定义的国际化能力接口的使用方
| ohos.intl | formatRange(startDate:Date,endDate:Date):string | 依据DateTimeFormat对象的Locale及其他格式化属性,计算时间段的格式化表示。 |
| ohos.intl | resolvedOptions():DateTimeOptions | 获取DateTimeFormat对象的相关属性。 |
### 开发步骤
1. 实例化日期时间格式化对象。
一种方法是使用DateTimeFormat提供的默认构造函数,通过访问系统语言和地区设置,获取系统默认Locale,并将其作为DateTimeFormat对象内部的Locale(intl为导入的模块名)。
```
```js
var dateTimeFormat = new intl.DateTimeFormat();
```
另一种方法是使用开发者提供的Locale和格式化参数来创建日期时间格式化对象。其中,格式化参数是可选的,完整的格式化参数列表见[DateTimeOptions](../reference/apis/js-apis-intl.md)。
另一种方法是使用开发者提供的Locale和格式化参数来创建日期时间格式化对象。其中,格式化参数是可选的,完整的格式化参数列表见[DateTimeOptions](../reference/apis/js-apis-intl.md#datetimeoptions)。
```
```js
var options = {dateStyle: "full", timeStyle: "full"};
var dateTimeFormat = new intl.DateTimeFormat("zh-CN", options);
```
......@@ -94,34 +104,33 @@ Intl开发指导提供了ECMA 402中定义的国际化能力接口的使用方
使用DateTimeFormat的format方法对一个Date对象进行格式化,该方法会返回一个字符串作为格式化的结果。
```
Date date = new Date();
```js
var date = new Date();
var formatResult = dateTimeFormat.format(date);
```
3. 格式化时间段。
使用DateTimeFormat的formatRange方法对一个时间段进行格式化。该方法需要传入两个Date对象,分别表示时间段的起止时间,返回一个字符串作为格式化的结果
使用DateTimeFormat的formatRange方法对一个时间段进行格式化。该方法需要传入两个Date对象,分别表示时间段的起止日期,返回一个字符串作为格式化的结果。当传入的两个Date对象表示同一天时,返回对象为该日期的表示;当传入的两个Date对象不是同一天时,返回结果为这两个日期的区间表示
```
Date startDate = new Date();
Date endDate = new Date();
var formatResult = dateTimeFormat.formatRange(startDate, endDate);
```js
var startDate = new Date(2021, 11, 17, 3, 24, 0);
var endDate = new Date(2021, 11, 18, 3, 24, 0);
var datefmt = new Intl.DateTimeFormat("en-GB");
datefmt.formatRange(startDate, endDate);
```
4. 访问日期时间格式化对象的相关属性。
DateTimeFormat的resolvedOptions方法会返回一个对象,该对象包含了DateTimeFormat对象的所有相关属性及其值。
```
```js
var options = dateTimeFormat.resolvedOptions();
```
## 数字格式化
调用数字格式化[NumberFormat](../reference/apis/js-apis-intl.md)的接口,实现针对特定Locale的数字格式化功能。
调用数字格式化[NumberFormat](../reference/apis/js-apis-intl.md#numberformat)的接口,实现针对特定Locale的数字格式化功能。
### 接口说明
......@@ -132,21 +141,19 @@ Intl开发指导提供了ECMA 402中定义的国际化能力接口的使用方
| ohos.intl | format(number:number):string | 依据NumberFormat对象的Locale及其他格式化属性,计算数字的格式化表示。 |
| ohos.intl | resolvedOptions():NumberOptions | 获取NumberFormat对象的相关属性。 |
### 开发步骤
1. 实例化数字格式化对象。
一种方法是使用NumberFormat提供的默认构造函数,通过访问系统的语言和地区以获取系统默认Locale并进行设置(intl为导入的模块名)。
```
```js
var numberFormat = new intl.NumberFormat();
```
另一种方法是使用开发者提供的Locale和格式化参数来创建数字格式化对象。其中,格式化参数是可选的,完整的格式化参数列表参见[NumberOptions](../reference/apis/js-apis-intl.md)。
另一种方法是使用开发者提供的Locale和格式化参数来创建数字格式化对象。其中,格式化参数是可选的,完整的格式化参数列表参见[NumberOptions](../reference/apis/js-apis-intl.md#numberoptions)。
```
```js
var options = {compactDisplay: "short", notation: "compact"};
var numberFormat = new intl.NumberFormat("zh-CN", options);
```
......@@ -155,7 +162,7 @@ Intl开发指导提供了ECMA 402中定义的国际化能力接口的使用方
使用NumberFormat的format方法对传入的数字进行格式化。该方法返回一个字符串作为格式化的结果。
```
```js
var number = 1234.5678
var formatResult = numberFormat.format(number);
```
......@@ -164,15 +171,13 @@ Intl开发指导提供了ECMA 402中定义的国际化能力接口的使用方
NumberFormat的resolvedOptions方法会返回一个对象,该对象包含了NumberFormat对象的所有相关属性及其值。
```
```js
var options = numberFormat.resolvedOptions();
```
## 字符串排序
不同区域的用户对于字符串排序具有不同的需求。调用字符串排序[Collator](../reference/apis/js-apis-intl.md)的接口,实现针对特定Locale的字符串排序功能。
不同区域的用户对于字符串排序具有不同的需求。调用字符串排序[Collator](../reference/apis/js-apis-intl.md#collator8)的接口,实现针对特定Locale的字符串排序功能。
### 接口说明
......@@ -183,29 +188,27 @@ Intl开发指导提供了ECMA 402中定义的国际化能力接口的使用方
| ohos.intl | compare(first:string,second:string):number<sup>8+</sup> | 依据排序对象的Locale及其属性,计算两个字符串的比较结果。 |
| ohos.intl | resolvedOptions():CollatorOptions<sup>8+</sup> | 获取排序对象的相关属性。 |
### 开发步骤
1. 实例化排序对象。
一种方法是使用Collator提供的默认构造函数,通过访问系统的语言和地区以获取系统默认Locale并进行设置(intl为导入的模块名)。
```
```js
var collator = new intl.Collator();
```
另一种方法是使用开发者提供的Locale和其他相关参数来创建Collator对象,完整的参数列表参见[CollatorOptions](../reference/apis/js-apis-intl.md)。
另一种方法是使用开发者提供的Locale和其他相关参数来创建Collator对象,完整的参数列表参见[CollatorOptions](../reference/apis/js-apis-intl.md#collatoroptions8)。
```
var collator= new intl.Collator("zh-CN", {localeMatcher: "best fit", usage: "sort"};
```js
var collator= new intl.Collator("zh-CN", {localeMatcher: "best fit", usage: "sort"});
```
2. 比较字符串。
使用Collator的compare方法对传入的两个字符串进行比较。该方法返回一个数值作为比较的结果,返回-1表示第一个字符串小于第二个字符串,返回1表示第一个字符大于第二个字符串,返回0表示两个字符串相同。
使用Collator的compare方法对传入的两个字符串进行比较。该方法返回一个数值作为比较的结果,返回-1表示第一个字符串小于第二个字符串,返回1表示第一个字符大于第二个字符串,返回0表示两个字符串相同。基于两个字符串的比较结果,开发者可以字符串集合进行排序。
```
```js
var str1 = "first string";
var str2 = "second string";
var compareResult = collator.compare(str1, str2);
......@@ -215,15 +218,13 @@ Intl开发指导提供了ECMA 402中定义的国际化能力接口的使用方
Collator的resolvedOptions方法会返回一个对象,该对象包含了Collator对象的所有相关属性及其值。
```
```js
var options = collator.resolvedOptions();
```
## 判定单复数类别
在一些语言的语法中,当数字后面存在名词时,名词需要根据数字的值采用不同的形式。调用单复数[PluralRules](../reference/apis/js-apis-intl.md)的接口,可以实现针对特定Locale计算数字单复数类别的功能,从而选择合适的名词单复数表示。
在一些语言的语法中,当数字后面存在名词时,名词需要根据数字的值采用不同的形式。调用单复数[PluralRules](../reference/apis/js-apis-intl.md#pluralrules8)的接口,可以实现针对特定Locale计算数字单复数类别的功能,从而选择合适的名词单复数表示。
### 接口说明
......@@ -240,31 +241,28 @@ Intl开发指导提供了ECMA 402中定义的国际化能力接口的使用方
一种方法是使用PluralRules提供的默认构造函数,通过访问系统的语言和地区以获取系统默认Locale并进行设置(intl为导入的模块名)。
```
```js
var pluralRules = new intl.PluralRules();
```
另一种方法是使用开发者提供的Locale和其他相关参数来创建单复数对象。完整的参数列表参见[PluralRulesOptions](../reference/apis/js-apis-intl.md)。
另一种方法是使用开发者提供的Locale和其他相关参数来创建单复数对象。完整的参数列表参见[PluralRulesOptions](../reference/apis/js-apis-intl.md#pluralrulesoptions8)。
```
var plurals = new intl.PluralRules("zh-CN", {localeMatcher: "best fit", type: "cardinal"};
```js
var pluralRules = new intl.PluralRules("zh-CN", {localeMatcher: "best fit", type: "cardinal"});
```
2. 计算数字单复数类别。
使用PluralRules的select方法计算传入数字的单复数类别。该方法返回一个字符串作为传入数字的类别,包括:"zero", "one", "two", "few", "many", "other"六个类别。
```
```js
var number = 1234.5678
var categoryResult = plurals.select(number);
```
## 相对时间格式化
调用相对时间格式化[RelativeTimeFormat](../reference/apis/js-apis-intl.md)的接口,实现针对特定Locale的相对时间格式化功能。
调用相对时间格式化[RelativeTimeFormat](../reference/apis/js-apis-intl.md#relativetimeformat8)的接口,实现针对特定Locale的相对时间格式化功能。
### 接口说明
......@@ -276,29 +274,27 @@ Intl开发指导提供了ECMA 402中定义的国际化能力接口的使用方
| ohos.intl | formatToParts(value:number,unit:string):Array&lt;object&gt;<sup>8+</sup> | 依据相对时间格式化对象的Locale及其他格式化属性,返回相对时间格式化表示的各个部分。 |
| ohos.intl | resolvedOptions():RelativeTimeFormatResolvedOptions<sup>8+</sup> | 获取相对时间格式化对象的相关属性。 |
### 开发步骤
1. 实例化相对时间格式化对象。
一种方法是使用RelativeTimeFormat提供的默认构造函数,通过访问系统的语言和地区以获取系统默认Locale并进行设置(intl为导入的模块名)。
```
```js
var relativeTimeFormat = new intl.RelativeTimeFormat();
```
另一种方法是使用开发者提供的Locale和格式化参数来创建相对时间格式化对象。其中,格式化参数是可选的,完整的参数列表参见[ RelativeTimeFormatInputOptions](../reference/apis/js-apis-intl.md)。
另一种方法是使用开发者提供的Locale和格式化参数来创建相对时间格式化对象。其中,格式化参数是可选的,完整的参数列表参见[ RelativeTimeFormatInputOptions](../reference/apis/js-apis-intl.md#relativetimeformatinputoptions8)。
```
var relativeTimeFormat = new intl.RelativeTimeFormat("zh-CN", {numeric: "always", style: "long"};
var relativeTimeFormat = new intl.RelativeTimeFormat("zh-CN", {numeric: "always", style: "long"});
```
2. 相对时间格式化。
使用RelativeTimeFormat的format方法对相对时间进行格式化。方法接收一个表示相对时间长度的数值和表示单位的字符串,其中单位包括:"year", "quarter", "month", "week", "day", "hour", "minute", "second"。方法返回一个字符串作为格式化的结果。
```
```js
var number = 2;
var unit = "year"
var formatResult = relativeTimeFormat.format(number, unit);
......@@ -308,7 +304,7 @@ Intl开发指导提供了ECMA 402中定义的国际化能力接口的使用方
获取相对时间格式化结果的各个部分,从而自定义格式化结果。
```
```js
var number = 2;
var unit = "year"
var formatResult = relativeTimeFormat.formatToParts(number, unit);
......@@ -316,9 +312,9 @@ Intl开发指导提供了ECMA 402中定义的国际化能力接口的使用方
4. 访问相对时间格式化对象的相关属性。
RelativeTimeFormat的resolvedOptions方法会返回一个对象,该对象包含了RelativeTimeFormat对象的所有相关属性及其值,完整的属性列表参见[ RelativeTimeFormatResolvedOptions](../reference/apis/js-apis-intl.md)。
RelativeTimeFormat的resolvedOptions方法会返回一个对象,该对象包含了RelativeTimeFormat对象的所有相关属性及其值,完整的属性列表参见[ RelativeTimeFormatResolvedOptions](../reference/apis/js-apis-intl.md#relativetimeformatresolvedoptions8)。
```
```js
var options = numberFormat.resolvedOptions();
```
......@@ -326,6 +322,6 @@ Intl开发指导提供了ECMA 402中定义的国际化能力接口的使用方
针对Intl开发,有以下相关实例可供参考:
-[`International`:国际化(JS)(API8)](https://gitee.com/openharmony/app_samples/tree/master/UI/International)
-[`International`:国际化(JS)(API8)](https://gitee.com/openharmony/applications_app_samples/tree/master/UI/International)
-[`International`:国际化(eTS)(API8)](https://gitee.com/openharmony/app_samples/tree/master/common/International)
\ No newline at end of file
-[`International`:国际化(eTS)(API8)(Full SDK)](https://gitee.com/openharmony/applications_app_samples/tree/master/common/International)
\ No newline at end of file
......@@ -282,7 +282,7 @@ let alarm : reminderAgent.ReminderRequestAlarm = {
基于后台代理提醒开发,有以下相关实例可供参考:
- [`AlarmClock`:后台代理提醒(eTS)(API8)](https://gitee.com/openharmony/app_samples/tree/master/Notification/AlarmClock)
- [`AlarmClock`:后台代理提醒(eTS)(API8)](https://gitee.com/openharmony/applications_app_samples/tree/master/Notification/AlarmClock)
- [`FlipClock`:翻页时钟(eTS)(API8)](https://gitee.com/openharmony/app_samples/tree/master/CompleteApps/FlipClock)
- [`FlipClock`:翻页时钟(eTS)(API8)(Full SDK)](https://gitee.com/openharmony/applications_app_samples/tree/master/CompleteApps/FlipClock)
......@@ -2,7 +2,7 @@
# 应用包结构配置文件的说明
在开发FA模型下的应用程序时,需要在config.json文件中对应用的包结构进行申明;同样的,在开发stage模型下的应用程序时,需要在module.json和app.json配置文件中对应用的包结构进行声明。
在开发FA模型下的应用程序时,需要在config.json文件中对应用的包结构进行申明;同样的,在开发stage模型下的应用程序时,需要在module.json5和app.json配置文件中对应用的包结构进行声明。
## 配置文件内部结构
......@@ -66,7 +66,7 @@ app.json示例:
### module对象内部结构
module.json示例:
module.json5示例:
```json
{
......@@ -543,7 +543,7 @@ form示例 :
}
```
在module.json的extension组件下面定义metadata信息
在module.json5的extension组件下面定义metadata信息
```json
{
......@@ -665,7 +665,7 @@ metadata中指定commonEvent信息,其中 :
}
```
在module.json的extension组件下面定义metadata信息,如下 :
在module.json5的extension组件下面定义metadata信息,如下 :
```json
"extensionAbilities": [
......@@ -757,7 +757,7 @@ distroFilter示例 :
]
```
在module.json的extensionAbilities组件下面定义metadata信息,如下 :
在module.json5的extensionAbilities组件下面定义metadata信息,如下 :
```json
"extensionAbilities": [
......
......@@ -157,7 +157,7 @@
- [@ohos.hiAppEvent (应用打点)](js-apis-hiappevent.md)
- [@ohos.hichecker (检测模式)](js-apis-hichecker.md)
- [@ohos.hidebug (Debug调试)](js-apis-hidebug.md)
- [@ohos.hilog (日志打印)](js-apis-hilog.md)
- [@ohos.hilog (HiLog日志打印)](js-apis-hilog.md)
- [@ohos.hiTraceChain (分布式跟踪)](js-apis-hitracechain.md)
- [@ohos.hiTraceMeter (性能打点)](js-apis-hitracemeter.md)
- [@ohos.inputMethod (输入法框架)](js-apis-inputmethod.md)
......@@ -166,6 +166,7 @@
- [@ohos.screenLock (锁屏管理)](js-apis-screen-lock.md)
- [@ohos.systemTime (设置系统时间)](js-apis-system-time.md)
- [@ohos.wallpaper (壁纸)](js-apis-wallpaper.md)
- [console (日志打印)](js-apis-logs.md)
- [Timer (定时器)](js-apis-timer.md)
- 设备管理
......@@ -240,4 +241,3 @@
- [@system.sensor (传感器)](js-apis-system-sensor.md)
- [@system.storage (数据存储)](js-apis-system-storage.md)
- [@system.vibrator (振动)](js-apis-system-vibrate.md)
\ No newline at end of file
- [console (日志打印)](js-apis-logs.md)
\ No newline at end of file
......@@ -193,6 +193,44 @@ context.requestPermissionsFromUser(
```
## Context.requestPermissionsFromUser<sup>7+</sup>
requestPermissionsFromUser(permissions: Array\<string>, requestCode: number): Promise\<[PermissionRequestResult](#permissionrequestresult7)>
从系统请求某些权限(promise形式)。
**系统能力**:SystemCapability.Ability.AbilityRuntime.Core
**参数:**
| 名称 | 类型 | 必填 | 描述 |
| -------------- | ------------------- | ----- | -------------------------------------------- |
| permissions | Array\<string> | 是 | 指示要请求的权限列表。此参数不能为null。 |
| requestCode | number | 是 | 指示要传递给PermissionRequestResult的请求代码。 |
**返回值:**
| 类型 | 说明 |
| ------------------------------------------------------------- | ---------------- |
| Promise\<[PermissionRequestResult](#permissionrequestresult7)> | 返回授权结果信息。 |
**示例:**
```js
import featureAbility from '@ohos.ability.featureAbility'
var context = featureAbility.getContext();
context.requestPermissionsFromUser(
["com.example.permission1",
"com.example.permission2",
"com.example.permission3",
"com.example.permission4",
"com.example.permission5"],
1).then((data)=>{
console.info("====>requestdata====>" + JSON.stringify(data));
});
```
## Context.getApplicationInfo
......
......@@ -126,7 +126,7 @@ var options = {
windowMode: 0,
};
this.context.startAbility(want, options)
.then((data) => {
.then(() => {
console.log('Operation successful.')
}).catch((error) => {
console.log('Operation failed.');
......@@ -273,7 +273,7 @@ var options = {
};
var accountId = 11;
this.context.startAbility(want, accountId, options)
.then((data) => {
.then(() => {
console.log('Operation successful.')
}).catch((error) => {
console.log('Operation failed.');
......@@ -352,7 +352,7 @@ startAbilityForResult(want: Want, options: StartOptions): Promise&lt;AbilityResu
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| want | [Want](js-apis-featureAbility.md#Want) | 是 | 启动Ability的want信息。 |
| options | StartOptions | | 启动Ability所携带的参数。 |
| options | StartOptions | | 启动Ability所携带的参数。 |
**返回值**
......@@ -511,8 +511,8 @@ terminateSelf(): Promise&lt;void&gt;
**示例**
```js
this.context.terminateSelf(want).then((data) => {
console.log('success:' + JSON.stringify(data));
this.context.terminateSelf(want).then(() => {
console.log('success:');
}).catch((error) => {
console.log('failed:' + JSON.stringify(error));
});
......@@ -571,7 +571,7 @@ this.context.terminateSelfWithResult(
{
want: {bundleName: "com.extreme.myapplication", abilityName: "MainAbilityDemo"},
resultCode: 100
}).then((result) => {
}).then(() => {
console.log("terminateSelfWithResult")
})
```
......@@ -768,8 +768,8 @@ setMissionLabel(label: string): Promise\<void>
**示例**
```js
this.context.setMissionLabel("test").then((data) => {
console.log('success:' + JSON.stringify(data));
this.context.setMissionLabel("test").then(() => {
console.log('success:');
}).catch((error) => {
console.log('failed:' + JSON.stringify(error));
});
......
......@@ -22,8 +22,8 @@ import Ability from '@ohos.application.Ability';
| 名称 | 参数类型 | 可读 | 可写 | 说明 |
| -------- | -------- | -------- | -------- | -------- |
| context | [AbilityContext](js-apis-ability-context.md) | 是 | 否 | 上下文。 |
| launchWant | [Want](js-apis-featureAbility.md#Want类型说明) | 是 | 否 | Ability启动时的参数。 |
| lastRequestWant | [Want](js-apis-featureAbility.md#Want类型说明) | 是 | 否 | Ability最后请求时的参数。|
| launchWant | [Want](js-apis-application-want.md) | 是 | 否 | Ability启动时的参数。 |
| lastRequestWant | [Want](js-apis-application-want.md) | 是 | 否 | Ability最后请求时的参数。|
## Ability.onCreate
......@@ -38,7 +38,7 @@ Ability创建时回调,执行初始化业务逻辑操作。
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| want | [Want](js-apis-featureAbility.md#Want类型说明) | 是 | 当前Ability的Want类型信息,包括ability名称、bundle名称等。 |
| want | [Want](js-apis-application-want.md) | 是 | 当前Ability的Want类型信息,包括ability名称、bundle名称等。 |
| param | AbilityConstant.LaunchParam | 是 | 创建&nbsp;ability、上次异常退出的原因信息。 |
**示例:**
......@@ -223,7 +223,7 @@ onNewWant(want: Want): void;
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| want | [Want](js-apis-featureAbility.md#Want类型说明) | 是 | Want类型参数,如ability名称,包名等。 |
| want | [Want](js-apis-application-want.md) | 是 | Want类型参数,如ability名称,包名等。 |
**示例:**
......
......@@ -1269,9 +1269,8 @@ getConnectionDevices(): Array&lt;string&gt;
**返回值:**
| | |
| ------------------- | ------------- |
| 类型 | 说明 |
| ------------------- | ------------- |
| Array&lt;string&gt; | 返回已连接设备的地址列表。 |
......@@ -1290,11 +1289,11 @@ getDeviceState(device: string): ProfileConnectionState
| 参数名 | 类型 | 必填 | 说明 |
| ------ | ------ | ---- | ------- |
| device | string | 是 | 远端设备地址。 |
**返回值:**
| | |
| ------------------------------------------------- | ----------------------- |
| 类型 | 说明 |
| ------------------------------------------------- | ----------------------- |
| [ProfileConnectionState](#profileconnectionstate) | 返回profile的连接状态。 |
......@@ -1318,13 +1317,11 @@ connect(device: string): boolean
| 参数名 | 类型 | 必填 | 说明 |
| ------ | ------ | ---- | ------- |
| device | string | 是 | 远端设备地址。 |
|
**返回值:**
| | |
| ------- | ------------------- |
| 类型 | 说明 |
| ------- | ------------------- |
| boolean | 成功返回true,失败返回false。 |
**示例:**
......@@ -1350,13 +1347,12 @@ disconnect(device: string): boolean
| 参数名 | 类型 | 必填 | 说明 |
| ------ | ------ | ---- | ------- |
| device | string | 是 | 远端设备地址。 |
|
**返回值:**
| | |
| ------- | ------------------- |
| 类型 | 说明 |
| ------- | ------------------- |
| boolean | 成功返回true,失败返回false。 |
**示例:**
......@@ -1443,9 +1439,8 @@ getPlayingState(device: string): PlayingState
**返回值:**
| | |
| ----------------------------- | ---------- |
| 类型 | 说明 |
| ----------------------------- | ---------- |
| [PlayingState](#PlayingState) | 远端设备的播放状态。 |
**示例:**
......@@ -1476,13 +1471,12 @@ connect(device: string): boolean
| 参数名 | 类型 | 必填 | 说明 |
| ------ | ------ | ---- | ------- |
| device | string | 是 | 远端设备地址。 |
|
**返回值:**
| | |
| ------- | ------------------- |
| 类型 | 说明 |
| ------- | ------------------- |
| boolean | 成功返回true,失败返回false。 |
**示例:**
......@@ -1508,7 +1502,7 @@ disconnect(device: string): boolean
| 参数名 | 类型 | 必填 | 说明 |
| ------ | ------ | ---- | ------- |
| device | string | 是 | 远端设备地址。 |
|
**返回值:**
......@@ -1753,9 +1747,8 @@ removeService(serviceUuid: string): boolean
**返回值:**
| | |
| ------- | -------------------------- |
| 类型 | 说明 |
| ------- | -------------------------- |
| boolean | 删除服务操作,成功返回true,否则返回false。 |
**示例:**
......@@ -1803,9 +1796,8 @@ server端特征值发生变化时,主动通知已连接的client设备。
**返回值:**
| | |
| ------- | ------------------------ |
| 类型 | 说明 |
| ------- | ------------------------ |
| boolean | 通知操作,成功返回true,否则返回false。 |
**示例:**
......@@ -1849,9 +1841,8 @@ server端回复client端的读写请求。
**返回值:**
| | |
| ------- | -------------------------- |
| 类型 | 说明 |
| ------- | -------------------------- |
| boolean | 回复响应操作,成功返回true,否则返回false。 |
**示例:**
......@@ -2479,9 +2470,8 @@ client端读取蓝牙低功耗设备特定服务的特征值。
**返回值:**
| | |
| ---------------------------------------- | -------------------------- |
| 类型 | 说明 |
| ---------------------------------------- | -------------------------- |
| Promise&lt;[BLECharacteristic](#blecharacteristic)&gt; | client读取特征值,通过promise形式获取。 |
**示例:**
......@@ -2570,9 +2560,8 @@ client端读取蓝牙低功耗设备特定的特征包含的描述符。
**返回值:**
| | |
| ---------------------------------------- | -------------------------- |
| 类型 | 说明 |
| ---------------------------------------- | -------------------------- |
| Promise&lt;[BLEDescriptor](#bledescriptor)&gt; | client读取描述符,通过promise形式获取。 |
**示例:**
......
# 屏幕亮度
该模块提供屏幕亮度的设置接口。
> ![icon-note.gif](public_sys-resources/icon-note.gif) **说明:**
> 本模块首批接口从API version 7开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。
该模块提供屏幕亮度的设置接口。
## 导入模块
......
......@@ -54,11 +54,11 @@ var context = featureAbility.getContext();
context.getFilesDir().then((filePath) => {
path = filePath;
console.info("======================>getFilesDirPromsie====================>");
});
let storage = data_storage.getStorageSync(path + '/mystore');
storage.putSync('startup', 'auto');
storage.flushSync();
let storage = data_storage.getStorageSync(path + '/mystore');
storage.putSync('startup', 'auto');
storage.flushSync();
});
```
......@@ -87,16 +87,16 @@ var context = featureAbility.getContext();
context.getFilesDir().then((filePath) => {
path = filePath;
console.info("======================>getFilesDirPromsie====================>");
});
data_storage.getStorage(path + '/mystore', function (err, storage) {
data_storage.getStorage(path + '/mystore', function (err, storage) {
if (err) {
console.info("Failed to get the storage. path: " + path + '/mystore');
return;
}
storage.putSync('startup', 'auto');
storage.flushSync();
})
})
});
```
......@@ -130,15 +130,15 @@ var context = featureAbility.getContext();
context.getFilesDir().then((filePath) => {
path = filePath;
console.info("======================>getFilesDirPromsie====================>");
});
let getPromise = data_storage.getStorage(path + '/mystore');
getPromise.then((storage) => {
let getPromise = data_storage.getStorage(path + '/mystore');
getPromise.then((storage) => {
storage.putSync('startup', 'auto');
storage.flushSync();
}).catch((err) => {
}).catch((err) => {
console.info("Failed to get the storage. path: " + path + '/mystore');
})
})
});
```
......@@ -166,12 +166,11 @@ var context = featureAbility.getContext();
context.getFilesDir().then((filePath) => {
path = filePath;
console.info("======================>getFilesDirPromsie====================>");
});
data_storage.deleteStorageSync(path + '/mystore');
data_storage.deleteStorageSync(path + '/mystore');
});
```
## data_storage.deleteStorage
deleteStorage(path: string, callback: AsyncCallback&lt;void&gt;): void
......@@ -197,15 +196,15 @@ var context = featureAbility.getContext();
context.getFilesDir().then((filePath) => {
path = filePath;
console.info("======================>getFilesDirPromsie====================>");
});
data_storage.deleteStorage(path + '/mystore', function (err) {
data_storage.deleteStorage(path + '/mystore', function (err) {
if (err) {
console.info("Failed to delete the storage with err: " + err);
return;
}
console.info("Succeeded in deleting the storage.");
})
})
});
```
......@@ -239,14 +238,14 @@ var context = featureAbility.getContext();
context.getFilesDir().then((filePath) => {
path = filePath;
console.info("======================>getFilesDirPromsie====================>");
});
let promisedelSt = data_storage.deleteStorage(path + '/mystore');
promisedelSt.then(() => {
let promisedelSt = data_storage.deleteStorage(path + '/mystore');
promisedelSt.then(() => {
console.info("Succeeded in deleting the storage.");
}).catch((err) => {
}).catch((err) => {
console.info("Failed to delete the storage with err: " + err);
})
})
});
```
......@@ -273,9 +272,9 @@ var context = featureAbility.getContext();
context.getFilesDir().then((filePath) => {
path = filePath;
console.info("======================>getFilesDirPromsie====================>");
});
data_storage.removeStorageFromCacheSync(path + '/mystore');
data_storage.removeStorageFromCacheSync(path + '/mystore');
});
```
......@@ -304,15 +303,15 @@ var context = featureAbility.getContext();
context.getFilesDir().then((filePath) => {
path = filePath;
console.info("======================>getFilesDirPromsie====================>");
});
data_storage.removeStorageFromCache(path + '/mystore', function (err) {
data_storage.removeStorageFromCache(path + '/mystore', function (err) {
if (err) {
console.info("Failed to remove storage from cache with err: " + err);
return;
}
console.info("Succeeded in removing storage from cache.");
})
})
});
```
......@@ -346,22 +345,20 @@ var context = featureAbility.getContext();
context.getFilesDir().then((filePath) => {
path = filePath;
console.info("======================>getFilesDirPromsie====================>");
});
let promiserevSt = data_storage.removeStorageFromCache(path + '/mystore')
promiserevSt.then(() => {
let promiserevSt = data_storage.removeStorageFromCache(path + '/mystore')
promiserevSt.then(() => {
console.info("Succeeded in removing storage from cache.");
}).catch((err) => {
}).catch((err) => {
console.info("Failed to remove storage from cache with err: " + err);
})
})
});
```
## Storage
提供获取和修改存储数据的接口。
### getSync
getSync(key: string, defValue: ValueType): ValueType
......
......@@ -152,9 +152,9 @@ getAllDisplay(): Promise&lt;Array&lt;Display&gt;&gt;
```js
let promise = display.getAllDisplay();
promise.then((data) => {
console.error('Failed to obtain all the display objects. Code: ' + JSON.stringify(err));
}).catch((err) => {
console.info('Succeeded in obtaining all the display objects. Data: ' + JSON.stringify(data));
}).catch((err) => {
console.error('Failed to obtain all the display objects. Code: ' + JSON.stringify(err));
});
```
......
......@@ -139,7 +139,7 @@ startAbilityForResult(parameter: StartAbilityParameter, callback: AsyncCallback\
**示例:**
```javascript
import featureAbility from '@ohos.ability.featureability';
import featureAbility from '@ohos.ability.featureAbility';
import wantConstant from '@ohos.ability.wantConstant'
featureAbility.startAbilityForResult(
{
......@@ -155,6 +155,9 @@ featureAbility.startAbilityForResult(
uri:""
},
},
(err, data) => {
console.info("err: " + JSON.stringify(err) + "data: " + JSON.stringify(data))
}
)
```
......@@ -181,7 +184,7 @@ startAbilityForResult(parameter: StartAbilityParameter): Promise\<AbilityResult>
**示例:**
```javascript
import featureAbility from '@ohos.ability.featureability';
import featureAbility from '@ohos.ability.featureAbility';
import wantConstant from '@ohos.ability.wantConstant'
featureAbility.startAbilityForResult(
{
......@@ -285,7 +288,7 @@ terminateSelfWithResult(parameter: AbilityResult): Promise\<void>
**示例:**
```javascript
import featureAbility from '@ohos.ability.featureability';
import featureAbility from '@ohos.ability.featureAbility';
import wantConstant from '@ohos.ability.wantConstant'
featureAbility.terminateSelfWithResult(
{
......@@ -336,7 +339,7 @@ hasWindowFocus(callback: AsyncCallback\<boolean>): void
**示例:**
```javascript
import featureAbility from '@ohos.ability.featureability';
import featureAbility from '@ohos.ability.featureAbility';
featureAbility.hasWindowFocus()
```
......@@ -359,7 +362,7 @@ hasWindowFocus(): Promise\<boolean>
**示例:**
```javascript
import featureAbility from '@ohos.ability.featureability';
import featureAbility from '@ohos.ability.featureAbility';
featureAbility.hasWindowFocus().then((data) => {
console.info("==========================>hasWindowFocus=======================>");
});
......@@ -384,7 +387,7 @@ getWant(callback: AsyncCallback\<Want>): void
**示例:**
```javascript
import featureAbility from '@ohos.ability.featureability';
import featureAbility from '@ohos.ability.featureAbility';
featureAbility.getWant()
```
......@@ -407,7 +410,7 @@ getWant(): Promise\<Want>
**示例:**
```javascript
import featureAbility from '@ohos.ability.featureability';
import featureAbility from '@ohos.ability.featureAbility';
featureAbility.getWant().then((data) => {
console.info("==========================>getWantCallBack=======================>");
});
......@@ -430,7 +433,7 @@ getContext(): Context
**示例:**
```javascript
import featureAbility from '@ohos.ability.featureability';
import featureAbility from '@ohos.ability.featureAbility';
var context = featureAbility.getContext()
context.getBundleName()
```
......@@ -454,7 +457,7 @@ terminateSelf(callback: AsyncCallback\<void>): void
**示例:**
```javascript
import featureAbility from '@ohos.ability.featureability';
import featureAbility from '@ohos.ability.featureAbility';
featureAbility.terminateSelf()
```
......@@ -477,7 +480,7 @@ terminateSelf(): Promise\<void>
**示例:**
```javascript
import featureAbility from '@ohos.ability.featureability';
import featureAbility from '@ohos.ability.featureAbility';
featureAbility.terminateSelf().then((data) => { console.info("==========================>terminateSelfCallBack=======================>");
});
```
......
# 日志打印
# HiLog日志打印
hilog日志系统,使应用/服务可以按照指定级别、标识和格式字符串输出日志内容,帮助开发者了解应用/服务的运行状态,更好地调试程序。
......
# 性能打点
本模块提供了踪进程轨迹,度量程序执行性能的打点能力。本模块打点的数据供hiTraceMeter工具分析使用。
本模块提供了踪进程轨迹,度量程序执行性能的打点能力。本模块打点的数据供hiTraceMeter工具分析使用。
> ![icon-note.gif](public_sys-resources/icon-note.gif) **说明:**
> 本模块首批接口从API version 8开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。
......@@ -17,9 +17,9 @@ import hiTraceMeter from '@ohos.hiTraceMeter';
startTrace(name: string, taskId: number): void
标记一个预踪耗时任务的开始。
标记一个预踪耗时任务的开始。
如果有多个相同name的任务需要追踪或者对同一个任务要追踪多次,并且任务同时被执行,则每次调用startTrace的taskId不相同。
如果有多个相同name的任务需要跟踪或者对同一个任务要跟踪多次,并且任务同时被执行,则每次调用startTrace的taskId不相同。
如果具有相同name的任务是串行执行的,则taskId可以相同。具体示例可参考[hiTraceMeter.finishTrace](#hitracemeterfinishtrace)中的示例。
......@@ -29,7 +29,7 @@ startTrace(name: string, taskId: number): void
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| name | string | 是 | 要踪的任务名称 |
| name | string | 是 | 要踪的任务名称 |
| taskId | number | 是 | 任务id |
**示例:**
......@@ -43,7 +43,7 @@ hiTraceMeter.startTrace("myTestFunc", 1);
finishTrace(name: string, taskId: number): void
标记一个预踪耗时任务的结束。
标记一个预踪耗时任务的结束。
finishTrace的name和taskId必须与流程开始的[startTrace](#hitracemeterstarttrace)对应参数值一致。
......@@ -53,7 +53,7 @@ finishTrace的name和taskId必须与流程开始的[startTrace](#hitracemetersta
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| name | string | 是 | 要踪的任务名称 |
| name | string | 是 | 要踪的任务名称 |
| taskId | number | 是 | 任务id。 |
**示例:**
......@@ -63,10 +63,10 @@ hiTraceMeter.finishTrace("myTestFunc", 1);
```
```js
//踪并行执行的同名任务
//踪并行执行的同名任务
hiTraceMeter.startTrace("myTestFunc", 1);
//业务流程......
hiTraceMeter.startTrace("myTestFunc", 2); //第二个追踪的任务开始,同时第一个追踪的同名任务还没结束,出现了并行执行,对应接口的taskId需要不同。
hiTraceMeter.startTrace("myTestFunc", 2); //第二个跟踪的任务开始,同时第一个跟踪的同名任务还没结束,出现了并行执行,对应接口的taskId需要不同。
//业务流程......
hiTraceMeter.finishTrace("myTestFunc", 1);
//业务流程......
......@@ -74,12 +74,12 @@ hiTraceMeter.finishTrace("myTestFunc", 2);
```
```js
//踪串行执行的同名任务
//踪串行执行的同名任务
hiTraceMeter.startTrace("myTestFunc", 1);
//业务流程......
hiTraceMeter.finishTrace("myTestFunc", 1); //第一个踪的任务结束
hiTraceMeter.finishTrace("myTestFunc", 1); //第一个踪的任务结束
//业务流程......
hiTraceMeter.startTrace("myTestFunc", 1); //第二个追踪的同名任务开始,同名的待追踪任务串行执行。
hiTraceMeter.startTrace("myTestFunc", 1); //第二个跟踪的同名任务开始,同名的待跟踪任务串行执行。
//业务流程......
hiTraceMeter.finishTrace("myTestFunc", 1);
```
......@@ -89,7 +89,7 @@ hiTraceMeter.finishTrace("myTestFunc", 1);
traceByValue(name: string, count: number): void
用来标记一个预踪的数值变量,该变量的数值会不断变化。
用来标记一个预踪的数值变量,该变量的数值会不断变化。
**系统能力:** SystemCapability.HiviewDFX.HiTrace
......@@ -97,7 +97,7 @@ traceByValue(name: string, count: number): void
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| name | string | 是 | 要踪的数值变量名称 |
| name | string | 是 | 要踪的数值变量名称 |
| count | number | 是 | 变量的值 |
**示例:**
......
# 国际化-Intl
> ![icon-note.gif](public_sys-resources/icon-note.gif) **说明:**
本模块提供提供基础的应用国际化能力,包括时间日期格式化、数字格式化、排序等,相关接口在ECMA 402标准中定义。
[I18N模块](js-apis-i18n.md)提供其他非ECMA 402定义的国际化接口,与本模块共同使用可提供完整地国际化支持能力。
> **说明:**
> - 本模块首批接口从API version 6开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。
>
> - Intl模块包含国际化能力基础接口(在ECMA 402中定义)。
> - Intl模块包含国际化能力基础接口(在ECMA 402中定义),包括时间日期格式化、数字格式化、排序等,国际化增强能力请参考[I18N模块](js-apis-i18n.md)
## 导入模块
```
```js
import Intl from '@ohos.intl';
```
......@@ -43,7 +46,7 @@ constructor()
**系统能力**:SystemCapability.Global.I18n
**示例:**
```
```js
var locale = new Intl.Locale();
```
......@@ -63,7 +66,7 @@ constructor(locale: string, options?: LocaleOptions)
| options | LocaleOptions | 否 | 用于创建区域对象的选项。 |
**示例:**
```
```js
var locale = new Intl.Locale("zh-CN");
```
......@@ -82,7 +85,7 @@ toString(): string
| string | 字符串形式的区域信息。 |
**示例:**
```
```js
var locale = new Intl.Locale("zh-CN");
locale.toString();
```
......@@ -102,7 +105,7 @@ maximize(): Locale
| [Locale](#locale) | 最大化后的区域对象。 |
**示例:**
```
```js
var locale = new Intl.Locale("zh-CN");
locale.maximize();
```
......@@ -122,7 +125,7 @@ minimize(): Locale
| [Locale](#locale) | 最小化后的区域对象。 |
**示例:**
```
```js
var locale = new Intl.Locale("zh-CN");
locale.minimize();
```
......@@ -132,7 +135,7 @@ minimize(): Locale
表示区域初始化选项。
**系统能力**以下各项对应的系统能力均为SystemCapability.Global.I18n
**系统能力**:SystemCapability.Global.I18n
| 名称 | 参数类型 | 可读 | 可写 | 说明 |
| --------------- | ------- | ---- | ---- | ---------------------------------------- |
......@@ -156,7 +159,7 @@ constructor()
**系统能力**:SystemCapability.Global.I18n
**示例:**
```
```js
var datefmt= new Intl.DateTimeFormat();
```
......@@ -176,13 +179,13 @@ constructor(locale: string | Array&lt;string&gt;, options?: DateTimeOptions)
| options | [DateTimeOptions](#datetimeoptions) | 否 | 用于创建时间日期格式化的选项。 |
**示例:**
```
```js
var datefmt= new Intl.DateTimeFormat("zh-CN", { dateStyle: 'full', timeStyle: 'medium' });
```
**示例:**
```
```js
var datefmt= new Intl.DateTimeFormat(["ban", "zh"], { dateStyle: 'full', timeStyle: 'medium' });
```
......@@ -206,7 +209,7 @@ format(date: Date): string
| string | 格式化后的时间日期字符串 |
**示例:**
```
```js
var date = new Date(2021, 11, 17, 3, 24, 0);
var datefmt = new Intl.DateTimeFormat("en-GB");
datefmt.format(date);
......@@ -233,7 +236,7 @@ formatRange(startDate: Date, endDate: Date): string
| string | 格式化后的时间日期段字符串。 |
**示例:**
```
```js
var startDate = new Date(2021, 11, 17, 3, 24, 0);
var endDate = new Date(2021, 11, 18, 3, 24, 0);
var datefmt = new Intl.DateTimeFormat("en-GB");
......@@ -255,7 +258,7 @@ resolvedOptions(): DateTimeOptions
| [DateTimeOptions](#datetimeoptions) | DateTimeFormat&nbsp;对象的格式化选项。 |
**示例:**
```
```js
var datefmt = new Intl.DateTimeFormat("en-GB");
datefmt.resolvedOptions();
```
......@@ -265,7 +268,7 @@ resolvedOptions(): DateTimeOptions
表示时间日期格式化选项。
**系统能力**以下各项对应的系统能力均为SystemCapability.Global.I18n
**系统能力**:SystemCapability.Global.I18n
| 名称 | 参数类型 | 可读 | 可写 | 说明 |
| --------------- | ------- | ---- | ---- | ---------------------------------------- |
......@@ -302,7 +305,7 @@ constructor()
**系统能力**:SystemCapability.Global.I18n
**示例:**
```
```js
var numfmt = new Intl.NumberFormat();
```
......@@ -322,7 +325,7 @@ constructor(locale: string | Array&lt;string&gt;, options?: NumberOptions)
| options | [NumberOptions](#numberoptions) | 否 | 用于创建数字格式化的选项。 |
**示例:**
```
```js
var numfmt = new Intl.NumberFormat("en-GB", {style:'decimal', notation:"scientific"});
```
......@@ -347,7 +350,7 @@ format(number: number): string;
**示例:**
```
```js
var numfmt = new Intl.NumberFormat(["en-GB", "zh"], {style:'decimal', notation:"scientific"});
numfmt.format(1223);
```
......@@ -368,7 +371,7 @@ resolvedOptions(): NumberOptions
**示例:**
```
```js
var numfmt = new Intl.NumberFormat(["en-GB", "zh"], {style:'decimal', notation:"scientific"});
numfmt.resolvedOptions();
```
......@@ -415,7 +418,7 @@ constructor()
**系统能力**:SystemCapability.Global.I18n
**示例:**
```
```js
var collator = new Intl.Collator();
```
......@@ -436,7 +439,7 @@ constructor(locale: string | Array&lt;string&gt;, options?: CollatorOptions)
| options | [CollatorOptions](#collatoroptions) | 否 | 用于创建排序对象的选项。 |
**示例:**
```
```js
var collator = new Intl.Collator("zh-CN", {localeMatcher: "lookup", usage: "sort"});
```
......@@ -461,7 +464,7 @@ compare(first: string, second: string): number
| number | 比较结果。当number为负数,表示first排序在second之前;当number为0,表示first与second排序相同;当number为正数,表示first排序在second之后。 |
**示例:**
```
```js
var collator = new Intl.Collator("zh-Hans");
collator.compare("first", "second");
```
......@@ -481,17 +484,17 @@ resolvedOptions(): CollatorOptions
| [CollatorOptions](#collatoroptions) | 返回的Collator对象的属性。 |
**示例:**
```
```js
var collator = new Intl.Collator("zh-Hans");
var options = collator.resolvedOptions();
```
## CollatorOptions<sup>8+</sup><a name=collatoroptions></a>
## CollatorOptions<sup>8+</sup>
表示Collator可设置的属性。
**系统能力**以下各项对应的系统能力均为SystemCapability.Global.I18n
**系统能力**:SystemCapability.Global.I18n
| 名称 | 参数类型 | 可读 | 可写 | 说明 |
| ----------------- | ------- | ---- | ---- | ---------------------------------------- |
......@@ -516,7 +519,7 @@ constructor()
**系统能力**:SystemCapability.Global.I18n
**示例:**
```
```js
var pluralRules = new Intl.PluralRules();
```
......@@ -536,8 +539,8 @@ constructor(locale: string | Array&lt;string&gt;, options?: PluralRulesOptions)
| options | [PluralRulesOptions](#pluralrulesoptions) | 否 | 用于创建单复数对象的选项。 |
**示例:**
```
var pluralRules= new Intl.PluraRules("zh-CN", {"localeMatcher": "lookup", "type": "cardinal"});
```js
var pluralRules= new Intl.PluralRules("zh-CN", {"localeMatcher": "lookup", "type": "cardinal"});
```
......@@ -560,17 +563,17 @@ select(n: number): string
| string | 单复数类别,取值包括:"zero","one","two",&nbsp;"few",&nbsp;"many",&nbsp;"others"。 |
**示例:**
```
```js
var pluralRules = new Intl.PluralRules("zh-Hans");
pluralRules.select(1);
```
## PluralRulesOptions<sup>8+</sup><a name=pluralrulesoptions></a>
## PluralRulesOptions<sup>8+</sup>
表示PluralRules对象可设置的属性。
**系统能力**以下各项对应的系统能力均为SystemCapability.Global.I18n
**系统能力**:SystemCapability.Global.I18n
| 名称 | 参数类型 | 可读 | 可写 | 说明 |
| ------------------------ | ------ | ---- | ---- | ---------------------------------------- |
......@@ -595,7 +598,7 @@ constructor()
**系统能力**:SystemCapability.Global.I18n
**示例:**
```
```js
var relativetimefmt = new Intl.RelativeTimeFormat();
```
......@@ -615,7 +618,7 @@ constructor(locale: string | Array&lt;string&gt;, options?: RelativeTimeFormatIn
| options | [RelativeTimeFormatInputOptions](#relativetimeformatinputoptions) | 否 | 用于创建相对时间格式化对象的选项。 |
**示例:**
```
```js
var relativeTimeFormat = new Intl.RelativeTimeFormat("zh-CN", {"localeMatcher": "lookup", "numeric": "always", "style": "long"});
```
......@@ -640,7 +643,7 @@ format(value: number, unit: string): string
| string | 格式化后的相对时间。 |
**示例:**
```
```js
var relativetimefmt = new Intl.RelativeTimeFormat("zh-CN");
relativetimefmt.format(3, "quarter")
```
......@@ -666,7 +669,7 @@ formatToParts(value: number, unit: string): Array&lt;object&gt;
| Array&lt;object&gt; | 返回可用于自定义区域设置格式的相对时间格式的对象数组。 |
**示例:**
```
```js
var relativetimefmt = new Intl.RelativeTimeFormat("en", {"numeric": "auto"});
var parts = relativetimefmt.format(10, "seconds");
```
......@@ -686,17 +689,17 @@ resolvedOptions(): RelativeTimeFormatResolvedOptions
| [RelativeTimeFormatResolvedOptions](#relativetimeformatresolvedoptions) | RelativeTimeFormat&nbsp;对象的格式化选项。 |
**示例:**
```
```js
var relativetimefmt= new Intl.RelativeTimeFormat("en-GB");
relativetimefmt.resolvedOptions();
```
## RelativeTimeFormatInputOptions<sup>8+</sup><a name=relativetimeformatinputoptions></a>
## RelativeTimeFormatInputOptions<sup>8+</sup>
表示RelativeTimeFormat对象可设置的属性。
**系统能力**以下各项对应的系统能力均为SystemCapability.Global.I18n
**系统能力**:SystemCapability.Global.I18n
| 名称 | 参数类型 | 可读 | 可写 | 说明 |
| ------------- | ------ | ---- | ---- | ---------------------------------------- |
......@@ -705,11 +708,11 @@ resolvedOptions(): RelativeTimeFormatResolvedOptions
| style | string | 是 | 是 | 国际化消息的长度,取值包括:"long",&nbsp;"short",&nbsp;"narrow"。 |
## RelativeTimeFormatResolvedOptions<sup>8+</sup><a name=relativetimeformatresolvedoptions></a>
## RelativeTimeFormatResolvedOptions<sup>8+</sup>
表示RelativeTimeFormat对象可设置的属性。
**系统能力**以下各项对应的系统能力均为SystemCapability.Global.I18n
**系统能力**:SystemCapability.Global.I18n
| 名称 | 参数类型 | 可读 | 可写 | 说明 |
| --------------- | ------ | ---- | ---- | ---------------------------------------- |
......
# 日志打印
> ![icon-note.gif](public_sys-resources/icon-note.gif) **说明:**
> 从API Version 7 开始,该接口不再维护,推荐使用新接口[`@ohos.hilog`](js-apis-hilog.md)'。
本模块提供基础的日志打印能力,支持按照日志级别打印日志信息。
如果需要使用更高级的日志打印服务,比如按照指定标识筛选日志内容,推荐使用[`@ohos.hilog`](js-apis-hilog.md)
> **说明:**
>
> 本模块首批接口从API version 3开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。
## console.debug
......@@ -9,10 +14,13 @@ debug(message: string): void
打印debug级别的日志信息。
- 参数
| 参数名 | 类型 | 必填 | 说明 |
| ------- | ------ | ---- | ----------- |
| message | string | 是 | 表示要打印的文本信息。 |
**系统能力:** SystemCapability.ArkUI.ArkUI.Full
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| ------- | ------ | ---- | ----------- |
| message | string | 是 | 表示要打印的文本信息。 |
## console.log
......@@ -21,10 +29,13 @@ log(message: string): void
打印debug级别的日志信息。
- 参数
| 参数名 | 类型 | 必填 | 说明 |
| ------- | ------ | ---- | ----------- |
| message | string | 是 | 表示要打印的文本信息。 |
**系统能力:** SystemCapability.ArkUI.ArkUI.Full
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| ------- | ------ | ---- | ----------- |
| message | string | 是 | 表示要打印的文本信息。 |
## console.info
......@@ -33,10 +44,13 @@ info(message: string): void
打印info级别的日志信息。
- 参数
| 参数名 | 类型 | 必填 | 说明 |
| ------- | ------ | ---- | ----------- |
| message | string | 是 | 表示要打印的文本信息。 |
**系统能力:** SystemCapability.ArkUI.ArkUI.Full
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| ------- | ------ | ---- | ----------- |
| message | string | 是 | 表示要打印的文本信息。 |
## console.warn
......@@ -45,10 +59,13 @@ warn(message: string): void
打印warn级别的日志信息。
- 参数
| 参数名 | 类型 | 必填 | 说明 |
| ------- | ------ | ---- | ----------- |
| message | string | 是 | 表示要打印的文本信息。 |
**系统能力:** SystemCapability.ArkUI.ArkUI.Full
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| ------- | ------ | ---- | ----------- |
| message | string | 是 | 表示要打印的文本信息。 |
## console.error
......@@ -57,10 +74,13 @@ error(message: string): void
打印error级别的日志信息。
- 参数
| 参数名 | 类型 | 必填 | 说明 |
| ------- | ------ | ---- | ----------- |
| message | string | 是 | 表示要打印的文本信息。 |
**系统能力:** SystemCapability.ArkUI.ArkUI.Full
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| ------- | ------ | ---- | ----------- |
| message | string | 是 | 表示要打印的文本信息。 |
## 示例
......
......@@ -3055,7 +3055,7 @@ Notification.subscribe(subscriber, subscribeCallback);
| desc | 是 | 是 | string | 否 | 通知渠道描述信息。 |
| badgeFlag | 是 | 是 | boolean | 否 | 是否显示角标。 |
| bypassDnd | 是 | 是 | boolean | 否 | 置是否在系统中绕过免打扰模式。 |
| lockscreenVisibility | 是 | 是 | boolean | 否 | 在锁定屏幕上显示通知的模式。 |
| lockscreenVisibility | 是 | 是 | number | 否 | 在锁定屏幕上显示通知的模式。 |
| vibrationEnabled | 是 | 是 | boolean | 否 | 是否可振动。 |
| sound | 是 | 是 | string | 否 | 通知提示音。 |
| lightEnabled | 是 | 是 | boolean | 否 | 是否闪灯。 |
......
# 电量信息
> ![icon-note.gif](public_sys-resources/icon-note.gif) **说明:**
> **说明:**
> - 从API Version 6开始,该接口不再维护,推荐使用新接口[`@ohos.batteryInfo`](js-apis-battery-info.md)。
>
> - 本模块首批接口从API version 3开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。
......@@ -26,16 +26,9 @@ getStatus(Object): void
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| success | Function | 否 | 接口调用成功的回调函数。 |
| fail | Function | 否 | 接口调用失败的回调函数。 |
| complete | Function | 否 | 接口调用结束的回调函数。 |
success返回值:
| 参数名 | 类型 | 说明 |
| -------- | -------- | -------- |
| charging | boolean | 当前电池是否在充电中。 |
| level | number | 当前电池的电量,取值范围:0.00&nbsp;-&nbsp;1.00&nbsp;。 |
| success | (data: [BatteryResponse](#batteryresponse)) => void | 否 | 接口调用成功的回调函数。|
| fail | (data: string, code: number) => void | 否 | 接口调用失败的回调函数。|
| complete | () => void | 否 | 接口调用结束的回调函数。 |
**示例:**
......@@ -53,3 +46,10 @@ export default {
},
}
```
## BatteryResponse
| 参数名 | 类型 | 说明 |
| -------- | -------- | -------- |
| charging | boolean | 当前电池是否在充电中。 |
| level | number | 当前电池的电量,取值范围:0.00&nbsp;-&nbsp;1.00&nbsp;。 |
此差异已折叠。
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册