“ef04dfd60154f5b0ab5346bb3b4a22eceb0ba2ca”上不存在“...release-notes/api-diff/v3.2-beta4/js-apidiff-account.md”
提交 dfcd5710 编写于 作者: J junyi233 提交者: Gitee

扫描缺陷修改

...@@ -78,9 +78,9 @@ The ability assistant is pre-installed in the device environment. You can direct ...@@ -78,9 +78,9 @@ The ability assistant is pre-installed in the device environment. You can direct
| -l/--mission-list | type (All logs are printed if this parameter is left unspecified.)| Prints mission stack information.<br>The following values are available for **type**:<br>- NORMAL <br>- DEFAULT_STANDARD<br>- DEFAULT_SINGLE<br>- LAUNCHER | | -l/--mission-list | type (All logs are printed if this parameter is left unspecified.)| Prints mission stack information.<br>The following values are available for **type**:<br>- NORMAL <br>- DEFAULT_STANDARD<br>- DEFAULT_SINGLE<br>- LAUNCHER |
| -e/--extension | elementName | Prints extended component information. | | -e/--extension | elementName | Prints extended component information. |
| -u/--userId | UserId | Prints stack information of a specified user ID. This parameter must be used together with other parameters.<br>Example commands: aa **dump -a -u 100** and **aa dump -d -u 100**| | -u/--userId | UserId | Prints stack information of a specified user ID. This parameter must be used together with other parameters.<br>Example commands: aa **dump -a -u 100** and **aa dump -d -u 100**|
| -d/--data | | Prints Data ability information. | | -d/--data | - | Prints Data ability information. |
| -i/--ability | AbilityRecord ID | Prints detailed information about a specified ability. | | -i/--ability | AbilityRecord ID | Prints detailed information about a specified ability. |
| -c/--client | | Prints detailed ability information. This parameter must be used together with other parameters.<br>Example commands: **aa dump -a -c** and **aa dump -i 21 -c**| | -c/--client | - | Prints detailed ability information. This parameter must be used together with other parameters.<br>Example commands: **aa dump -a -c** and **aa dump -i 21 -c**|
**Method** **Method**
......
...@@ -132,7 +132,9 @@ You can also include **parameters** in the **want** parameter and set its value ...@@ -132,7 +132,9 @@ You can also include **parameters** in the **want** parameter and set its value
); );
``` ```
### Starting a Remote Page Ability ### Starting a Remote Page Ability
>Note: This feature applies only to system applications, since the **getTrustedDeviceListSync** API of the **DeviceManager** class is open only to system applications. >Note
>
>This feature applies only to system applications, since the **getTrustedDeviceListSync** API of the **DeviceManager** class is open only to system applications.
**Modules to Import** **Modules to Import**
......
...@@ -166,7 +166,7 @@ let connId = featureAbility.connectAbility( ...@@ -166,7 +166,7 @@ let connId = featureAbility.connectAbility(
); );
``` ```
When a Service ability is connected, the **onConnect()** callback is invoked and returns an **IRemoteObject** defining the proxy used for communicating with the Service ability. OpenHarmony provides a default implementation of the **IRemoteObject** interface. You can extend **rpc.RemoteObject** to implement your own class of **IRemoteObject**. When a Service ability is connected, the **onConnect()** callback is invoked and returns an **IRemoteObject** defining the proxy used for communicating with the Service ability. OpenHarmony provides a default implementation of **IRemoteObject**. You can extend **rpc.RemoteObject** to implement your own class of **IRemoteObject**.
The following code snippet shows how the Service ability instance returns itself to the calling ability: The following code snippet shows how the Service ability instance returns itself to the calling ability:
......
...@@ -119,7 +119,7 @@ The following table lists the APIs used for ability continuation. For details ab ...@@ -119,7 +119,7 @@ The following table lists the APIs used for ability continuation. For details ab
```javascript ```javascript
onContinue(wantParam : {[key: string]: any}) { onContinue(wantParam : {[key: string]: any}) {
Logger.info("onContinue using distributedObject") Logger.info("onContinue using distributedObject")
// Set the user input data into the want parameter. // Set the user input data into want params.
wantParam["input"] = AppStorage.Get<string>('ContinueInput'); wantParam["input"] = AppStorage.Get<string>('ContinueInput');
Logger.info(`onContinue input = ${wantParam["input"]}`); Logger.info(`onContinue input = ${wantParam["input"]}`);
return AbilityConstant.OnContinueResult.AGREE return AbilityConstant.OnContinueResult.AGREE
......
...@@ -12,7 +12,8 @@ Basic concepts: ...@@ -12,7 +12,8 @@ Basic concepts:
- Widget host: an application that displays the widget content and controls the position where the widget is displayed in the host application. - Widget host: an application that displays the widget content and controls the position where the widget is displayed in the host application.
- Widget Manager: a resident agent that manages widgets added to the system and provides functions such as periodic widget update. - Widget Manager: a resident agent that manages widgets added to the system and provides functions such as periodic widget update.
> ![icon-note.gif](public_sys-resources/icon-note.gif) **NOTE** > **NOTE**
>
> The widget host and provider do not keep running all the time. The Widget Manager starts the widget provider to obtain widget information when a widget is added, deleted, or updated. > The widget host and provider do not keep running all the time. The Widget Manager starts the widget provider to obtain widget information when a widget is added, deleted, or updated.
You only need to develop widget content as the widget provider. The system automatically handles the work done by the widget host and Widget Manager. You only need to develop widget content as the widget provider. The system automatically handles the work done by the widget host and Widget Manager.
...@@ -254,7 +255,7 @@ Data of a temporary widget is not persistently stored. If it is deleted from the ...@@ -254,7 +255,7 @@ Data of a temporary widget is not persistently stored. If it is deleted from the
### Updating Widget Data ### Updating Widget Data
When a widget application initiates a data update upon a scheduled or periodic update, the application obtains the latest data and calls **updateForm** to update the widget. The code snippet is as follows: When a widget application initiates a data update upon a scheduled or periodic update, the application obtains the latest data and calls **updateForm** to update the widget. The sample code is as follows:
```javascript ```javascript
onUpdate(formId) { onUpdate(formId) {
......
# Service Extension Ability Development # Service Extension Ability Development
## When to Use ## When to Use
**ExtensionAbility** is the base class of the new Extension component in the stage model. It is used to process missions without UIs. The lifecycle of an Extension ability is simple and does not involve foreground or background. **ServiceExtensionAbility** is extended from **ExtensionAbility**. **ExtensionAbility** is the base class of the new Extension component in the stage model. It is used to process missions without UIs. The lifecycle of an Extension ability is simple and does not involve foreground or background states. **ServiceExtensionAbility** is extended from **ExtensionAbility**.
You can customize a class that inherits from **ServiceExtensionAbility** and override the lifecycle callbacks in the base class to perform service logic operations during the initialization, connection, and disconnection processes. You can customize a class that inherits from **ServiceExtensionAbility** and override the lifecycle callbacks in the base class to perform service logic operations during the initialization, connection, and disconnection processes.
## Available APIs ## Available APIs
**Table 1** ServiceExtensionAbility lifecycle callbacks **Table 1** ServiceExtensionAbility lifecycle APIs
|API|Description| |API|Description|
|:------|:------| |:------|:------|
|onCreate|Called for the initialization when **startAbility** or **connectAbility** is invoked for a given ability for the first time.| |onCreate(want: Want): void|Called for the initialization when **startAbility** or **connectAbility** is invoked for a given ability for the first time.|
|onRequest|Called each time **startAbility** is invoked for a given ability. The initial value of **startId** is 1, and the value is incremented by one each time **startAbility** is invoked for that ability.| |onRequest(want: Want, startId: number): void|Called each time **startAbility** is invoked for a given ability. The initial value of **startId** is **1**, and the value is incremented by one each time **startAbility** is invoked for that ability.|
|onConnect|Called when **connectAbility** is invoked for a given ability. This callback is not invoked for repeated calling of **connectAbility** for a specific ability. However, it will be invoked when **disconnectAbility** is called to disconnect an ability and then **connectAbility** is called to connect the ability again. The returned result is a **RemoteObject**.| |onConnect(want: Want): rpc.RemoteObject|Called when **connectAbility** is invoked for a given ability. This callback is not invoked for repeated calling of **connectAbility** for a specific ability. However, it will be invoked unless **connectAbility** is called after the ability has been disconnected using **disconnectAbility**. The returned result is a **RemoteObject**.|
|onDisconnect|Called when **disconnectAbility** is called for a given ability. If the Extension ability is started by **connectAbility** and is not bound by other applications, the **onDestroy** callback will also be triggered to destroy the Extension ability.| |onDisconnect(want: Want): void|Called when **disconnectAbility** is called for a given ability. If the Extension ability is started by **connectAbility** and is not bound to other applications, the **onDestroy** callback will also be triggered to destroy the Extension ability.|
|onDestroy|Called when **terminateSelf** is invoked to terminate the ability.| |onDestroy(): void|Called when **terminateSelf** is invoked to terminate the ability.|
## Constraints ## Constraints
- Currently, OpenHarmony does not support creation of a Service Extension ability for third-party applications. OpenHarmony does not support creation of a Service Extension ability for third-party applications.
## How to Develop ## How to Develop
1. Create a Service Extension ability. 1. Create a Service Extension ability.
Customize a class that inherits from **ServiceExtensionAbility** in the .ts file 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 and override the lifecycle callbacks of the base class. The code sample is as follows:
```js ```js
import rpc from '@ohos.rpc' import rpc from '@ohos.rpc'
...@@ -61,9 +61,9 @@ Customize a class that inherits from **ServiceExtensionAbility** in the .ts file ...@@ -61,9 +61,9 @@ Customize a class that inherits from **ServiceExtensionAbility** in the .ts file
2. Register the Service Extension ability. 2. Register the Service Extension ability.
Declare the Service Extension ability in the **module.json** file by setting its **type** attribute to **service**. Declare the Service Extension ability in the **module.json** file by setting its **type** attribute to **service**.
**module.json configuration example** **module.json configuration example**
```json ```json
"extensionAbilities":[{ "extensionAbilities":[{
...@@ -76,9 +76,7 @@ Declare the Service Extension ability in the **module.json** file by setting its ...@@ -76,9 +76,7 @@ Declare the Service Extension ability in the **module.json** file by setting its
}] }]
``` ```
## Development Example ## Samples
The following sample is provided to help you better understand how to develop a Service Extension ability:
- [`ServiceExtAbility`: Stage Extension Ability Creation and Usage (eTS, API version 9)](https://gitee.com/openharmony/app_samples/tree/master/ability/ServiceExtAbility)
The following sample is provided to help you better understand how to develop Service Extension abilities:
- [`ServiceExtAbility`: Stage Extension Ability Creation and Usage (eTS, API version 9)](https://gitee.com/openharmony/app_samples/tree/master/ability/StageCallAbility)
# video # video
> **NOTE**<br> > **NOTE**
> >
> - This component is supported since API version 4. Updates will be marked with a superscript to indicate their earliest API version. > - This component is supported since API version 4. Updates will be marked with a superscript to indicate their earliest API version.
> >
...@@ -15,7 +15,7 @@ ...@@ -15,7 +15,7 @@
> ] > ]
> ``` > ```
The **\<Video>** component provides a video player. The **\<video>** component provides a video player.
## Child Components ## Child Components
...@@ -76,7 +76,8 @@ In addition to the [universal methods](../arkui-js/js-components-common-methods. ...@@ -76,7 +76,8 @@ In addition to the [universal methods](../arkui-js/js-components-common-methods.
| pause | - | Pauses a video.| | pause | - | Pauses a video.|
| setCurrentTime | {&nbsp;currenttime:&nbsp;value&nbsp;} | Sets the video playback position, in seconds.| | setCurrentTime | {&nbsp;currenttime:&nbsp;value&nbsp;} | Sets the video playback position, in seconds.|
> **NOTE**<br> > **NOTE**
>
> The methods in the above table can be called after the **attached** callback is invoked. > The methods in the above table can be called after the **attached** callback is invoked.
## Example ## Example
...@@ -89,7 +90,7 @@ In addition to the [universal methods](../arkui-js/js-components-common-methods. ...@@ -89,7 +90,7 @@ In addition to the [universal methods](../arkui-js/js-components-common-methods.
onpaues='pauesCallback' onfinish='finishCallback' onerror='errorCallback' onpaues='pauesCallback' onfinish='finishCallback' onerror='errorCallback'
onseeking='seekingCallback' onseeked='seekedCallback' onseeking='seekingCallback' onseeked='seekedCallback'
ontimeupdate='timeupdateCallback' ontimeupdate='timeupdateCallback'
style="object-fit:fit; width:80%; height:400px;" style="object-fit:fill; width:80%; height:400px;"
onclick="change_start_pause"> onclick="change_start_pause">
</video> </video>
</div> </div>
......
...@@ -54,7 +54,7 @@ ImageAnimator() ...@@ -54,7 +54,7 @@ ImageAnimator()
## Events ## Events
| Name | Description | | Name | Description |
| -------- | -------- | -------- | | -------- | -------- |
| onStart() =&gt; void | Triggered when the animation starts to play. | | onStart() =&gt; void | Triggered when the animation starts to play. |
| onPause() =&gt; void | Triggered when the animation playback is paused. | | onPause() =&gt; void | Triggered when the animation playback is paused. |
| onRepeat() =&gt; void | Triggered when the animation playback is repeated. | | onRepeat() =&gt; void | Triggered when the animation playback is repeated. |
......
# Progress # Progress
> ![icon-note.gif](public_sys-resources/icon-note.gif) **NOTE** > **NOTE**
>
> This component is supported since API version 7. Updates will be marked with a superscript to indicate their earliest API version. > This component is supported since API version 7. Updates will be marked with a superscript to indicate their earliest API version.
The **&lt;Progress&gt;** component is used to provide a progress bar that displays the progress of content loading or an operation. The **\<Progress>** component is used to provide a progress bar that displays the progress of content loading or an operation.
## Required Permissions ## Required Permissions
...@@ -15,12 +16,12 @@ None ...@@ -15,12 +16,12 @@ None
## Child Components ## Child Components
None Not supported
## APIs ## APIs
Progress(value: { value: number, total?: number, type?: ProgressType}) Progress(value: {value: number, total?: number, type?: ProgressType})
Creates a progress bar. Creates a progress bar.
...@@ -54,7 +55,8 @@ Creates a progress bar. ...@@ -54,7 +55,8 @@ Creates a progress bar.
## Example ## Example
``` ```ts
// xxx.ets
@Entry @Entry
@Component @Component
struct ProgressExample { struct ProgressExample {
...@@ -88,8 +90,8 @@ struct ProgressExample { ...@@ -88,8 +90,8 @@ struct ProgressExample {
Text('Capsule Progress').fontSize(9).fontColor(0xCCCCCC).width('90%') Text('Capsule Progress').fontSize(9).fontColor(0xCCCCCC).width('90%')
Row({ space: 40 }) { Row({ space: 40 }) {
Progress({ value: 10, type: ProgressType.Capsule }).width(100) Progress({ value: 10, type: ProgressType.Capsule }).width(100).height(50)
Progress({ value: 20, total: 150, type: ProgressType.Capsule }).color(Color.Grey).value(50).width(100) Progress({ value: 20, total: 150, type: ProgressType.Capsule }).color(Color.Grey).value(50).width(100).height(50)
} }
}.width('100%').margin({ top: 30 }) }.width('100%').margin({ top: 30 })
} }
......
# TextArea # TextArea
> **NOTE**<br> > **NOTE**
>
> This component is supported since API version 7. Updates will be marked with a superscript to indicate their earliest API version. > This component is supported since API version 7. Updates will be marked with a superscript to indicate their earliest API version.
...@@ -20,7 +21,7 @@ Not supported ...@@ -20,7 +21,7 @@ Not supported
## APIs ## APIs
TextArea(value?:{placeholder?: string controller?: TextAreaController}) TextArea(value?:{placeholder?: string, controller?: TextAreaController})
- Parameters - Parameters
| Name | Type | Mandatory | Default Value | Description | | Name | Type | Mandatory | Default Value | Description |
...@@ -93,10 +94,11 @@ Sets the position of the caret. ...@@ -93,10 +94,11 @@ Sets the position of the caret.
@Entry @Entry
@Component @Component
struct TextAreaExample1 { struct TextAreaExample1 {
controller: TextAreaController = new TextAreaController()
@State text: string = '' @State text: string = ''
build() { build() {
Column() { Column() {
TextArea({ placeholder: 'input your word'}) TextArea({ placeholder: 'input your word', controller: this.controller})
.placeholderColor("rgb(0,0,225)") .placeholderColor("rgb(0,0,225)")
.placeholderFont({ size: 30, weight: 100, family: 'cursive', style: FontStyle.Italic }) .placeholderFont({ size: 30, weight: 100, family: 'cursive', style: FontStyle.Italic })
.textAlign(TextAlign.Center) .textAlign(TextAlign.Center)
...@@ -112,6 +114,7 @@ struct TextAreaExample1 { ...@@ -112,6 +114,7 @@ struct TextAreaExample1 {
}) })
.onChange((value: string) => { .onChange((value: string) => {
this.text = value this.text = value
this.controller.caretPosition(-1)
}) })
Text(this.text).width('90%') Text(this.text).width('90%')
} }
......
# TextInput # TextInput
> **NOTE**<br/> > **NOTE**
>
> This component is supported since API version 7. Updates will be marked with a superscript to indicate their earliest API version. > This component is supported since API version 7. Updates will be marked with a superscript to indicate their earliest API version.
...@@ -39,9 +40,8 @@ In addition to universal attributes, the following attributes are supported. ...@@ -39,9 +40,8 @@ In addition to universal attributes, the following attributes are supported.
| placeholderFont | {<br/>size?: Length,<br/>weight?: number\|[FontWeight](ts-universal-attributes-text-style.md),<br/>family?: string,<br/>style?: [FontStyle](ts-universal-attributes-text-style.md)<br/>} | - | Placeholder text style.<br/>- **size**: font size. If the value is of the number type, the unit fp is used.<br/>- **weight**: font weight. For the number type, the value ranges from 100 to 900, at an interval of 100. The default value is **400**. A larger value indicates a larger font weight.<br/>- **family**: font family. Use commas (,) to separate multiple fonts, for example, **'Arial, sans-serif'**. The priority of the fonts is the sequence in which they are placed.<br/>- **style**: font style. | | placeholderFont | {<br/>size?: Length,<br/>weight?: number\|[FontWeight](ts-universal-attributes-text-style.md),<br/>family?: string,<br/>style?: [FontStyle](ts-universal-attributes-text-style.md)<br/>} | - | Placeholder text style.<br/>- **size**: font size. If the value is of the number type, the unit fp is used.<br/>- **weight**: font weight. For the number type, the value ranges from 100 to 900, at an interval of 100. The default value is **400**. A larger value indicates a larger font weight.<br/>- **family**: font family. Use commas (,) to separate multiple fonts, for example, **'Arial, sans-serif'**. The priority of the fonts is the sequence in which they are placed.<br/>- **style**: font style. |
| enterKeyType | EnterKeyType | EnterKeyType.Done | How the Enter key is labeled. | | enterKeyType | EnterKeyType | EnterKeyType.Done | How the Enter key is labeled. |
| caretColor | Color | - | Color of the caret (also known as the text insertion cursor). | | caretColor | Color | - | Color of the caret (also known as the text insertion cursor). |
| maxLength<sup>8+</sup> | number | - | Maximum number of characters in the text input. | | maxLength | number | - | Maximum number of characters in the text input. |
| inputFilter<sup>8+</sup> | {<br/>value: [ResourceStr](../../ui/ts-types.md)<sup>8+</sup>,<br/>error?: (value: string)<br/>} | - | Regular expression for input filtering. Only inputs that comply with the regular expression can be displayed. Other inputs are ignored. The specified regular expression can match single characters, but not strings. Example: ^(? =.\*\d)(? =.\*[a-z])(? =.\*[A-Z]).{8,10}$. Strong passwords containing 8 to 10 characters cannot be filtered.<br/>- **value**: regular expression to set.<br/>- **error**: error message containing the ignored content returned when regular expression matching fails. | | inputFilter<sup>8+</sup> | {<br/>value: [ResourceStr](../../ui/ts-types.md)<sup>8+</sup>,<br/>error?: (value: string)<br/>} | - | Regular expression for input filtering. Only inputs that comply with the regular expression can be displayed. Other inputs are ignored. The specified regular expression can match single characters, but not strings. Example: ^(? =.\*\d)(? =.\*[a-z])(? =.\*[A-Z]).{8,10}$. Strong passwords containing 8 to 10 characters cannot be filtered.<br/>- **value**: regular expression to set.<br/>- **error**: error message containing the ignored content returned when regular expression matching fails. |
| copyOption<sup>9+</sup> | boolean\|[CopyOption](ts-basic-components-text.md) | true | Whether copy and paste is allowed. |
- EnterKeyType enums - EnterKeyType enums
| Name | Description | | Name | Description |
...@@ -75,10 +75,10 @@ In addition to universal attributes, the following attributes are supported. ...@@ -75,10 +75,10 @@ In addition to universal attributes, the following attributes are supported.
### TextInputController<sup>8+</sup> ### TextInputController<sup>8+</sup>
Implements the controller of the **&lt;TextInput&gt;** component. Implements the controller of the **\<TextInput>** component.
### Objects to Import #### Objects to Import
``` ```
...@@ -86,7 +86,7 @@ controller: TextInputController = new TextInputController() ...@@ -86,7 +86,7 @@ controller: TextInputController = new TextInputController()
``` ```
### caretPosition #### caretPosition
caretPosition(value: number): void caretPosition(value: number): void
...@@ -113,10 +113,9 @@ struct TextInputExample1 { ...@@ -113,10 +113,9 @@ struct TextInputExample1 {
build() { build() {
Column() { Column() {
TextArea({ placeholder: 'input your word' }) TextInput({ placeholder: 'input your word' })
.placeholderColor("rgb(0,0,225)") .placeholderColor("rgb(0,0,225)")
.placeholderFont({ size: 30, weight: 100, family: 'cursive', style: FontStyle.Italic }) .placeholderFont({ size: 30, weight: 100, family: 'cursive', style: FontStyle.Italic })
.textAlign(TextAlign.Center)
.caretColor(Color.Blue) .caretColor(Color.Blue)
.height(50) .height(50)
.fontSize(30) .fontSize(30)
......
...@@ -74,97 +74,85 @@ The universal events are not supported. ...@@ -74,97 +74,85 @@ The universal events are not supported.
| onShowFileSelector(callback: (event?: { result: [FileSelectorResult](#fileselectorresult), fileSelector: [FileSelectorParam](#fileselectorparam) }) => void) | <p>Triggered to process an HTML form whose input type is **file**, in response to the tapping of the **Select File** button.<br>**result**: file selection result to be sent to the web component.<br>**fileSelector**: information about the file selector.</p> | | onShowFileSelector(callback: (event?: { result: [FileSelectorResult](#fileselectorresult), fileSelector: [FileSelectorParam](#fileselectorparam) }) => void) | <p>Triggered to process an HTML form whose input type is **file**, in response to the tapping of the **Select File** button.<br>**result**: file selection result to be sent to the web component.<br>**fileSelector**: information about the file selector.</p> |
| onUrlLoadIntercept(callback: (event?: { data:string \| [WebResourceRequest](#webresourcerequest) }) => boolean) | <p>Triggered before the **\<Web>** component loads the URL to determine whether to block the access. The callback returns **true** if the access is blocked, and **false** otherwise.<br>**data**: URL information.</p> | | onUrlLoadIntercept(callback: (event?: { data:string \| [WebResourceRequest](#webresourcerequest) }) => boolean) | <p>Triggered before the **\<Web>** component loads the URL to determine whether to block the access. The callback returns **true** if the access is blocked, and **false** otherwise.<br>**data**: URL information.</p> |
### ConsoleMessage ## ConsoleMessage
- APIs | Name | Description |
| ------------------------------- | ---------------------- |
| Name | Description | | getLineNumber(): number | Obtains the number of rows in the **ConsoleMessage**. |
| ------------------------------- | ---------------------- | | getMessage(): string | Obtains the log information of the **ConsoleMessage**.|
| getLineNumber(): number | Obtains the number of rows in the **ConsoleMessage**. | | getMessageLevel(): [MessageLevel](#messagelevel-enums) | Obtains the log information level of the **ConsoleMessage**.|
| getMessage(): string | Obtains the log information of the **ConsoleMessage**.| | getSourceId(): string | Obtains the path and name of the web page source file. |
| getMessageLevel(): MessageLevel | Obtains the log information level of the **ConsoleMessage**.|
| getSourceId(): string | Obtains the path and name of the web page source file. |
- MessageLevel enums ## MessageLevel Enums
| Name | Description | | Name | Description |
| ----- | :---- | | ----- | :---- |
| Debug | Debug level.| | Debug | Debug level.|
| Error | Error level.| | Error | Error level.|
| Info | Information level.| | Info | Information level.|
| Log | Log level.| | Log | Log level.|
| Warn | Warning level. | | Warn | Warning level. |
### JsResult ## JsResult
Provides the result returned to the **\<Web>** component to indicate the user operation performed in the dialog box. Provides the result returned to the **\<Web>** component to indicate the user operation performed in the dialog box.
- APIs | Name | Description |
| --------------------- | ----------------------- |
| Name | Description | | handleCancel(): void | <p>The user's cancel operation in the dialog box.</p> |
| --------------------- | ----------------------- | | handleConfirm(): void | <p>The user's confirm operation in the dialog box.</p> |
| handleCancel(): void | <p>The user's cancel operation in the dialog box.</p> |
| handleConfirm(): void | <p>The user's confirm operation in the dialog box.</p> |
### WebResourceError
- APIs
| Name | Description | ## WebResourceError
| ---------------------- | ------------ |
| getErrorCode(): number | Obtains the error code for resource loading. |
| getErrorInfo(): string | Obtains error information about resource loading.|
### WebResourceRequest | Name | Description |
| ---------------------- | ------------ |
| getErrorCode(): number | Obtains the error code for resource loading. |
| getErrorInfo(): string | Obtains error information about resource loading.|
- APIs ## WebResourceRequest
| Name | Description | | Name | Description |
| ---------------------------------------- | -------------------- | | ---------------------------------------- | -------------------- |
| getRequestHeader(): Array\<[Header](#header)\> | Obtains the information about the resource request header. | | getRequestHeader(): Array\<[Header](#header)\> | Obtains the information about the resource request header. |
| getRequestUrl(): string | Obtains the URL of the resource request. | | getRequestUrl(): string | Obtains the URL of the resource request. |
| isMainFrame(): boolean | Checks whether the resource request is in the main frame. | | isMainFrame(): boolean | Checks whether the resource request is in the main frame. |
| isRedirect(): boolean | Checks whether the resource request is redirected by the server. | | isRedirect(): boolean | Checks whether the resource request is redirected by the server. |
| isRequestGesture(): boolean | Checks whether the resource request is associated with a gesture (for example, a tap).| | isRequestGesture(): boolean | Checks whether the resource request is associated with a gesture (for example, a tap).|
### Header ## Header
Describes the request/response header returned by the **\<Web>** component. Describes the request/response header returned by the **\<Web>** component.
- Parameters | Name | Type | Description |
| ----------- | ------ | ------------- |
| Name | Type | Description | | headerKey | string | Key of the request/response header. |
| ----------- | ------ | ------------- | | headerValue | string | Value of the request/response header.|
| headerKey | string | Key of the request/response header. |
| headerValue | string | Value of the request/response header.|
### WebResourceResponse ## WebResourceResponse
- APIs | Name | Description |
| ---------------------------------------- | ------------------ |
| Name | Description | | getReasonMessage(): string | Obtains the status code description of the resource response. |
| ---------------------------------------- | ------------------ | | getResponseCode(): number | Obtains the status code of the resource response. |
| getReasonMessage(): string | Obtains the status code description of the resource response. | | getResponseData(): string | Obtains the data in the resource response. |
| getResponseCode(): number | Obtains the status code of the resource response. | | getResponseEncoding(): string | Obtains the encoding of the resource response. |
| getResponseData(): string | Obtains the data in the resource response. | | getResponseHeader(): Array\<[Header](#header)\> | Obtains the resource response header. |
| getResponseEncoding(): string | Obtains the encoding of the resource response. | | getResponseMimeType(): string | Obtains the media (MIME) type of the resource response.|
| getResponseHeader(): Array\<[Header](#header)\> | Obtains the resource response header. |
| getResponseMimeType(): string | Obtains the media (MIME) type of the resource response.|
### RenderExitReason ## RenderExitReason
Explains why the rendering process exits. Explains why the rendering process exits.
| Name | Description | | Name | Description |
| -------------------------- | ----------------- | | -------------------------- | ----------------- |
| ProcessAbnormalTermination | The rendering process exits abnormally. | | PROCESS_ABNORMAL_TERMINATION | The rendering process exits abnormally. |
| ProcessWasKilled | The rendering process receives a SIGKILL message or is manually terminated.| | PROCESS_WAS_KILLED | The rendering process receives a SIGKILL message or is manually terminated.|
| ProcessCrashed | The rendering process crashes due to a segmentation error or other errors. | | PROCESS_CRASHED | The rendering process crashes due to a segmentation error or other errors. |
| ProcessOom | The program memory is running low. | | PROCESS_OOM | The program memory is running low. |
| ProcessExitUnknown | Other reason. | | PROCESS_EXIT_UNKNOWN | Other reason. |
### MixedMode ## MixedMode
| Name | Description | | Name | Description |
| ---------- | ---------------------------------- | | ---------- | ---------------------------------- |
...@@ -172,7 +160,7 @@ Explains why the rendering process exits. ...@@ -172,7 +160,7 @@ Explains why the rendering process exits.
| Compatible | HTTP and HTTPS hybrid content can be loaded in compatibility mode. This means that some insecure content may be loaded. | | Compatible | HTTP and HTTPS hybrid content can be loaded in compatibility mode. This means that some insecure content may be loaded. |
| None | HTTP and HTTPS hybrid content cannot be loaded. | | None | HTTP and HTTPS hybrid content cannot be loaded. |
### CacheMode ## CacheMode
| Name | Description | | Name | Description |
| ------- | ------------------------------------ | | ------- | ------------------------------------ |
| Default | The cache that has not expired is used to load the resources. If the resources do not exist in the cache, they will be obtained from the Internet.| | Default | The cache that has not expired is used to load the resources. If the resources do not exist in the cache, they will be obtained from the Internet.|
...@@ -180,32 +168,28 @@ Explains why the rendering process exits. ...@@ -180,32 +168,28 @@ Explains why the rendering process exits.
| Online | The cache is not used to load the resources. All resources are obtained from the Internet. | | Online | The cache is not used to load the resources. All resources are obtained from the Internet. |
| Only | The cache alone is used to load the resources. | | Only | The cache alone is used to load the resources. |
### FileSelectorResult ## FileSelectorResult
Notifies the **\<Web>** component of the file selection result. Notifies the **\<Web>** component of the file selection result.
- APIs | Name | Description |
| ---------------------------------------------- | ------------------------------------------------------------ |
| Name | Description | | handleFileList(fileList: Array\<string>): void | Instructs the **\<Web>** component to select a file.<br>**fileList**: list of files to operate. |
| ---------------------------------------------- | ------------------------------------------------------------ |
| handleFileList(fileList: Array\<string>): void | Instructs the **\<Web>** component to select a file.<br>**fileList**: list of files to operate. |
### FileSelectorParam
- APIs
| Name | Description | ## FileSelectorParam
| -------------------------------- | ------------ | | Name | Description |
| getTitle(): string | Obtains the title of the file selector. | | -------------------------------- | ------------ |
| getMode(): FileSelectorMode | Obtains the mode of the file selector. | | title(): string | Title of the file selector. |
| getAcceptType(): Array\<string\> | Obtains the file filtering type. | | mode(): FileSelectorMode | Mode of the file selector. |
| isCapture(): boolean | Checks whether multimedia capabilities are invoked.| | acceptType(): Array\<string\> | File filtering type. |
| isCapture(): boolean | Whether multimedia capabilities are invoked.|
### FileSelectorMode ## FileSelectorMode
| Name | Description | | Name | Description |
| -------------------- | ---------- | | -------------------- | ---------- |
| FileOpenMode | Open and upload a file. | | FILE_OPEN_MODE | Open and upload a file. |
| FileOpenMultipleMode | Open and upload multiple files. | | FILE_OPEN_MULTIPLE_MODE | Open and upload multiple files. |
| FileOpenFolderMode | Open and upload a folder.| | FILE_OPEN_FOLDER_MODE | Open and upload a folder.|
| FileSaveMode | Save a file. | | FILE_SAVE_MODE | Save a file. |
## WebController ## WebController
......
# Navigator # Navigator
> ![icon-note.gif](public_sys-resources/icon-note.gif) **NOTE** > **NOTE**
>
> This component is supported since API version 7. Updates will be marked with a superscript to indicate their earliest API version. > This component is supported since API version 7. Updates will be marked with a superscript to indicate their earliest API version.
The **&lt;Navigator&gt;** component provides redirection. The **\<Navigator>** component provides redirection to the target page.
## Required Permissions ## Required Permissions
...@@ -40,27 +41,28 @@ Creates a navigator. ...@@ -40,27 +41,28 @@ Creates a navigator.
## Attributes ## Attributes
| Name | Parameters | Default Value | Description | | Name | Parameters | Default Value | Description |
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| active | boolean | - | Whether the **&lt;Navigator&gt;** component is activated. If the component is activated, the corresponding navigation takes effect. | | active | boolean | - | Whether the **\<Navigator>** component is activated. If the component is activated, the corresponding navigation takes effect. |
| params | Object | undefined | Data that needs to be passed to the target page during redirection. You can use **router.getParams()** to obtain the data on the target page. | | params | Object | undefined | Data that needs to be passed to the target page during redirection. You can use **router.getParams()** to obtain the data on the target page. |
## Example ## Example
``` ```ts
// Navigator Page // Navigator.ets
@Entry @Entry
@Component @Component
struct NavigatorExample { struct NavigatorExample {
@State active: boolean = false @State active: boolean = false
@State Text: string = 'news' @State Text: object = {name: 'news'}
build() { build() {
Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Start, justifyContent: FlexAlign.SpaceBetween }) { Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Start, justifyContent: FlexAlign.SpaceBetween }) {
Navigator({ target: 'pages/container/navigator/Detail', type: NavigationType.Push }) { Navigator({ target: 'pages/container/navigator/Detail', type: NavigationType.Push }) {
Text('Go to ' + this.Text + ' page').width('100%').textAlign(TextAlign.Center) Text('Go to ' + this.Text['name'] + ' page')
.width('100%').textAlign(TextAlign.Center)
}.params({ text: this.Text }) }.params({ text: this.Text })
Navigator() { Navigator() {
...@@ -75,14 +77,14 @@ struct NavigatorExample { ...@@ -75,14 +77,14 @@ struct NavigatorExample {
``` ```
``` ```ts
// Detail Page // Detail.ets
import router from '@system.router' import router from '@system.router'
@Entry @Entry
@Component @Component
struct DetailExample { struct DetailExample {
@State text: string = router.getParams().text @State text: any = router.getParams().text
build() { build() {
Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Start, justifyContent: FlexAlign.SpaceBetween }) { Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Start, justifyContent: FlexAlign.SpaceBetween }) {
...@@ -90,7 +92,8 @@ struct DetailExample { ...@@ -90,7 +92,8 @@ struct DetailExample {
Text('Go to back page').width('100%').height(20) Text('Go to back page').width('100%').height(20)
} }
Text('This is ' + this.text + ' page').width('100%').textAlign(TextAlign.Center) Text('This is ' + this.text['name'] + ' page')
.width('100%').textAlign(TextAlign.Center)
} }
.width('100%').height(200).padding({ left: 35, right: 35, top: 35 }) .width('100%').height(200).padding({ left: 35, right: 35, top: 35 })
} }
...@@ -98,9 +101,8 @@ struct DetailExample { ...@@ -98,9 +101,8 @@ struct DetailExample {
``` ```
```ts
``` // Back.ets
// Back Page
@Entry @Entry
@Component @Component
struct BackExample { struct BackExample {
......
...@@ -18,19 +18,19 @@ Use the following attributes to bind gesture recognition to a component. When a ...@@ -18,19 +18,19 @@ Use the following attributes to bind gesture recognition to a component. When a
| Name | Type | Default Value | Description | | Name | Type | Default Value | Description |
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| gesture | gesture: GestureType,<br/>mask?: GestureMask | gesture: -,<br/>mask: GestureMask.Normal | Gesture to recognize.<br/>**gesture** specifies the type of the gesture to bind, and **mask** specifies the event response setting. | | gesture | gesture: GestureType,<br/>mask?: GestureMask | gesture: -,<br/>mask: GestureMask.Normal | Gesture to recognize.<br/>- **gesture**: type of the gesture to bind.<br/>- **mask**: event response setting. |
| priorityGesture | gesture: GestureType,<br/>mask?: GestureMask | gesture: -,<br/>mask: GestureMask.Normal | Gesture to preferentially recognize.<br/>**gesture** specifies the type of the gesture to bind, and **mask** specifies the event response setting.<br/>> ![icon-note.gif](public_sys-resources/icon-note.gif) **NOTE**<br/>> - By default, the child component takes precedence over the parent component in gesture recognition. When **priorityGesture** is configured for the parent component, the parent component takes precedence over the child component in gesture recognition. | | priorityGesture | gesture: GestureType,<br/>mask?: GestureMask | gesture: -,<br/>mask: GestureMask.Normal | Gesture to preferentially recognize.<br/>- **gesture**: type of the gesture to bind.<br/>- **mask**: event response setting.<br/>By default, the child component takes precedence over the parent component in gesture recognition. When **priorityGesture** is configured for the parent component, the parent component takes precedence over the child component in gesture recognition. |
| parallelGesture | gesture: GestureType,<br/>mask?: GestureMask | gesture: -,<br/>mask: GestureMask.Normal | Gesture that can be triggered together with the child component gesture.<br/>**gesture** specifies the type of the gesture to bind, and **mask** specifies the event response setting.<br/>> ![icon-note.gif](public_sys-resources/icon-note.gif) **NOTE**<br/>> - The gesture event is not a bubbling event. When **parallelGesture** is set for the parent component, gesture events that are the same for the parent component and child components can be triggered, thereby implementing a bubbling effect. | | parallelGesture | gesture: GestureType,<br/>mask?: GestureMask | gesture: -,<br/>mask: GestureMask.Normal | Gesture that can be triggered together with the child component gesture.<br/>- **gesture**: type of the gesture to bind.<br/>- **mask**: event response setting.<br/>The gesture event is not a bubbling event. When **parallelGesture** is set for the parent component, gesture events bound to both the parent and child components can be triggered, thereby implementing a bubbling effect. |
- GestureMask enums - GestureMask enums
| Name | Description | | Name | Description |
| -------- | -------- | | -------- | -------- |
| Normal | The gestures of child components are not masked and are recognized based on the default gesture recognition sequence. | | Normal | The gestures of child components are not masked and are recognized based on the default gesture recognition sequence. |
| IgnoreInternal | The gestures of child components are masked. Only the gestures of the current component are recognized.<br/>> ![icon-note.gif](public_sys-resources/icon-note.gif) **NOTE**<br/>> However, the built-in gestures of the child components are not masked. For example, when the child component is a **&lt;List&gt;** component, the built-in sliding gestures can still be triggered. | | IgnoreInternal | The gestures of child components are masked. Only the gestures of the current component are recognized.<br/>However, the built-in gestures of the child components are not masked. For example, when the child component is a **&lt;List&gt;** component, the built-in sliding gestures can still be triggered. |
- Gesture types - GestureType enums
| Name | Description | | Name | Description |
| -------- | -------- | | -------- | -------- |
| TapGesture | Tap gesture, which can be a single-tap or multi-tap gesture. | | TapGesture | Tap gesture, which can be a single-tap or multi-tap gesture. |
...@@ -38,12 +38,13 @@ Use the following attributes to bind gesture recognition to a component. When a ...@@ -38,12 +38,13 @@ Use the following attributes to bind gesture recognition to a component. When a
| PanGesture | Pan gesture. | | PanGesture | Pan gesture. |
| PinchGesture | Pinch gesture. | | PinchGesture | Pinch gesture. |
| RotationGesture | Rotation gesture. | | RotationGesture | Rotation gesture. |
| SwipeGesture | Swipe gesture, which can be idenfied when the swipe speed is 100 vp/s or higher. |
| GestureGroup | A group of gestures. Continuous recognition, parallel recognition, and exclusive recognition are supported. | | GestureGroup | A group of gestures. Continuous recognition, parallel recognition, and exclusive recognition are supported. |
## Gesture Response Event ## Gesture Response Event
The component uses the **gesture** method to bind the gesture object and uses the events provided in this object to respond to the gesture operation. For example, the **onAction** event of the **TapGesture** object can be used to respond to a click event. For details about the event definition, see the section of each gesture object. A component uses the **gesture** method to bind the gesture object and uses the events provided in this object to respond to the gesture operation. For example, the **onAction** event of the **TapGesture** object can be used to respond to a click event. For details about the event definition, see the section of each gesture object.
- TapGesture events - TapGesture events
| Name | Description | | Name | Description |
...@@ -54,13 +55,14 @@ The component uses the **gesture** method to bind the gesture object and uses th ...@@ -54,13 +55,14 @@ The component uses the **gesture** method to bind the gesture object and uses th
| Name | Type | Description | | Name | Type | Description |
| -------- | -------- | -------- | | -------- | -------- | -------- |
| timestamp | number | Timestamp of the event. | | timestamp | number | Timestamp of the event. |
| target<sup>8+</sup> | EventTarget | Object that triggers the gesture event. | | target<sup>8+</sup> | [EventTarget](ts-universal-events-click.md) | Object that triggers the gesture event. |
## Example ## Example
```ts ```ts
// xxx.ets
@Entry @Entry
@Component @Component
struct GestureSettingsExample { struct GestureSettingsExample {
......
# Motion Path Animation # Motion Path Animation
> ![icon-note.gif](public_sys-resources/icon-note.gif) **NOTE** > **NOTE**
>
> This animation is supported since API version 7. Updates will be marked with a superscript to indicate their earliest API version. > This animation is supported since API version 7. Updates will be marked with a superscript to indicate their earliest API version.
The attributes described in this topic are used to set the motion path of the component in a translation animation. The attributes below can be used to set the motion path of the component in a translation animation.
## Attributes ## Attributes
| Name | Type | Default Value | Description | | Name | Type | Default Value | Description |
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| motionPath | {<br/>path: string,<br/>from?: number,<br/>to?: number,<br/>rotatable?: boolean<br/>}<br/>> ![icon-note.gif](public_sys-resources/icon-note.gif) **NOTE**<br/>> In a path, **start** and **end** can be used to replace the start point and end point. Example:<br/>> <br/>> 'Mstart.x start.y L50 50 Lend.x end.y Z' | {<br/>"",<br/>0.0,<br/>1.0,<br/>false<br/>} | Motion path of the component. The input parameters are described as follows:<br/>- **path**: motion path of the translation animation. The **svg** path string is used.<br/>- **from**: start point of the motion path. The default value is **0.0**.<br/>- **to**: end point of the motion path. The default value is **1.0**.<br/>- **rotatable**: whether to rotate along the path. | | motionPath | {<br/>path: string,<br/>from?: number,<br/>to?: number,<br/>rotatable?: boolean<br/>}<br/>**NOTE**<br/>In a path, **start** and **end** can be used to replace the start point and end point. Example:<br/>'Mstart.x start.y L50 50 Lend.x end.y Z' | {<br/>"",<br/>0.0,<br/>1.0,<br/>false<br/>} | Motion path of the component. The input parameters are described as follows:<br/>- **path**: motion path of the translation animation. The **svg** path string is used.<br/>- **from**: start point of the motion path. The default value is **0.0**.<br/>- **to**: end point of the motion path. The default value is **1.0**.<br/>- **rotatable**: whether to rotate along the path. |
## Example ## Example
......
# Component ID # Component ID
**id** identifies a component uniquely within an application. This module provides APIs for obtaining the attributes of or sending events to the component with the specified ID.
> ![icon-note.gif](public_sys-resources/icon-note.gif) **NOTE** > **NOTE**
> This component is supported since API version 8. Updates will be marked with a superscript to indicate their earliest API version. >
> - The APIs of this module are supported since API version 8. Updates will be marked with a superscript to indicate their earliest API version.
> - The APIs provided by this module are system APIs.
## Required Permissions ## Required Permissions
...@@ -12,9 +15,9 @@ None ...@@ -12,9 +15,9 @@ None
## Attributes ## Attributes
| Name | Type | Default Value | Description | | Name | Type | Default Value | Description |
| -------- | -------- | -------- | -------- | | ---- | ------ | ---- | ------------------ |
| id | string | '' | Unique ID of the component. The uniqueness is ensured by the user. | | id | string | '' | Unique ID you assigned to the component.|
## APIs ## APIs
...@@ -28,14 +31,25 @@ Obtains all attributes of the component with the specified ID, excluding the inf ...@@ -28,14 +31,25 @@ Obtains all attributes of the component with the specified ID, excluding the inf
- Parameters - Parameters
| Name | Type | Mandatory | Default Value | Description | | Name | Type | Mandatory | Default Value | Description |
| -------- | -------- | -------- | -------- | -------- | | ---- | ------ | ---- | ---- | ----------- |
| id | string | Yes | - | ID of the component whose attributes are to be obtained. | | id | string | Yes | - | ID of the component whose attributes are to be obtained.|
- Return value - Return value
| Type | Description | | Type | Description |
| -------- | -------- | | ------ | --------------- |
| string | JSON string of the component attribute list. | | string | JSON string of the component attribute list.|
### getInspectorTree
getInspectorTree(): string
Obtains the component tree and component attributes.
- Return value
| Type | Description |
| ------ | ------------------- |
| string | JSON string of the component tree and component attribute list.|
### sendEventByKey ### sendEventByKey
...@@ -45,60 +59,206 @@ Sends an event to the component with the specified ID. ...@@ -45,60 +59,206 @@ Sends an event to the component with the specified ID.
- Parameters - Parameters
| Name | Type | Mandatory | Default Value | Description | | Name | Type | Mandatory | Default Value | Description |
| -------- | -------- | -------- | -------- | -------- | | ------ | ------ | ---- | ---- | ---------------------------------------- |
| id | string | Yes | - | ID of the component for which the event is to be sent. | | id | string | Yes | - | ID of the component to which the event is to be sent. |
| action | number | Yes | - | Type of the event to be sent. The options are as follows:<br/>- Click event: 10.<br/>- LongClick: 11. | | action | number | Yes | - | Type of the event to be sent. The options are as follows:<br>- **10**: click event.<br>- **11**: long click event.|
| params | string | Yes | - | Event parameters. If there is no parameter, pass an empty string **""**. | | params | string | Yes | - | Event parameters. If there is no parameter, pass an empty string **""**. |
- Return value - Return value
| Type | Description | | Type | Description |
| -------- | -------- | | ------- | ------------------------------ |
| boolean | Returns **false** if the component with the specified ID cannot be found; returns **true** otherwise. | | boolean | Returns **true** if the component with the specified ID is found; returns **false** otherwise.|
### sendTouchEvent
sendTouchEvent(event: TouchObject): boolean
Sends a touch event.
- Parameters
| Name | Type | Mandatory | Default Value | Description |
| ----- | ----------- | ---- | ---- | ---------------------------------------- |
| event | TouchObject | Yes | - | Location where a touch event is triggered. For details, see [TouchEvent](ts-universal-events-touch.md#touchevent).|
- Return value
| Type | Description |
| ------- | -------------------------- |
| boolean | Returns **true** if the event is sent successfully; returns **false** otherwise.|
### sendKeyEvent
sendKeyEvent(event: KeyEvent): boolean
Sends a key event.
- Parameters
| Name | Type | Mandatory | Default Value | Description |
| ----- | -------- | ---- | ---- | ---------------------------------------- |
| event | KeyEvent | Yes | - | Key event. For details, see [KeyEvent](ts-universal-events-key.md#keyevent).|
- Return value
| Type | Description |
| ------- | --------------------------- |
| boolean | Returns **true** if the event is sent successfully; returns **false** otherwise.|
### sendMouseEvent
sendMouseEvent(event: MouseEvent): boolean
Sends a mouse event.
- Parameters
| Name | Type | Mandatory | Default Value | Description |
| ----- | ---------- | ---- | ---- | ---------------------------------------- |
| event | MouseEvent | Yes | - | Mouse event. For details, see [MouseEvent](ts-universal-mouse-key.md#mouseevent).|
- Return value
| Type | Description |
| ------- | --------------------------- |
| boolean | Returns **true** if the event is sent successfully; returns **false** otherwise.|
## Example ## Example
```ts
// xxx.ets
class Utils {
static rect_left;
static rect_top;
static rect_right;
static rect_bottom;
static rect_value;
static getComponentRect(key) {
let strJson = getInspectorByKey(key);
let obj = JSON.parse(strJson);
console.info("[getInspectorByKey] current component obj is: " + JSON.stringify(obj));
let rectInfo = JSON.parse('[' + obj.$rect + ']')
console.info("[getInspectorByKey] rectInfo is: " + rectInfo);
this.rect_left = JSON.parse('[' + rectInfo[0] + ']')[0]
this.rect_top = JSON.parse('[' + rectInfo[0] + ']')[1]
this.rect_right = JSON.parse('[' + rectInfo[1] + ']')[0]
this.rect_bottom = JSON.parse('[' + rectInfo[1] + ']')[1]
return this.rect_value = {
"left": this.rect_left, "top": this.rect_top, "right": this.rect_right, "bottom": this.rect_bottom
}
}
}
```
@Entry @Entry
@Component @Component
struct IdExample { struct IdExample {
@State text: string = ''
build() { build() {
Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) { Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) {
Button() { Button() {
Text('click') Text('onKeyTab').fontSize(25).fontWeight(FontWeight.Bold)
.fontSize(25) }.margin({ top: 20 }).backgroundColor('#0D9FFB')
.fontWeight(FontWeight.Bold) .onKeyEvent(() => {
} this.text = "onKeyTab"
.type(ButtonType.Capsule) })
.margin({
top: 20 Button() {
}).onClick(() => { Text('click to start').fontSize(25).fontWeight(FontWeight.Bold)
}.margin({ top: 20 })
.onClick(() => {
console.info(getInspectorByKey("click")) console.info(getInspectorByKey("click"))
console.info(getInspectorTree()) console.info(getInspectorTree())
this.text = "Button 'click to start' is clicked"
setTimeout(() => { setTimeout(() => {
sendEventByKey("longclick", 11, "") sendEventByKey("longclick", 11, "")
}, 2000) }, 2000)
}).id('click') }).id('click')
Button() { Button() {
Text('longclick') Text('longclick').fontSize(25).fontWeight(FontWeight.Bold)
.fontSize(25) }.margin({ top: 20 }).backgroundColor('#0D9FFB')
.fontWeight(FontWeight.Bold)
}
.type(ButtonType.Capsule)
.margin({
top: 20
})
.backgroundColor('#0D9FFB')
.gesture( .gesture(
LongPressGesture().onActionEnd(() => { LongPressGesture().onActionEnd(() => {
console.info('long clicked') console.info('long clicked')
})) this.text = "Button 'longclick' is longclicked"
.id('longclick') setTimeout(() => {
let rect = Utils.getComponentRect('onTouch')
let touchPoint: TouchObject = {
id: 1,
x: rect.left + (rect.right - rect.left) / 2,
y: rect.top + (rect.bottom - rect.top) / 2,
type: TouchType.Down,
screenX: rect.left + (rect.right - rect.left) / 2,
screenY: rect.left + (rect.right - rect.left) / 2,
}
sendTouchEvent(touchPoint)
touchPoint.type = TouchType.Up
sendTouchEvent(touchPoint)
}, 2000)
})).id('longclick')
Button() {
Text('onTouch').fontSize(25).fontWeight(FontWeight.Bold)
}.type(ButtonType.Capsule).margin({ top: 20 })
.onClick(() => {
console.info('onTouch is clicked')
this.text = "Button 'onTouch' is clicked"
setTimeout(() => {
let rect = Utils.getComponentRect('onMouse')
let mouseEvent: MouseEvent = {
button: MouseButton.Left,
action: MouseAction.Press,
x: rect.left + (rect.right - rect.left) / 2,
y: rect.top + (rect.bottom - rect.top) / 2,
screenX: rect.left + (rect.right - rect.left) / 2,
screenY: rect.top + (rect.bottom - rect.top) / 2,
timestamp: 1,
target: {
area: {
width: 1,
height: 1,
position: {
x: 1,
y: 1
},
globalPosition: {
x: 1,
y: 1
}
}
},
source: SourceType.Mouse
}
sendMouseEvent(mouseEvent)
}, 2000)
}).id('onTouch')
Button() {
Text('onMouse').fontSize(25).fontWeight(FontWeight.Bold)
}.margin({ top: 20 }).backgroundColor('#0D9FFB')
.onMouse(() => {
console.info('onMouse')
this.text = "Button 'onMouse' in onMouse"
setTimeout(() => {
let keyEvent: KeyEvent = {
type: KeyType.Down,
keyCode: 2049,
keyText: 'tab',
keySource: 4,
deviceId: 0,
metaKey: 0,
timestamp: 0
}
sendKeyEvent(keyEvent)
}, 2000)
}).id('onMouse')
Text(this.text).fontSize(25).padding(15)
} }
.width('100%') .width('100%').height('100%')
.height('100%')
} }
} }
``` ```
...@@ -6,7 +6,7 @@ Based on the Hi3861 platform, the OpenHarmony WLAN module provides abundant peri ...@@ -6,7 +6,7 @@ Based on the Hi3861 platform, the OpenHarmony WLAN module provides abundant peri
## Development<a name="section13857170163412"></a> ## Development<a name="section13857170163412"></a>
1. Complete the operations described in [Getting Started with Hi3861](../quick-start/quickstart-lite-introduction-hi3861.md#section19352114194115). 1. Complete the operations described in [Getting Started with Hi3861](../quick-start/quickstart-lite-overview.md).
LED control examples are stored in the file **applications/sample/wifi-iot/app/iothardware/led\_example.c**. LED control examples are stored in the file **applications/sample/wifi-iot/app/iothardware/led\_example.c**.
...@@ -73,7 +73,6 @@ Based on the Hi3861 platform, the OpenHarmony WLAN module provides abundant peri ...@@ -73,7 +73,6 @@ Based on the Hi3861 platform, the OpenHarmony WLAN module provides abundant peri
break; break;
} }
} }
return NULL;
} }
``` ```
...@@ -97,7 +96,7 @@ Based on the Hi3861 platform, the OpenHarmony WLAN module provides abundant peri ...@@ -97,7 +96,7 @@ Based on the Hi3861 platform, the OpenHarmony WLAN module provides abundant peri
## Verification<a name="section1949121910344"></a> ## Verification<a name="section1949121910344"></a>
For details about the compilation and burning processes, see [Building](../quick-start/quickstart-lite-steps-hi3861-building.md) and [Burning](../quick-start/quickstart-lite-steps-hi3861-burn.md) in the _Getting Started with Hi3861_. For details about the compilation and burning processes, see [Building](../quick-start/quickstart-lite-steps-hi3861-building.md) and [Burning](../quick-start/quickstart-lite-steps-hi3861-burn.md).
After the preceding two steps are complete, press the **RST** button to reset the module. If the LED blinks periodically as expected, the verification is passed. After the preceding two steps are complete, press the **RST** button to reset the module. If the LED blinks periodically as expected, the verification is passed.
......
...@@ -44,26 +44,26 @@ import stats from '@ohos.bundleState'; ...@@ -44,26 +44,26 @@ import stats from '@ohos.bundleState';
import stats from '@ohos.bundleState' import stats from '@ohos.bundleState'
// 异步方法promise方式 // 异步方法promise方式
stats.queryBundleActiveStates(0, 20000000000000).then( res => { stats.queryBundleActiveStates(0, 20000000000000).then(res => {
console.log('BUNDLE_ACTIVE queryBundleActiveStates promise success.'); console.log('BUNDLE_ACTIVE queryBundleActiveStates promise success.');
for (let i = 0; i < res.length; i++) { for (let i = 0; i < res.length; i++) {
console.log('BUNDLE_ACTIVE queryBundleActiveStates promise number : ' + (i + 1)); console.log('BUNDLE_ACTIVE queryBundleActiveStates promise number : ' + (i + 1));
console.log('BUNDLE_ACTIVE queryBundleActiveStates promise result ' + JSON.stringify(res[i])); console.log('BUNDLE_ACTIVE queryBundleActiveStates promise result ' + JSON.stringify(res[i]));
} }
}).catch( err => { }).catch(err => {
console.log('BUNDLE_ACTIVE queryBundleActiveStates promise failed, because: ' + err.code); console.log('BUNDLE_ACTIVE queryBundleActiveStates promise failed, because: ' + err.code);
}); });
// 异步方法callback方式 // 异步方法callback方式
stats.queryBundleActiveStates(0, 20000000000000, (err, res) => { stats.queryBundleActiveStates(0, 20000000000000, (err, res) => {
if(err.code == 0) { if (err) {
console.log('BUNDLE_ACTIVE queryBundleActiveStates callback failed, because: ' + err.code);
} else {
console.log('BUNDLE_ACTIVE queryBundleActiveStates callback success.'); console.log('BUNDLE_ACTIVE queryBundleActiveStates callback success.');
for (let i = 0; i < res.length; i++) { for (let i = 0; i < res.length; i++) {
console.log('BUNDLE_ACTIVE queryBundleActiveStates callback number : ' + (i + 1)); console.log('BUNDLE_ACTIVE queryBundleActiveStates callback number : ' + (i + 1));
console.log('BUNDLE_ACTIVE queryBundleActiveStates callback result ' + JSON.stringify(res[i])); console.log('BUNDLE_ACTIVE queryBundleActiveStates callback result ' + JSON.stringify(res[i]));
} }
} else {
console.log('BUNDLE_ACTIVE queryBundleActiveStates callback failed, because: ' + err.code);
} }
}); });
``` ```
...@@ -74,30 +74,30 @@ import stats from '@ohos.bundleState'; ...@@ -74,30 +74,30 @@ import stats from '@ohos.bundleState';
import stats from '@ohos.bundleState' import stats from '@ohos.bundleState'
// 异步方法promise方式 // 异步方法promise方式
stats.queryBundleStateInfos(0, 20000000000000).then( res => { stats.queryBundleStateInfos(0, 20000000000000).then(res => {
console.log('BUNDLE_ACTIVE queryBundleStateInfos promise success.'); console.log('BUNDLE_ACTIVE queryBundleStateInfos promise success.');
let i = 1; let i = 1;
for(let key in res){ for (let key in res) {
console.log('BUNDLE_ACTIVE queryBundleStateInfos promise number : ' + i); console.log('BUNDLE_ACTIVE queryBundleStateInfos promise number : ' + i);
console.log('BUNDLE_ACTIVE queryBundleStateInfos promise result ' + JSON.stringify(res[key])); console.log('BUNDLE_ACTIVE queryBundleStateInfos promise result ' + JSON.stringify(res[key]));
i++; i++;
} }
}).catch( err => { }).catch(err => {
console.log('BUNDLE_ACTIVE queryBundleStateInfos promise failed, because: ' + err.code); console.log('BUNDLE_ACTIVE queryBundleStateInfos promise failed, because: ' + err.code);
}); });
// 异步方法callback方式 // 异步方法callback方式
stats.queryBundleStateInfos(0, 20000000000000, (err, res) => { stats.queryBundleStateInfos(0, 20000000000000, (err, res) => {
if(err.code == 0) { if (err) {
console.log('BUNDLE_ACTIVE queryBundleStateInfos callback failed, because: ' + err.code);
} else {
console.log('BUNDLE_ACTIVE queryBundleStateInfos callback success.'); console.log('BUNDLE_ACTIVE queryBundleStateInfos callback success.');
let i = 1; let i = 1;
for(let key in res){ for (let key in res) {
console.log('BUNDLE_ACTIVE queryBundleStateInfos callback number : ' + i); console.log('BUNDLE_ACTIVE queryBundleStateInfos callback number : ' + i);
console.log('BUNDLE_ACTIVE queryBundleStateInfos callback result ' + JSON.stringify(res[key])); console.log('BUNDLE_ACTIVE queryBundleStateInfos callback result ' + JSON.stringify(res[key]));
i++; i++;
} }
} else {
console.log('BUNDLE_ACTIVE queryBundleStateInfos callback failed, because: ' + err.code);
} }
}); });
``` ```
...@@ -108,26 +108,26 @@ import stats from '@ohos.bundleState'; ...@@ -108,26 +108,26 @@ import stats from '@ohos.bundleState';
import stats from '@ohos.bundleState' import stats from '@ohos.bundleState'
// 异步方法promise方式 // 异步方法promise方式
stats.queryCurrentBundleActiveStates(0, 20000000000000).then( res => { stats.queryCurrentBundleActiveStates(0, 20000000000000).then(res => {
console.log('BUNDLE_ACTIVE queryCurrentBundleActiveStates promise success.'); console.log('BUNDLE_ACTIVE queryCurrentBundleActiveStates promise success.');
for (let i = 0; i < res.length; i++) { for (let i = 0; i < res.length; i++) {
console.log('BUNDLE_ACTIVE queryCurrentBundleActiveStates promise number : ' + (i + 1)); console.log('BUNDLE_ACTIVE queryCurrentBundleActiveStates promise number : ' + (i + 1));
console.log('BUNDLE_ACTIVE queryCurrentBundleActiveStates promise result ' + JSON.stringify(res[i])); console.log('BUNDLE_ACTIVE queryCurrentBundleActiveStates promise result ' + JSON.stringify(res[i]));
} }
}).catch( err => { }).catch(err => {
console.log('BUNDLE_ACTIVE queryCurrentBundleActiveStates promise failed, because: ' + err.code); console.log('BUNDLE_ACTIVE queryCurrentBundleActiveStates promise failed, because: ' + err.code);
}); });
// 异步方法callback方式 // 异步方法callback方式
stats.queryCurrentBundleActiveStates(0, 20000000000000, (err, res) => { stats.queryCurrentBundleActiveStates(0, 20000000000000, (err, res) => {
if(err.code == 0) { if (err) {
console.log('BUNDLE_ACTIVE queryCurrentBundleActiveStates callback failed, because: ' + err.code);
} else {
console.log('BUNDLE_ACTIVE queryCurrentBundleActiveStates callback success.'); console.log('BUNDLE_ACTIVE queryCurrentBundleActiveStates callback success.');
for (let i = 0; i < res.length; i++) { for (let i = 0; i < res.length; i++) {
console.log('BUNDLE_ACTIVE queryCurrentBundleActiveStates callback number : ' + (i + 1)); console.log('BUNDLE_ACTIVE queryCurrentBundleActiveStates callback number : ' + (i + 1));
console.log('BUNDLE_ACTIVE queryCurrentBundleActiveStates callback result ' + JSON.stringify(res[i])); console.log('BUNDLE_ACTIVE queryCurrentBundleActiveStates callback result ' + JSON.stringify(res[i]));
} }
} else {
console.log('BUNDLE_ACTIVE queryCurrentBundleActiveStates callback failed, because: ' + err.code);
} }
}); });
``` ```
...@@ -138,26 +138,26 @@ import stats from '@ohos.bundleState'; ...@@ -138,26 +138,26 @@ import stats from '@ohos.bundleState';
import stats from '@ohos.bundleState' import stats from '@ohos.bundleState'
// 异步方法promise方式 // 异步方法promise方式
stats.queryBundleStateInfoByInterval(0, 0, 20000000000000).then( res => { stats.queryBundleStateInfoByInterval(0, 0, 20000000000000).then(res => {
console.log('BUNDLE_ACTIVE queryBundleStateInfoByInterval promise success.'); console.log('BUNDLE_ACTIVE queryBundleStateInfoByInterval promise success.');
for (let i = 0; i < res.length; i++) { for (let i = 0; i < res.length; i++) {
console.log('BUNDLE_ACTIVE queryBundleStateInfoByInterval promise number : ' + (i + 1)); console.log('BUNDLE_ACTIVE queryBundleStateInfoByInterval promise number : ' + (i + 1));
console.log('BUNDLE_ACTIVE queryBundleStateInfoByInterval promise result ' + JSON.stringify(res[i])); console.log('BUNDLE_ACTIVE queryBundleStateInfoByInterval promise result ' + JSON.stringify(res[i]));
} }
}).catch( err => { }).catch(err => {
console.log('BUNDLE_ACTIVE queryBundleStateInfoByInterval promise failed, because: ' + err.code); console.log('BUNDLE_ACTIVE queryBundleStateInfoByInterval promise failed, because: ' + err.code);
}); });
// 异步方法callback方式 // 异步方法callback方式
stats.queryBundleStateInfoByInterval(0, 0, 20000000000000, (err, res) => { stats.queryBundleStateInfoByInterval(0, 0, 20000000000000, (err, res) => {
if(err.code == 0) { if (err) {
console.log('BUNDLE_ACTIVE queryBundleStateInfoByInterval callback failed, because: ' + err.code);
} else {
console.log('BUNDLE_ACTIVE queryBundleStateInfoByInterval callback success.'); console.log('BUNDLE_ACTIVE queryBundleStateInfoByInterval callback success.');
for (let i = 0; i < res.length; i++) { for (let i = 0; i < res.length; i++) {
console.log('BUNDLE_ACTIVE queryBundleStateInfoByInterval callback number : ' + (i + 1)); console.log('BUNDLE_ACTIVE queryBundleStateInfoByInterval callback number : ' + (i + 1));
console.log('BUNDLE_ACTIVE queryBundleStateInfoByInterval callback result ' + JSON.stringify(res[i])); console.log('BUNDLE_ACTIVE queryBundleStateInfoByInterval callback result ' + JSON.stringify(res[i]));
} }
} else {
console.log('BUNDLE_ACTIVE queryBundleStateInfoByInterval callback failed, because: ' + err.code);
} }
}); });
``` ```
...@@ -168,18 +168,18 @@ import stats from '@ohos.bundleState'; ...@@ -168,18 +168,18 @@ import stats from '@ohos.bundleState';
import stats from '@ohos.bundleState' import stats from '@ohos.bundleState'
// 异步方法promise方式 // 异步方法promise方式
stats.queryAppUsagePriorityGroup().then( res => { stats.queryAppUsagePriorityGroup().then(res => {
console.log('BUNDLE_ACTIVE queryAppUsagePriorityGroup promise succeeded. result: ' + JSON.stringify(res)); console.log('BUNDLE_ACTIVE queryAppUsagePriorityGroup promise succeeded. result: ' + JSON.stringify(res));
}).catch( err => { }).catch(err => {
console.log('BUNDLE_ACTIVE queryAppUsagePriorityGroup promise failed. because: ' + err.code); console.log('BUNDLE_ACTIVE queryAppUsagePriorityGroup promise failed. because: ' + err.code);
}); });
// 异步方法callback方式 // 异步方法callback方式
stats.queryAppUsagePriorityGroup((err, res) => { stats.queryAppUsagePriorityGroup((err, res) => {
if(err.code === 0) { if (err) {
console.log('BUNDLE_ACTIVE queryAppUsagePriorityGroup callback succeeded. result: ' + JSON.stringify(res));
} else {
console.log('BUNDLE_ACTIVE queryAppUsagePriorityGroup callback failed. because: ' + err.code); console.log('BUNDLE_ACTIVE queryAppUsagePriorityGroup callback failed. because: ' + err.code);
} else {
console.log('BUNDLE_ACTIVE queryAppUsagePriorityGroup callback succeeded. result: ' + JSON.stringify(res));
} }
}); });
``` ```
...@@ -190,18 +190,18 @@ import stats from '@ohos.bundleState'; ...@@ -190,18 +190,18 @@ import stats from '@ohos.bundleState';
import stats from '@ohos.bundleState' import stats from '@ohos.bundleState'
// 异步方法promise方式 // 异步方法promise方式
stats.isIdleState("com.ohos.camera").then( res => { stats.isIdleState("com.ohos.camera").then(res => {
console.log('BUNDLE_ACTIVE isIdleState promise succeeded, result: ' + JSON.stringify(res)); console.log('BUNDLE_ACTIVE isIdleState promise succeeded, result: ' + JSON.stringify(res));
}).catch( err => { }).catch(err => {
console.log('BUNDLE_ACTIVE isIdleState promise failed, because: ' + err.code); console.log('BUNDLE_ACTIVE isIdleState promise failed, because: ' + err.code);
}); });
// 异步方法callback方式 // 异步方法callback方式
stats.isIdleState("com.ohos.camera", (err, res) => { stats.isIdleState("com.ohos.camera", (err, res) => {
if(err.code === 0) { if (err) {
console.log('BUNDLE_ACTIVE isIdleState callback succeeded, result: ' + JSON.stringify(res));
} else {
console.log('BUNDLE_ACTIVE isIdleState callback failed, because: ' + err.code); console.log('BUNDLE_ACTIVE isIdleState callback failed, because: ' + err.code);
} else {
console.log('BUNDLE_ACTIVE isIdleState callback succeeded, result: ' + JSON.stringify(res));
} }
}); });
``` ```
\ No newline at end of file
...@@ -3,9 +3,13 @@ ...@@ -3,9 +3,13 @@
## 场景介绍 ## 场景介绍
使用坐标描述一个位置,非常准确,但是并不直观,面向用户表达并不友好。 使用坐标描述一个位置,非常准确,但是并不直观,面向用户表达并不友好。系统向开发者提供了以下两种转化能力。
系统向开发者提供了地理编码转化能力(将地理描述转化为具体坐标),以及逆地理编码转化能力(将坐标转化为地理描述)。其中地理编码包含多个属性来描述位置,包括国家、行政区划、街道、门牌号、地址描述等等,这样的信息更便于用户理解。 - 地理编码转化:将地理描述转化为具体坐标。
- 逆地理编码转化能力:将坐标转化为地理描述。
其中地理编码包含多个属性来描述位置,包括国家、行政区划、街道、门牌号、地址描述等等,这样的信息更便于用户理解。
## 接口说明 ## 接口说明
......
# 传感器开发概述 # 传感器开发概述
OpenHarmony系统传感器是应用访问底层硬件传感器的一种设备抽象概念。开发者根据传感器提供的Sensor API,可以查询设备上的传感器,订阅传感器数据,并根据传感器数据定制相应的算法开发各类应用,比如指南针、运动健康、游戏等。 OpenHarmony系统传感器是应用访问底层硬件传感器的一种设备抽象概念。开发者根据传感器提供的[Sensor接口](../reference/apis/js-apis-sensor.md),可以查询设备上的传感器,订阅传感器数据,并根据传感器数据定制相应的算法开发各类应用,比如指南针、运动健康、游戏等。
传感器是指用于侦测环境中所发生事件或变化,并将此消息发送至其他电子设备(如中央处理器)的设备,通常由敏感组件和转换组件组成。传感器是实现物联网智能化的重要基石,为实现全场景智慧化战略,支撑“1+8+N”产品需求,需要构筑统一的传感器管理框架,达到为各产品/业务提供低时延、低功耗的感知数据的目的。下面为传感器列表: 传感器是指用于侦测环境中所发生事件或变化,并将此消息发送至其他电子设备(如中央处理器)的设备,通常由敏感组件和转换组件组成。传感器是实现物联网智能化的重要基石,为实现全场景智慧化战略,支撑“1+8+N”产品需求,需要构筑统一的传感器管理框架,达到为各产品/业务提供低时延、低功耗的感知数据的目的。下面为传感器列表:
......
...@@ -5,6 +5,8 @@ ...@@ -5,6 +5,8 @@
当设备需要设置不同的振动效果时,可以调用Vibrator模块,例如:设备的按键可以设置不同强度和不同时长的振动,闹钟和来电可以设置不同强度和时长的单次或周期振动。 当设备需要设置不同的振动效果时,可以调用Vibrator模块,例如:设备的按键可以设置不同强度和不同时长的振动,闹钟和来电可以设置不同强度和时长的单次或周期振动。
详细的接口介绍请参考[Vibrator接口](../reference/apis/js-apis-vibrator.md)
## 接口说明 ## 接口说明
......
...@@ -12,18 +12,19 @@ I18n开发指导提供了未在ECMA 402中定义的国际化能力接口的使 ...@@ -12,18 +12,19 @@ I18n开发指导提供了未在ECMA 402中定义的国际化能力接口的使
| 模块 | 接口名称 | 描述 | | 模块 | 接口名称 | 描述 |
| -------- | -------- | -------- | | -------- | -------- | -------- |
| ohos.i18n | getSystemLanguage():&nbsp;string | 获取系统语言。 | | ohos.i18n | getSystemLanguage():string | 获取系统语言。 |
| ohos.i18n | getSystemRegion():&nbsp;string | 获取系统区域。 | | ohos.i18n | getSystemRegion():string | 获取系统区域。 |
| ohos.i18n | getSystemLocale():&nbsp;string | 获取系统Locale。 | | ohos.i18n | getSystemLocale():string | 获取系统Locale。 |
| ohos.i18n | isRTL(locale:&nbsp;string):&nbsp;boolean<sup>7+</sup> | locale对应的语言是否为从右到左语言。 | | ohos.i18n | isRTL(locale:string):boolean<sup>7+</sup> | locale对应的语言是否为从右到左语言。 |
| ohos.i18n | is24HourClock():&nbsp;boolean<sup>7+</sup> | 获取当前系统时间是否采用24小时制 | | ohos.i18n | is24HourClock():boolean<sup>7+</sup> | 获取当前系统时间是否采用24小时制。 |
| ohos.i18n | getDisplayLanguage(language:&nbsp;string,&nbsp;locale:&nbsp;string,&nbsp;sentenceCase?:&nbsp;boolean):&nbsp;string | 获取语言的本地化表示。 | | ohos.i18n | getDisplayLanguage(language:string,locale:string,sentenceCase?:boolean):string | 获取语言的本地化表示。 |
| ohos.i18n | getDisplayCountry(country:&nbsp;string,&nbsp;locale:&nbsp;string,&nbsp;sentenceCase?:&nbsp;boolean):&nbsp;string | 获取国家的本地化表示。 | | ohos.i18n | getDisplayCountry(country:string,locale:string,sentenceCase?:boolean):string | 获取国家的本地化表示。 |
### 开发步骤 ### 开发步骤
1. 获取系统语言 1. 获取系统语言。
调用getSystemLanguage方法获取当前系统设置的语言(i18n为导入的模块)。 调用getSystemLanguage方法获取当前系统设置的语言(i18n为导入的模块)。
...@@ -31,21 +32,24 @@ I18n开发指导提供了未在ECMA 402中定义的国际化能力接口的使 ...@@ -31,21 +32,24 @@ I18n开发指导提供了未在ECMA 402中定义的国际化能力接口的使
var language = i18n.getSystemLanguage(); var language = i18n.getSystemLanguage();
``` ```
2. 获取系统区域 2. 获取系统区域。
调用getSystemRegion方法获取当前系统设置的区域 调用getSystemRegion方法获取当前系统设置的区域
``` ```
var region = i18n.getSystemRegion(); var region = i18n.getSystemRegion();
``` ```
3. 获取系统Locale 3. 获取系统Locale。
调用getSystemLocale方法获取当前系统设置的Locale 调用getSystemLocale方法获取当前系统设置的Locale
``` ```
var locale = i18n.getSystemLocale(); var locale = i18n.getSystemLocale();
``` ```
4. 判断Locale的语言是否为RTL语言 4. 判断Locale的语言是否为RTL语言。
调用isRTL方法获取Locale的语言是否为从右到左语言。 调用isRTL方法获取Locale的语言是否为从右到左语言。
...@@ -53,14 +57,16 @@ I18n开发指导提供了未在ECMA 402中定义的国际化能力接口的使 ...@@ -53,14 +57,16 @@ I18n开发指导提供了未在ECMA 402中定义的国际化能力接口的使
var rtl = i18n.isRTL("zh-CN"); var rtl = i18n.isRTL("zh-CN");
``` ```
5. 判断当前系统时间是否采用24小时制 5. 判断当前系统时间是否采用24小时制。
调用is24HourClock方法来判断当前系统的时间是否采用24小时制。 调用is24HourClock方法来判断当前系统的时间是否采用24小时制。
``` ```
var hourClock = i18n.is24HourClock(); var hourClock = i18n.is24HourClock();
``` ```
6. 获取语言的本地化表示 6. 获取语言的本地化表示。
调用getDisplayLanguage方法获取某一语言的本地化表示。其中,language表示待本地化显示的语言,locale表示本地化的Locale,sentenceCase结果是否需要首字母大写。 调用getDisplayLanguage方法获取某一语言的本地化表示。其中,language表示待本地化显示的语言,locale表示本地化的Locale,sentenceCase结果是否需要首字母大写。
``` ```
...@@ -70,7 +76,8 @@ I18n开发指导提供了未在ECMA 402中定义的国际化能力接口的使 ...@@ -70,7 +76,8 @@ I18n开发指导提供了未在ECMA 402中定义的国际化能力接口的使
var localizedLanguage = i18n.getDisplayLanguage(language, locale, sentenceCase); var localizedLanguage = i18n.getDisplayLanguage(language, locale, sentenceCase);
``` ```
7. 获取国家的本地化表示 7. 获取国家的本地化表示。
调用getDisplayCountry方法获取某一国家的本地化表示。其中,country表示待本地化显示的国家,locale表示本地化的Locale,sentenceCase结果是否需要首字母大写。 调用getDisplayCountry方法获取某一国家的本地化表示。其中,country表示待本地化显示的国家,locale表示本地化的Locale,sentenceCase结果是否需要首字母大写。
``` ```
...@@ -90,23 +97,24 @@ I18n开发指导提供了未在ECMA 402中定义的国际化能力接口的使 ...@@ -90,23 +97,24 @@ I18n开发指导提供了未在ECMA 402中定义的国际化能力接口的使
| 模块 | 接口名称 | 描述 | | 模块 | 接口名称 | 描述 |
| -------- | -------- | -------- | | -------- | -------- | -------- |
| ohos.i18n | getCalendar(locale:&nbsp;string,&nbsp;type?:&nbsp;string):&nbsp;Calendar<sup>8+</sup> | 获取指定locale和type的日历对象。 | | ohos.i18n | getCalendar(locale:string,type?:string):Calendar<sup>8+</sup> | 获取指定locale和type的日历对象。 |
| ohos.i18n | setTime(date:&nbsp;Date): void<sup>8+</sup> | 设置日历对象内部的时间日期。 | | ohos.i18n | setTime(date:Date): void<sup>8+</sup> | 设置日历对象内部的时间日期。 |
| ohos.i18n | setTime(time:&nbsp;number): void<sup>8+</sup> | 设置日历对象内部的时间日期。 | | ohos.i18n | setTime(time:number): void<sup>8+</sup> | 设置日历对象内部的时间日期。 |
| ohos.i18n | set(year:&nbsp;number,&nbsp;month:&nbsp;number,&nbsp;date:&nbsp;number,&nbsp;hour?:&nbsp;number,&nbsp;minute?:&nbsp;number,&nbsp;second?:&nbsp;number): void<sup>8+</sup> | 设置日历对象的年、月、日、时、分、秒。 | | ohos.i18n | set(year:number,month:number,date:number,hour?:number,minute?:number,second?:number): void<sup>8+</sup> | 设置日历对象的年、月、日、时、分、秒。 |
| ohos.i18n | setTimeZone(timezone:&nbsp;string): void<sup>8+</sup> | 设置日历对象的时区。 | | ohos.i18n | setTimeZone(timezone:string): void<sup>8+</sup> | 设置日历对象的时区。 |
| ohos.i18n | getTimeZone():&nbsp;string<sup>8+</sup> | 获取日历对象的时区。 | | ohos.i18n | getTimeZone():string<sup>8+</sup> | 获取日历对象的时区。 |
| ohos.i18n | getFirstDayOfWeek():&nbsp;number<sup>8+</sup> | 获取日历对象的一周起始日。 | | ohos.i18n | getFirstDayOfWeek():number<sup>8+</sup> | 获取日历对象的一周起始日。 |
| ohos.i18n | setFirstDayOfWeek(value:&nbsp;number): void<sup>8+</sup> | 设置日历对象的一周起始日。 | | ohos.i18n | setFirstDayOfWeek(value:number): void<sup>8+</sup> | 设置日历对象的一周起始日。 |
| ohos.i18n | getMinimalDaysInFirstWeek():&nbsp;number<sup>8+</sup> | 获取一年中第一周的最小天数。 | | ohos.i18n | getMinimalDaysInFirstWeek():number<sup>8+</sup> | 获取一年中第一周的最小天数。 |
| ohos.i18n | setMinimalDaysInFirstWeek(value:&nbsp;number): void<sup>8+</sup> | 设置一年中第一周的最小天数。 | | ohos.i18n | setMinimalDaysInFirstWeek(value:number): void<sup>8+</sup> | 设置一年中第一周的最小天数。 |
| ohos.i18n | getDisplayName(locale:&nbsp;string):&nbsp;string<sup>8+</sup> | 获取日历对象的本地化表示。 | | ohos.i18n | getDisplayName(locale:string):string<sup>8+</sup> | 获取日历对象的本地化表示。 |
| ohos.i18n | isWeekend(date?:&nbsp;Date):&nbsp;boolean<sup>8+</sup> | 判断给定的日期是否在日历中是周末。 | | ohos.i18n | isWeekend(date?:Date):boolean<sup>8+</sup> | 判断给定的日期是否在日历中是周末。 |
### 开发步骤 ### 开发步骤
1. 实例化日历对象 1. 实例化日历对象。
调用getCalendar方法获取指定locale和type的时区对象(i18n为导入的模块)。其中,type表示合法的日历类型,目前合法的日历类型包括:"buddhist", "chinese", "coptic", "ethiopic", "hebrew", "gregory", "indian", "islamic_civil", "islamic_tbla", "islamic_umalqura", "japanese", "persian"。当type没有给出时,采用区域默认的日历类型。 调用getCalendar方法获取指定locale和type的时区对象(i18n为导入的模块)。其中,type表示合法的日历类型,目前合法的日历类型包括:"buddhist", "chinese", "coptic", "ethiopic", "hebrew", "gregory", "indian", "islamic_civil", "islamic_tbla", "islamic_umalqura", "japanese", "persian"。当type没有给出时,采用区域默认的日历类型。
...@@ -114,7 +122,8 @@ I18n开发指导提供了未在ECMA 402中定义的国际化能力接口的使 ...@@ -114,7 +122,8 @@ I18n开发指导提供了未在ECMA 402中定义的国际化能力接口的使
var calendar = i18n.getCalendar("zh-CN", "gregory); var calendar = i18n.getCalendar("zh-CN", "gregory);
``` ```
2. 设置日历对象的时间 2. 设置日历对象的时间。
调用setTime方法设置日历对象的时间。setTime方法接收两种类型的参数。一种是传入一个Date对象,另一种是传入一个数值表示从1970.1.1 00:00:00 GMT逝去的毫秒数。 调用setTime方法设置日历对象的时间。setTime方法接收两种类型的参数。一种是传入一个Date对象,另一种是传入一个数值表示从1970.1.1 00:00:00 GMT逝去的毫秒数。
``` ```
...@@ -124,14 +133,16 @@ I18n开发指导提供了未在ECMA 402中定义的国际化能力接口的使 ...@@ -124,14 +133,16 @@ I18n开发指导提供了未在ECMA 402中定义的国际化能力接口的使
calendar.setTime(date2); calendar.setTime(date2);
``` ```
3. 设置日历对象的年、月、日、时、分、秒 3. 设置日历对象的年、月、日、时、分、秒。
调用set方法设置日历对象的年、月、日、时、分、秒。 调用set方法设置日历对象的年、月、日、时、分、秒。
``` ```
calendar.set(2021, 12, 21, 6, 0, 0) calendar.set(2021, 12, 21, 6, 0, 0)
``` ```
4. 设置、获取日历对象的时区 4. 设置、获取日历对象的时区。
调用setTimeZone方法和getTimeZone方法来设置、获取日历对象的时区。其中,setTimeZone方法需要传入一个字符串表示需要设置的时区。 调用setTimeZone方法和getTimeZone方法来设置、获取日历对象的时区。其中,setTimeZone方法需要传入一个字符串表示需要设置的时区。
...@@ -140,7 +151,8 @@ I18n开发指导提供了未在ECMA 402中定义的国际化能力接口的使 ...@@ -140,7 +151,8 @@ I18n开发指导提供了未在ECMA 402中定义的国际化能力接口的使
var timezone = calendar.getTimeZone(); var timezone = calendar.getTimeZone();
``` ```
5. 设置、获取日历对象的一周起始日 5. 设置、获取日历对象的一周起始日。
调用setFirstDayOfWeek方法和getFirstDayOfWeek方法设置、获取日历对象的一周起始日。其中,setFirstDayOfWeek需要传入一个数值表示一周的起始日,1代表周日,7代表周六。 调用setFirstDayOfWeek方法和getFirstDayOfWeek方法设置、获取日历对象的一周起始日。其中,setFirstDayOfWeek需要传入一个数值表示一周的起始日,1代表周日,7代表周六。
...@@ -165,7 +177,8 @@ I18n开发指导提供了未在ECMA 402中定义的国际化能力接口的使 ...@@ -165,7 +177,8 @@ I18n开发指导提供了未在ECMA 402中定义的国际化能力接口的使
var localizedName = calendar.getDisplayName("zh-CN"); var localizedName = calendar.getDisplayName("zh-CN");
``` ```
8. 判断某一个日期是否为周末 8. 判断某一个日期是否为周末。
调用isWeekend方法来判断输入的Date是否为周末。 调用isWeekend方法来判断输入的Date是否为周末。
...@@ -184,14 +197,15 @@ I18n开发指导提供了未在ECMA 402中定义的国际化能力接口的使 ...@@ -184,14 +197,15 @@ I18n开发指导提供了未在ECMA 402中定义的国际化能力接口的使
| 模块 | 接口名称 | 描述 | | 模块 | 接口名称 | 描述 |
| -------- | -------- | -------- | | -------- | -------- | -------- |
| ohos.i18n | constructor(country:&nbsp;string,&nbsp;options?:&nbsp;PhoneNumberFormatOptions)<sup>8+</sup> | 实例化PhoneNumberFormat对象。 | | ohos.i18n | constructor(country:string,options?:PhoneNumberFormatOptions)<sup>8+</sup> | 实例化PhoneNumberFormat对象。 |
| ohos.i18n | isValidNumber(number:&nbsp;string):&nbsp;boolean<sup>8+</sup> | 判断number是否是一个格式正确的电话号码。 | | ohos.i18n | isValidNumber(number:string):boolean<sup>8+</sup> | 判断number是否是一个格式正确的电话号码。 |
| ohos.i18n | format(number:&nbsp;string):&nbsp;string<sup>8+</sup> | 对number按照指定国家及风格进行格式化。 | | ohos.i18n | format(number:string):string<sup>8+</sup> | 对number按照指定国家及风格进行格式化。 |
### 开发步骤 ### 开发步骤
1. 实例化电话号码格式化对象 1. 实例化电话号码格式化对象。
调用PhoneNumberFormat的构造函数来实例化电话号码格式化对象,需要传入电话号码的国家代码及格式化选项。其中,格式化选项是可选的,包括style选项,该选项的取值包括:"E164", "INTERNATIONAL", "NATIONAL", "RFC3966"。 调用PhoneNumberFormat的构造函数来实例化电话号码格式化对象,需要传入电话号码的国家代码及格式化选项。其中,格式化选项是可选的,包括style选项,该选项的取值包括:"E164", "INTERNATIONAL", "NATIONAL", "RFC3966"。
...@@ -199,14 +213,16 @@ I18n开发指导提供了未在ECMA 402中定义的国际化能力接口的使 ...@@ -199,14 +213,16 @@ I18n开发指导提供了未在ECMA 402中定义的国际化能力接口的使
var phoneNumberFormat = new i18n.PhoneNubmerFormat("CN", {type: "E164"}); var phoneNumberFormat = new i18n.PhoneNubmerFormat("CN", {type: "E164"});
``` ```
2. 判断电话号码格式是否正确 2. 判断电话号码格式是否正确。
调用isValidNumber方法来判断输入的电话号码的格式是否正确。 调用isValidNumber方法来判断输入的电话号码的格式是否正确。
``` ```
var validNumber = phoneNumberFormat.isValidNumber("15812341234"); var validNumber = phoneNumberFormat.isValidNumber("15812341234");
``` ```
3. 电话号码格式化 3. 电话号码格式化。
调用电话号码格式化对象的format方法来对输入的电话号码进行格式化。 调用电话号码格式化对象的format方法来对输入的电话号码进行格式化。
``` ```
...@@ -223,12 +239,13 @@ I18n开发指导提供了未在ECMA 402中定义的国际化能力接口的使 ...@@ -223,12 +239,13 @@ I18n开发指导提供了未在ECMA 402中定义的国际化能力接口的使
| 模块 | 接口名称 | 描述 | | 模块 | 接口名称 | 描述 |
| -------- | -------- | -------- | | -------- | -------- | -------- |
| ohos.i18n | unitConvert(fromUnit:&nbsp;UnitInfo,&nbsp;toUnit:&nbsp;UnitInfo,&nbsp;value:&nbsp;number,&nbsp;locale:&nbsp;string,&nbsp;style?:&nbsp;string):&nbsp;string<sup>8+</sup> | 将fromUnit的单位转换为toUnit的单位,并根据区域与风格进行格式化。 | | ohos.i18n | unitConvert(fromUnit:UnitInfo,toUnit:UnitInfo,value:number,locale:string,style?:string):string<sup>8+</sup> | 将fromUnit的单位转换为toUnit的单位,并根据区域与风格进行格式化。 |
### 开发步骤 ### 开发步骤
1. 度量衡单位转换 1. 度量衡单位转换。
调用[unitConvert](../reference/apis/js-apis-intl.md)方法实现度量衡单位转换,并进行格式化显示的功能。 调用[unitConvert](../reference/apis/js-apis-intl.md)方法实现度量衡单位转换,并进行格式化显示的功能。
...@@ -251,15 +268,16 @@ I18n开发指导提供了未在ECMA 402中定义的国际化能力接口的使 ...@@ -251,15 +268,16 @@ I18n开发指导提供了未在ECMA 402中定义的国际化能力接口的使
| 模块 | 接口名称 | 描述 | | 模块 | 接口名称 | 描述 |
| -------- | -------- | -------- | | -------- | -------- | -------- |
| ohos.i18n | getInstance(locale?:&nbsp;string):&nbsp;IndexUtil<sup>8+</sup> | 实例化字母表索引对象。 | | ohos.i18n | getInstance(locale?:string):IndexUtil<sup>8+</sup> | 实例化字母表索引对象。 |
| ohos.i18n | getIndexList():&nbsp;Array&lt;string&gt;<sup>8+</sup> | 获取当前Locale的索引列表。 | | ohos.i18n | getIndexList():Array&lt;string&gt;<sup>8+</sup> | 获取当前Locale的索引列表。 |
| ohos.i18n | addLocale(locale:&nbsp;string): void<sup>8+</sup> | 将新的Locale对应的索引加入当前索引列表。 | | ohos.i18n | addLocale(locale:string): void<sup>8+</sup> | 将新的Locale对应的索引加入当前索引列表。 |
| ohos.i18n | getIndex(text:&nbsp;string):&nbsp;string<sup>8+</sup> | 获取text对应的索引。 | | ohos.i18n | getIndex(text:string):string<sup>8+</sup> | 获取text对应的索引。 |
### 开发步骤 ### 开发步骤
1. 实例化字母表索引对象 1. 实例化字母表索引对象。
调用getInstance方法来实例化特定locale对应的字母表索引对象。当locale参数为空时,实例化系统默认Locale的字母表索引对象。 调用getInstance方法来实例化特定locale对应的字母表索引对象。当locale参数为空时,实例化系统默认Locale的字母表索引对象。
...@@ -267,21 +285,24 @@ I18n开发指导提供了未在ECMA 402中定义的国际化能力接口的使 ...@@ -267,21 +285,24 @@ I18n开发指导提供了未在ECMA 402中定义的国际化能力接口的使
var indexUtil = getInstance("zh-CN"); var indexUtil = getInstance("zh-CN");
``` ```
2. 获取索引列表 2. 获取索引列表。
调用getIndexList方法来获取当前Locale对应的字母表索引列表。 调用getIndexList方法来获取当前Locale对应的字母表索引列表。
``` ```
var indexList = indexUtil.getIndexList(); var indexList = indexUtil.getIndexList();
``` ```
3. 增加新的索引 3. 增加新的索引。
调用addLocale方法,将新的Locale对应的字母表索引添加到当前字母表索引列表中。 调用addLocale方法,将新的Locale对应的字母表索引添加到当前字母表索引列表中。
``` ```
indexUtil.addLocale("ar") indexUtil.addLocale("ar")
``` ```
4. 获取字符串对应的索引 4. 获取字符串对应的索引。
调用getIndex方法来获取某一字符串对应的字母表索引。 调用getIndex方法来获取某一字符串对应的字母表索引。
``` ```
...@@ -299,21 +320,22 @@ I18n开发指导提供了未在ECMA 402中定义的国际化能力接口的使 ...@@ -299,21 +320,22 @@ I18n开发指导提供了未在ECMA 402中定义的国际化能力接口的使
| 模块 | 接口名称 | 描述 | | 模块 | 接口名称 | 描述 |
| -------- | -------- | -------- | | -------- | -------- | -------- |
| ohos.i18n | getLineInstance(locale:&nbsp;string):&nbsp;BreakIterator<sup>8+</sup> | 实例化断行对象。 | | ohos.i18n | getLineInstance(locale:string):BreakIterator<sup>8+</sup> | 实例化断行对象。 |
| ohos.i18n | setLineBreakText(text:&nbsp;string): void<sup>8+</sup> | 设置要处理的文本。 | | ohos.i18n | setLineBreakText(text:string): void<sup>8+</sup> | 设置要处理的文本。 |
| ohos.i18n | getLineBreakText():&nbsp;string<sup>8+</sup> | 获取要处理的文本。 | | ohos.i18n | getLineBreakText():string<sup>8+</sup> | 获取要处理的文本。 |
| ohos.i18n | current():&nbsp;number<sup>8+</sup> | 获取当前断行对象在处理文本的位置。 | | ohos.i18n | current():number<sup>8+</sup> | 获取当前断行对象在处理文本的位置。 |
| ohos.i18n | first():&nbsp;number<sup>8+</sup> | 将断行对象设置到第一个可断句的分割点。 | | ohos.i18n | first():number<sup>8+</sup> | 将断行对象设置到第一个可断句的分割点。 |
| ohos.i18n | last():&nbsp;number<sup>8+</sup> | 将断行对象设置到最后一个可断句的分割点。 | | ohos.i18n | last():number<sup>8+</sup> | 将断行对象设置到最后一个可断句的分割点。 |
| ohos.i18n | next(index?:&nbsp;number):&nbsp;number<sup>8+</sup> | 将断行对象移动index个分割点的位置。 | | ohos.i18n | next(index?:number):number<sup>8+</sup> | 将断行对象移动index个分割点的位置。 |
| ohos.i18n | previous():&nbsp;number<sup>8+</sup> | 将断行对象移动到前一个分割点的位置。 | | ohos.i18n | previous():number<sup>8+</sup> | 将断行对象移动到前一个分割点的位置。 |
| ohos.i18n | following(offset:&nbsp;number):&nbsp;number<sup>8+</sup> | 将断行对象移动到offset指定位置的后面一个分割点的位置。 | | ohos.i18n | following(offset:number):number<sup>8+</sup> | 将断行对象移动到offset指定位置的后面一个分割点的位置。 |
| ohos.i18n | isBoundary(offset:&nbsp;number):&nbsp;boolean<sup>8+</sup> | 判断某个位置是否是分割点。 | | ohos.i18n | isBoundary(offset:number):boolean<sup>8+</sup> | 判断某个位置是否是分割点。 |
### 开发步骤 ### 开发步骤
1. 实例化断行对象 1. 实例化断行对象。
调用getLineInstance方法来实例化断行对象。 调用getLineInstance方法来实例化断行对象。
...@@ -322,7 +344,8 @@ I18n开发指导提供了未在ECMA 402中定义的国际化能力接口的使 ...@@ -322,7 +344,8 @@ I18n开发指导提供了未在ECMA 402中定义的国际化能力接口的使
var breakIterator = i18n.getLineInstance(locale); var breakIterator = i18n.getLineInstance(locale);
``` ```
2. 设置、访问要断行处理的文本 2. 设置、访问要断行处理的文本。
调用setLineBreakText方法和getLineBreakText方法来设置、访问要断行处理的文本。 调用setLineBreakText方法和getLineBreakText方法来设置、访问要断行处理的文本。
...@@ -332,7 +355,8 @@ I18n开发指导提供了未在ECMA 402中定义的国际化能力接口的使 ...@@ -332,7 +355,8 @@ I18n开发指导提供了未在ECMA 402中定义的国际化能力接口的使
var breakText = breakIterator.getLineBreakText(); var breakText = breakIterator.getLineBreakText();
``` ```
3. 获取断行对象当前的位置 3. 获取断行对象当前的位置。
调用current方法来获取断行对象在当前处理文本中的位置。 调用current方法来获取断行对象在当前处理文本中的位置。
...@@ -340,7 +364,8 @@ I18n开发指导提供了未在ECMA 402中定义的国际化能力接口的使 ...@@ -340,7 +364,8 @@ I18n开发指导提供了未在ECMA 402中定义的国际化能力接口的使
var pos = breakIterator.current(); var pos = breakIterator.current();
``` ```
4. 设置断行对象的位置 4. 设置断行对象的位置。
系统提供了很多接口可以用于调整断行对象在处理文本中的位置,包括first, last, next, previous, following。 系统提供了很多接口可以用于调整断行对象在处理文本中的位置,包括first, last, next, previous, following。
...@@ -356,7 +381,8 @@ I18n开发指导提供了未在ECMA 402中定义的国际化能力接口的使 ...@@ -356,7 +381,8 @@ I18n开发指导提供了未在ECMA 402中定义的国际化能力接口的使
var followingPos = breakIterator.following(10); var followingPos = breakIterator.following(10);
``` ```
5. 判断某个位置是否为分割点 5. 判断某个位置是否为分割点。
调用isBoundary方法来判断一个方法是否为分割点;如果该位置是分割点,则返回true,并且将断行对象移动到该位置;如果该位置不是分割点,则返回false,并且将断行对象移动到该位置后的一个分割点。 调用isBoundary方法来判断一个方法是否为分割点;如果该位置是分割点,则返回true,并且将断行对象移动到该位置;如果该位置不是分割点,则返回false,并且将断行对象移动到该位置后的一个分割点。
......
...@@ -2,7 +2,6 @@ ...@@ -2,7 +2,6 @@
Intl开发指导提供了ECMA 402中定义的国际化能力接口的使用方法。 Intl开发指导提供了ECMA 402中定义的国际化能力接口的使用方法。
## 设置区域信息 ## 设置区域信息
调用[Locale](../reference/apis/js-apis-intl.md)的相关接口实现最大化区域信息或最小化区域信息。 调用[Locale](../reference/apis/js-apis-intl.md)的相关接口实现最大化区域信息或最小化区域信息。
...@@ -11,17 +10,18 @@ Intl开发指导提供了ECMA 402中定义的国际化能力接口的使用方 ...@@ -11,17 +10,18 @@ Intl开发指导提供了ECMA 402中定义的国际化能力接口的使用方
### 接口说明 ### 接口说明
| 模块 | 接口名称 | 描述 | | 模块 | 接口名称 | 描述 |
| --------- | ---------------------------------------- | -------------------------- | | -------- | -------- | -------- |
| ohos.intl | constructor()<sup>8+</sup> | 实例化Locale对象。 | | ohos.intl | constructor()<sup>8+</sup> | 实例化Locale对象。 |
| ohos.intl | constructor(locale:&nbsp;string,&nbsp;options?:&nbsp;LocaleOptions) | 基于locale参数及其选项实例化Locale对象。 | | ohos.intl | constructor(locale:string,options?:LocaleOptions) | 基于locale参数及其选项实例化Locale对象。 |
| ohos.intl | toString():&nbsp;string | 将Locale信息转换为字符串。 | | ohos.intl | toString():string | 将Locale信息转换为字符串。 |
| ohos.intl | maximize():&nbsp;Locale | 最大化区域信息。 | | ohos.intl | maximize():Locale | 最大化区域信息。 |
| ohos.intl | minimize():&nbsp;Locale | 最小化区域信息。 | | ohos.intl | minimize():Locale | 最小化区域信息。 |
### 开发步骤 ### 开发步骤
1. 实例化Locale对象 1. 实例化Locale对象。
使用Locale的构造函数创建Locale对象,该方法接收一个表示Locale的字符串及可选的[属性](../reference/apis/js-apis-intl.md)列表(intl为导入的模块名)。 使用Locale的构造函数创建Locale对象,该方法接收一个表示Locale的字符串及可选的[属性](../reference/apis/js-apis-intl.md)列表(intl为导入的模块名)。
...@@ -31,21 +31,24 @@ Intl开发指导提供了ECMA 402中定义的国际化能力接口的使用方 ...@@ -31,21 +31,24 @@ Intl开发指导提供了ECMA 402中定义的国际化能力接口的使用方
var localeObj = new intl.Locale(locale, options); var localeObj = new intl.Locale(locale, options);
``` ```
2. 获取Locale的字符串表示 2. 获取Locale的字符串表示。
调用toString方法来获取Locale对象的字符串表示,其中包括了语言、区域及其他选项信息。 调用toString方法来获取Locale对象的字符串表示,其中包括了语言、区域及其他选项信息。
``` ```
var localeStr = localeObj.toString(); var localeStr = localeObj.toString();
``` ```
3. 最大化区域信息 3. 最大化区域信息。
调用maximize方法来最大化区域信息,即当缺少脚本与地区信息时,对其进行补全。 调用maximize方法来最大化区域信息,即当缺少脚本与地区信息时,对其进行补全。
``` ```
var maximizedLocale = localeObj.maximize(); var maximizedLocale = localeObj.maximize();
``` ```
4. 最小化区域信息 4. 最小化区域信息。
调用minimize方法来最小化区域信息,即当存在脚本与地区信息时,对其进行删除。 调用minimize方法来最小化区域信息,即当存在脚本与地区信息时,对其进行删除。
``` ```
...@@ -61,17 +64,18 @@ Intl开发指导提供了ECMA 402中定义的国际化能力接口的使用方 ...@@ -61,17 +64,18 @@ Intl开发指导提供了ECMA 402中定义的国际化能力接口的使用方
### 接口说明 ### 接口说明
| 模块 | 接口名称 | 描述 | | 模块 | 接口名称 | 描述 |
| --------- | ---------------------------------------- | ---------------------------------------- | | -------- | -------- | -------- |
| ohos.intl | constructor()<sup>8+</sup> | 创建日期时间格式化对象。 | | ohos.intl | constructor()<sup>8+</sup> | 创建日期时间格式化对象。 |
| ohos.intl | constructor(locale:&nbsp;string&nbsp;\|&nbsp;Array&lt;string&gt;,&nbsp;options?:&nbsp;DateTimeOptions) | 创建日期时间格式化对象,并设置提供的Locale和格式化相关属性。 | | ohos.intl | constructor(locale:string\|Array&lt;string&gt;,options?:DateTimeOptions) | 创建日期时间格式化对象,并设置提供的Locale和格式化相关属性。 |
| ohos.intl | format(date:&nbsp;Date):&nbsp;string | 依据DateTimeFormat对象的Locale及其他格式化属性,计算日期时间的格式化表示。 | | ohos.intl | format(date:Date):string | 依据DateTimeFormat对象的Locale及其他格式化属性,计算日期时间的格式化表示。 |
| ohos.intl | formatRange(startDate:&nbsp;Date,&nbsp;endDate:&nbsp;Date):&nbsp;string | 依据DateTimeFormat对象的Locale及其他格式化属性,计算时间段的格式化表示。 | | ohos.intl | formatRange(startDate:Date,endDate:Date):string | 依据DateTimeFormat对象的Locale及其他格式化属性,计算时间段的格式化表示。 |
| ohos.intl | resolvedOptions():&nbsp;DateTimeOptions | 获取DateTimeFormat对象的相关属性。 | | ohos.intl | resolvedOptions():DateTimeOptions | 获取DateTimeFormat对象的相关属性。 |
### 开发步骤 ### 开发步骤
1. 实例化日期时间格式化对象 1. 实例化日期时间格式化对象。
一种方法是使用DateTimeFormat提供的默认构造函数,通过访问系统语言和地区设置,获取系统默认Locale,并将其作为DateTimeFormat对象内部的Locale(intl为导入的模块名)。 一种方法是使用DateTimeFormat提供的默认构造函数,通过访问系统语言和地区设置,获取系统默认Locale,并将其作为DateTimeFormat对象内部的Locale(intl为导入的模块名)。
...@@ -86,7 +90,8 @@ Intl开发指导提供了ECMA 402中定义的国际化能力接口的使用方 ...@@ -86,7 +90,8 @@ Intl开发指导提供了ECMA 402中定义的国际化能力接口的使用方
var dateTimeFormat = new intl.DateTimeFormat("zh-CN", options); var dateTimeFormat = new intl.DateTimeFormat("zh-CN", options);
``` ```
2. 格式化日期时间 2. 格式化日期时间。
使用DateTimeFormat的format方法对一个Date对象进行格式化,该方法会返回一个字符串作为格式化的结果。 使用DateTimeFormat的format方法对一个Date对象进行格式化,该方法会返回一个字符串作为格式化的结果。
``` ```
...@@ -94,7 +99,8 @@ Intl开发指导提供了ECMA 402中定义的国际化能力接口的使用方 ...@@ -94,7 +99,8 @@ Intl开发指导提供了ECMA 402中定义的国际化能力接口的使用方
var formatResult = dateTimeFormat.format(date); var formatResult = dateTimeFormat.format(date);
``` ```
3. 格式化时间段 3. 格式化时间段。
使用DateTimeFormat的formatRange方法对一个时间段进行格式化。该方法需要传入两个Date对象,分别表示时间段的起止时间,返回一个字符串作为格式化的结果。 使用DateTimeFormat的formatRange方法对一个时间段进行格式化。该方法需要传入两个Date对象,分别表示时间段的起止时间,返回一个字符串作为格式化的结果。
``` ```
...@@ -103,7 +109,8 @@ Intl开发指导提供了ECMA 402中定义的国际化能力接口的使用方 ...@@ -103,7 +109,8 @@ Intl开发指导提供了ECMA 402中定义的国际化能力接口的使用方
var formatResult = dateTimeFormat.formatRange(startDate, endDate); var formatResult = dateTimeFormat.formatRange(startDate, endDate);
``` ```
4. 访问日期时间格式化对象的相关属性 4. 访问日期时间格式化对象的相关属性。
DateTimeFormat的resolvedOptions方法会返回一个对象,该对象包含了DateTimeFormat对象的所有相关属性及其值。 DateTimeFormat的resolvedOptions方法会返回一个对象,该对象包含了DateTimeFormat对象的所有相关属性及其值。
``` ```
...@@ -119,16 +126,17 @@ Intl开发指导提供了ECMA 402中定义的国际化能力接口的使用方 ...@@ -119,16 +126,17 @@ Intl开发指导提供了ECMA 402中定义的国际化能力接口的使用方
### 接口说明 ### 接口说明
| 模块 | 接口名称 | 描述 | | 模块 | 接口名称 | 描述 |
| --------- | ---------------------------------------- | ---------------------------------------- | | -------- | -------- | -------- |
| ohos.intl | constructor()<SUP>8+</SUP> | 创建数字格式化对象。 | | ohos.intl | constructor()<SUP>8+</SUP> | 创建数字格式化对象。 |
| ohos.intl | constructor(locale:&nbsp;string&nbsp;\|&nbsp;Array&lt;string&gt;,&nbsp;options?:&nbsp;NumberOptions) | 创建数字格式化对象,并设置提供的locale和格式化相关属性。 | | ohos.intl | constructor(locale:string\|Array&lt;string&gt;,options?:NumberOptions) | 创建数字格式化对象,并设置提供的locale和格式化相关属性。 |
| ohos.intl | format(number:&nbsp;number):&nbsp;string | 依据NumberFormat对象的Locale及其他格式化属性,计算数字的格式化表示。 | | ohos.intl | format(number:number):string | 依据NumberFormat对象的Locale及其他格式化属性,计算数字的格式化表示。 |
| ohos.intl | resolvedOptions():&nbsp;NumberOptions | 获取NumberFormat对象的相关属性。 | | ohos.intl | resolvedOptions():NumberOptions | 获取NumberFormat对象的相关属性。 |
### 开发步骤 ### 开发步骤
1. 实例化数字格式化对象 1. 实例化数字格式化对象。
一种方法是使用NumberFormat提供的默认构造函数,通过访问系统的语言和地区以获取系统默认Locale并进行设置(intl为导入的模块名)。 一种方法是使用NumberFormat提供的默认构造函数,通过访问系统的语言和地区以获取系统默认Locale并进行设置(intl为导入的模块名)。
...@@ -143,7 +151,8 @@ Intl开发指导提供了ECMA 402中定义的国际化能力接口的使用方 ...@@ -143,7 +151,8 @@ Intl开发指导提供了ECMA 402中定义的国际化能力接口的使用方
var numberFormat = new intl.NumberFormat("zh-CN", options); var numberFormat = new intl.NumberFormat("zh-CN", options);
``` ```
2. 数字格式化 2. 数字格式化。
使用NumberFormat的format方法对传入的数字进行格式化。该方法返回一个字符串作为格式化的结果。 使用NumberFormat的format方法对传入的数字进行格式化。该方法返回一个字符串作为格式化的结果。
``` ```
...@@ -151,7 +160,8 @@ Intl开发指导提供了ECMA 402中定义的国际化能力接口的使用方 ...@@ -151,7 +160,8 @@ Intl开发指导提供了ECMA 402中定义的国际化能力接口的使用方
var formatResult = numberFormat.format(number); var formatResult = numberFormat.format(number);
``` ```
3. 访问数字格式化对象的相关属性 3. 访问数字格式化对象的相关属性。
NumberFormat的resolvedOptions方法会返回一个对象,该对象包含了NumberFormat对象的所有相关属性及其值。 NumberFormat的resolvedOptions方法会返回一个对象,该对象包含了NumberFormat对象的所有相关属性及其值。
``` ```
...@@ -167,16 +177,17 @@ Intl开发指导提供了ECMA 402中定义的国际化能力接口的使用方 ...@@ -167,16 +177,17 @@ Intl开发指导提供了ECMA 402中定义的国际化能力接口的使用方
### 接口说明 ### 接口说明
| 模块 | 接口名称 | 描述 | | 模块 | 接口名称 | 描述 |
| --------- | ---------------------------------------- | ------------------------------- | | -------- | -------- | -------- |
| ohos.intl | constructor()<sup>8+</sup> | 创建排序对象。 | | ohos.intl | constructor()<sup>8+</sup> | 创建排序对象。 |
| ohos.intl | constructor(locale:&nbsp;string&nbsp;\|&nbsp;Array&lt;string&gt;,&nbsp;options?:&nbsp;CollatorOptions)<sup>8+</sup> | 创建排序对象,并设置提供的locale和其他相关属性。 | | ohos.intl | constructor(locale:string\|Array&lt;string&gt;,options?:CollatorOptions)<sup>8+</sup> | 创建排序对象,并设置提供的locale和其他相关属性。 |
| ohos.intl | compare(first:&nbsp;string,&nbsp;second:&nbsp;string):&nbsp;number<sup>8+</sup> | 依据排序对象的Locale及其属性,计算两个字符串的比较结果。 | | ohos.intl | compare(first:string,second:string):number<sup>8+</sup> | 依据排序对象的Locale及其属性,计算两个字符串的比较结果。 |
| ohos.intl | resolvedOptions():&nbsp;CollatorOptions<sup>8+</sup> | 获取排序对象的相关属性。 | | ohos.intl | resolvedOptions():CollatorOptions<sup>8+</sup> | 获取排序对象的相关属性。 |
### 开发步骤 ### 开发步骤
1. 实例化排序对象 1. 实例化排序对象。
一种方法是使用Collator提供的默认构造函数,通过访问系统的语言和地区以获取系统默认Locale并进行设置(intl为导入的模块名)。 一种方法是使用Collator提供的默认构造函数,通过访问系统的语言和地区以获取系统默认Locale并进行设置(intl为导入的模块名)。
...@@ -190,7 +201,8 @@ Intl开发指导提供了ECMA 402中定义的国际化能力接口的使用方 ...@@ -190,7 +201,8 @@ Intl开发指导提供了ECMA 402中定义的国际化能力接口的使用方
var collator= new intl.Collator("zh-CN", {localeMatcher: "best fit", usage: "sort"}; var collator= new intl.Collator("zh-CN", {localeMatcher: "best fit", usage: "sort"};
``` ```
2. 比较字符串 2. 比较字符串。
使用Collator的compare方法对传入的两个字符串进行比较。该方法返回一个数值作为比较的结果,返回-1表示第一个字符串小于第二个字符串,返回1表示第一个字符大于第二个字符串,返回0表示两个字符串相同。 使用Collator的compare方法对传入的两个字符串进行比较。该方法返回一个数值作为比较的结果,返回-1表示第一个字符串小于第二个字符串,返回1表示第一个字符大于第二个字符串,返回0表示两个字符串相同。
``` ```
...@@ -199,7 +211,8 @@ Intl开发指导提供了ECMA 402中定义的国际化能力接口的使用方 ...@@ -199,7 +211,8 @@ Intl开发指导提供了ECMA 402中定义的国际化能力接口的使用方
var compareResult = collator.compare(str1, str2); var compareResult = collator.compare(str1, str2);
``` ```
3. 访问排序对象的相关属性 3. 访问排序对象的相关属性。
Collator的resolvedOptions方法会返回一个对象,该对象包含了Collator对象的所有相关属性及其值。 Collator的resolvedOptions方法会返回一个对象,该对象包含了Collator对象的所有相关属性及其值。
``` ```
...@@ -215,15 +228,16 @@ Intl开发指导提供了ECMA 402中定义的国际化能力接口的使用方 ...@@ -215,15 +228,16 @@ Intl开发指导提供了ECMA 402中定义的国际化能力接口的使用方
### 接口说明 ### 接口说明
| 模块 | 接口名称 | 描述 | | 模块 | 接口名称 | 描述 |
| --------- | ---------------------------------------- | ---------------------------------- | | -------- | -------- | -------- |
| ohos.intl | constructor()<sup>8+</sup> | 创建单复数对象。 | | ohos.intl | constructor()<sup>8+</sup> | 创建单复数对象。 |
| ohos.intl | constructor(locale:&nbsp;string&nbsp;\|&nbsp;Array&lt;string&gt;,&nbsp;options?:&nbsp;PluralRulesOptions)<sup>8+</sup> | 创建单复数对象,并设置提供的locale和其他相关属性。 | | ohos.intl | constructor(locale:string\|Array&lt;string&gt;,options?:PluralRulesOptions)<sup>8+</sup> | 创建单复数对象,并设置提供的locale和其他相关属性。 |
| ohos.intl | select(n:&nbsp;number):&nbsp;string<sup>8+</sup> | 依据单复数对象的Locale及其他格式化属性,计算数字的单复数类别。 | | ohos.intl | select(n:number):string<sup>8+</sup> | 依据单复数对象的Locale及其他格式化属性,计算数字的单复数类别。 |
### 开发步骤 ### 开发步骤
1. 实例化单复数对象 1. 实例化单复数对象。
一种方法是使用PluralRules提供的默认构造函数,通过访问系统的语言和地区以获取系统默认Locale并进行设置(intl为导入的模块名)。 一种方法是使用PluralRules提供的默认构造函数,通过访问系统的语言和地区以获取系统默认Locale并进行设置(intl为导入的模块名)。
...@@ -231,13 +245,14 @@ Intl开发指导提供了ECMA 402中定义的国际化能力接口的使用方 ...@@ -231,13 +245,14 @@ Intl开发指导提供了ECMA 402中定义的国际化能力接口的使用方
var pluralRules = new intl.PluralRules(); var pluralRules = new intl.PluralRules();
``` ```
另一种方法是使用开发者提供的Locale和其他相关参数来创建单复数对象完整的参数列表参见[PluralRulesOptions](../reference/apis/js-apis-intl.md)。 另一种方法是使用开发者提供的Locale和其他相关参数来创建单复数对象完整的参数列表参见[PluralRulesOptions](../reference/apis/js-apis-intl.md)。
``` ```
var plurals = new intl.PluralRules("zh-CN", {localeMatcher: "best fit", type: "cardinal"}; var plurals = new intl.PluralRules("zh-CN", {localeMatcher: "best fit", type: "cardinal"};
``` ```
2. 计算数字单复数类别 2. 计算数字单复数类别。
使用PluralRules的select方法计算传入数字的单复数类别。该方法返回一个字符串作为传入数字的类别,包括:"zero", "one", "two", "few", "many", "other"六个类别。 使用PluralRules的select方法计算传入数字的单复数类别。该方法返回一个字符串作为传入数字的类别,包括:"zero", "one", "two", "few", "many", "other"六个类别。
``` ```
...@@ -254,17 +269,18 @@ Intl开发指导提供了ECMA 402中定义的国际化能力接口的使用方 ...@@ -254,17 +269,18 @@ Intl开发指导提供了ECMA 402中定义的国际化能力接口的使用方
### 接口说明 ### 接口说明
| 模块 | 接口名称 | 描述 | | 模块 | 接口名称 | 描述 |
| --------- | ---------------------------------------- | ---------------------------------------- | | -------- | -------- | -------- |
| ohos.intl | constructor()<sup>8+</sup> | 创建相对时间格式化对象。 | | ohos.intl | constructor()<sup>8+</sup> | 创建相对时间格式化对象。 |
| ohos.intl | constructor(locale:&nbsp;string&nbsp;\|&nbsp;Array&lt;string&gt;,&nbsp;options?:&nbsp;RelativeTimeFormatInputOptions)<sup>8+</sup> | 创建相对时间格式化对象,并设置提供的locale和格式化相关属性。 | | ohos.intl | constructor(locale:string\|Array&lt;string&gt;,options?:RelativeTimeFormatInputOptions)<sup>8+</sup> | 创建相对时间格式化对象,并设置提供的locale和格式化相关属性。 |
| ohos.intl | format(value:&nbsp;number,&nbsp;unit:&nbsp;string):&nbsp;string<sup>8+</sup> | 依据相对时间格式化对象的Locale及其他格式化属性,计算相对时间的格式化表示。 | | ohos.intl | format(value:number,unit:string):string<sup>8+</sup> | 依据相对时间格式化对象的Locale及其他格式化属性,计算相对时间的格式化表示。 |
| ohos.intl | formatToParts(value:&nbsp;number,&nbsp;unit:&nbsp;string):&nbsp;Array&lt;object&gt;<sup>8+</sup> | 依据相对时间格式化对象的Locale及其他格式化属性,返回相对时间格式化表示的各个部分。 | | ohos.intl | formatToParts(value:number,unit:string):Array&lt;object&gt;<sup>8+</sup> | 依据相对时间格式化对象的Locale及其他格式化属性,返回相对时间格式化表示的各个部分。 |
| ohos.intl | resolvedOptions():&nbsp;RelativeTimeFormatResolvedOptions<sup>8+</sup> | 获取相对时间格式化对象的相关属性。 | | ohos.intl | resolvedOptions():RelativeTimeFormatResolvedOptions<sup>8+</sup> | 获取相对时间格式化对象的相关属性。 |
### 开发步骤 ### 开发步骤
1. 实例化相对时间格式化对象 1. 实例化相对时间格式化对象。
一种方法是使用RelativeTimeFormat提供的默认构造函数,通过访问系统的语言和地区以获取系统默认Locale并进行设置(intl为导入的模块名)。 一种方法是使用RelativeTimeFormat提供的默认构造函数,通过访问系统的语言和地区以获取系统默认Locale并进行设置(intl为导入的模块名)。
...@@ -278,7 +294,8 @@ Intl开发指导提供了ECMA 402中定义的国际化能力接口的使用方 ...@@ -278,7 +294,8 @@ Intl开发指导提供了ECMA 402中定义的国际化能力接口的使用方
var relativeTimeFormat = new intl.RelativeTimeFormat("zh-CN", {numeric: "always", style: "long"}; var relativeTimeFormat = new intl.RelativeTimeFormat("zh-CN", {numeric: "always", style: "long"};
``` ```
2. 相对时间格式化 2. 相对时间格式化。
使用RelativeTimeFormat的format方法对相对时间进行格式化。方法接收一个表示相对时间长度的数值和表示单位的字符串,其中单位包括:"year", "quarter", "month", "week", "day", "hour", "minute", "second"。方法返回一个字符串作为格式化的结果。 使用RelativeTimeFormat的format方法对相对时间进行格式化。方法接收一个表示相对时间长度的数值和表示单位的字符串,其中单位包括:"year", "quarter", "month", "week", "day", "hour", "minute", "second"。方法返回一个字符串作为格式化的结果。
``` ```
...@@ -287,7 +304,8 @@ Intl开发指导提供了ECMA 402中定义的国际化能力接口的使用方 ...@@ -287,7 +304,8 @@ Intl开发指导提供了ECMA 402中定义的国际化能力接口的使用方
var formatResult = relativeTimeFormat.format(number, unit); var formatResult = relativeTimeFormat.format(number, unit);
``` ```
3. 获取相对时间格式化结果的各个部分 3. 获取相对时间格式化结果的各个部分。
获取相对时间格式化结果的各个部分,从而自定义格式化结果。 获取相对时间格式化结果的各个部分,从而自定义格式化结果。
``` ```
...@@ -296,7 +314,8 @@ Intl开发指导提供了ECMA 402中定义的国际化能力接口的使用方 ...@@ -296,7 +314,8 @@ Intl开发指导提供了ECMA 402中定义的国际化能力接口的使用方
var formatResult = relativeTimeFormat.formatToParts(number, unit); var formatResult = relativeTimeFormat.formatToParts(number, unit);
``` ```
4. 访问相对时间格式化对象的相关属性 4. 访问相对时间格式化对象的相关属性。
RelativeTimeFormat的resolvedOptions方法会返回一个对象,该对象包含了RelativeTimeFormat对象的所有相关属性及其值,完整的属性列表参见[ RelativeTimeFormatResolvedOptions](../reference/apis/js-apis-intl.md)。 RelativeTimeFormat的resolvedOptions方法会返回一个对象,该对象包含了RelativeTimeFormat对象的所有相关属性及其值,完整的属性列表参见[ RelativeTimeFormatResolvedOptions](../reference/apis/js-apis-intl.md)。
``` ```
......
...@@ -20,7 +20,7 @@ resources ...@@ -20,7 +20,7 @@ resources
| | |---string.json | | |---string.json
| |---media | |---media
| | |---icon.png | | |---icon.png
|---rawfile // 默认存在的目录 |---rawfile
``` ```
**表1** resources目录分类 **表1** resources目录分类
......
...@@ -18,7 +18,7 @@ ...@@ -18,7 +18,7 @@
**系统能力**:以下各项对应的系统能力均为SystemCapability.Ability.AbilityRuntime.Core **系统能力**:以下各项对应的系统能力均为SystemCapability.Ability.AbilityRuntime.Core
| 名称 | 参数类型 | 可读 | 可写 | 说明 | | 名称 | 参数类型 | 可读 | 可写 | 说明 |
| -------- | -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- | -------- |
| resourceManager | ResourceManager | 是 | 否 | ResourceManager对象。 | | resourceManager | ResourceManager | 是 | 否 | ResourceManager对象。 |
| applicationInfo | ApplicationInfo | 是 | 否 | 当前应用信息。 | | applicationInfo | ApplicationInfo | 是 | 否 | 当前应用信息。 |
...@@ -42,15 +42,15 @@ createBundleContext(bundleName: string): Context; ...@@ -42,15 +42,15 @@ createBundleContext(bundleName: string): Context;
**参数:** **参数:**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| bundleName | string | 是 | 应用bundle名。 | | bundleName | string | 是 | 应用bundle名。 |
**返回值:** **返回值:**
| 类型 | 说明 | | 类型 | 说明 |
| -------- | -------- | | -------- | -------- |
| Context | 对应创建应用的上下文context。 | | Context | 对应创建应用的上下文context。 |
**示例:** **示例:**
...@@ -70,13 +70,51 @@ getApplicationContext(): Context; ...@@ -70,13 +70,51 @@ getApplicationContext(): Context;
**返回值:** **返回值:**
| 类型 | 说明 | | 类型 | 说明 |
| -------- | -------- | | -------- | -------- |
| Context | 当前Context&nbsp;信息。 | | Context | 当前Context&nbsp;信息。 |
**示例:** **示例:**
```js ```js
// 必选项。 // 必选项。
let context = this.context.getApplicationContext(); let context = this.context.getApplicationContext();
``` ```
> **说明:**
> 当SDK :API 9版本为Canary版本时;
## Context.switchArea
switchArea(mode: AreaMode): void
开启文件范围
**系统能力**:SystemCapability.Ability.AbilityRuntime.Core
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| ------ | --------------------- | ---- | -------------- |
| mode | [AreaMode](#AreaMode) | 是 | 应用bundle名。 |
**示例**
```js
var areaMode = 0
this.context.switchArea(areaMode);
```
## AreaMode
文件范围模式
**系统能力**:SystemCapability.Ability.AbilityRuntime.Core
| 名称 | 参数类型 | 值 |
| ---- | -------- | ---- |
| EL1 | number | 0 |
| EL2 | number | 1 |
\ No newline at end of file
# Context
> ![icon-note.gif](public_sys-resources/icon-note.gif) **说明**
>
> 本模块首批接口从API version 9开始支持。API 9当前为Canary版本,仅供使用,不保证接口可稳定调用。
提供开发者运行代码的上下文环境,包括应用信息、ResourceManager等信息。
## 使用说明
通过AbilityContext等继承实现。
## 属性
**系统能力**:以下各项对应的系统能力均为SystemCapability.Ability.AbilityRuntime.Core
| 名称 | 参数类型 | 可读 | 可写 | 说明 |
| -------- | -------- | -------- | -------- | -------- |
| resourceManager | ResourceManager | 是 | 否 | ResourceManager对象。 |
| applicationInfo | ApplicationInfo | 是 | 否 | 当前应用信息。 |
| cacheDir | string | 是 | 否 | 应用在内部存储上的缓存路径。 |
| tempDir | string | 是 | 否 | 应用的临时文件路径。 |
| filesDir | string | 是 | 否 | 应用在内部存储上的文件路径。 |
| databaseDir | string | 是 | 否 | 获取本地数据存储路径。 |
| storageDir | string | 是 | 否 | 获取轻量级数据存储路径。 |
| bundleCodeDir | string | 是 | 否 | 应用安装路径。 |
| distributedFilesDir | string | 是 | 否 | 应用的分布式文件路径。 |
| eventHub | [EventHub](js-apis-eventhub.md) | 是 | 否 | 事件中心信息。|
## Context.createBundleContext
createBundleContext(bundleName: string): Context;
创建指定应用上下文。
**系统能力**:SystemCapability.Ability.AbilityRuntime.Core
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| bundleName | string | 是 | 应用bundle名。 |
**返回值:**
| 类型 | 说明 |
| -------- | -------- |
| Context | 对应创建应用的上下文context。 |
**示例:**
```js
let test = "com.example.test";
let context = this.context.createBundleContext(test);
```
## Context.getApplicationContext
getApplicationContext(): Context;
获取当前context。
**系统能力**:SystemCapability.Ability.AbilityRuntime.Core
**返回值:**
| 类型 | 说明 |
| -------- | -------- |
| Context | 当前Context&nbsp;信息。 |
**示例:**
```js
// 必选项。
let context = this.context.getApplicationContext();
```
## Context.switchArea
switchArea(mode: AreaMode): void
开启文件范围
**系统能力**:SystemCapability.Ability.AbilityRuntime.Core
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| mode | [AreaMode](#AreaMode) | 是 | 应用bundle名。 |
**示例**
```js
var areaMode = 0
this.context.switchArea(areaMode);
```
## AreaMode
文件范围模式
**系统能力**:SystemCapability.Ability.AbilityRuntime.Core
| 名称 | 参数类型 | 值 |
| -------- | -------- | -------- |
| EL1 | number | 0 |
| EL2 | number | 1 |
\ No newline at end of file
# 配置策略 # 配置策略
配置策略提供按预先定义的定制配置层级获取对应定制配置目录和文件路径的能力。
> **说明:** > **说明:**
> >
> 本模块首批接口从API version 8开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。 > 本模块首批接口从API version 8开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。
> >
> 本模块接口均为系统接口,三方应用不支持调用。 > 本模块接口均为系统接口,三方应用不支持调用。
配置策略提供按预先定义的定制配置层级获取对应定制配置目录和文件路径的能力。
## 导入模块 ## 导入模块
```js ```js
...@@ -16,10 +16,10 @@ import configPolicy from '@ohos.configPolicy'; ...@@ -16,10 +16,10 @@ import configPolicy from '@ohos.configPolicy';
## getOneCfgFile ## getOneCfgFile
getOneCfgFile(relPath: string, callback: AsyncCallback&lt;string&gt;): void getOneCfgFile(relPath: string, callback: AsyncCallback&lt;string&gt;)
使用callback形式返回指定文件名的最高优先级配置文件路径。 使用callback形式返回指定文件名的最高优先级配置文件路径。
例如,config.xml在设备中存在以下路径(优先级从低到高):/system/etc/config.xml、/sys-pod/etc/config.xml,最终返回/sys-pod/etc/config.xml。 例如,config.xml在设备中存在以下路径(优先级从低到高):/system/etc/config.xml、/sys_pod/etc/config.xml,最终返回/sys_pod/etc/config.xml。
**系统能力**:SystemCapability.Customization.ConfigPolicy **系统能力**:SystemCapability.Customization.ConfigPolicy
...@@ -31,7 +31,7 @@ getOneCfgFile(relPath: string, callback: AsyncCallback&lt;string&gt;): void ...@@ -31,7 +31,7 @@ getOneCfgFile(relPath: string, callback: AsyncCallback&lt;string&gt;): void
**示例:** **示例:**
```js ```js
configPolicy.getOneCfgFile('config.xml', (error, value) => { configPolicy.getOneCfgFile('etc/config.xml', (error, value) => {
if (error == undefined) { if (error == undefined) {
console.log("value is " + value); console.log("value is " + value);
} else { } else {
...@@ -61,7 +61,7 @@ getOneCfgFile(relPath: string): Promise&lt;string&gt; ...@@ -61,7 +61,7 @@ getOneCfgFile(relPath: string): Promise&lt;string&gt;
**示例:** **示例:**
```js ```js
configPolicy.getOneCfgFile('config.xml').then(value => { configPolicy.getOneCfgFile('etc/config.xml').then(value => {
console.log("value is " + value); console.log("value is " + value);
}).catch(error => { }).catch(error => {
console.log("getOneCfgFile promise " + error); console.log("getOneCfgFile promise " + error);
...@@ -71,10 +71,10 @@ getOneCfgFile(relPath: string): Promise&lt;string&gt; ...@@ -71,10 +71,10 @@ getOneCfgFile(relPath: string): Promise&lt;string&gt;
## getCfgFiles ## getCfgFiles
getCfgFiles(relPath: string, callback: AsyncCallback&lt;Array&lt;string&gt;&gt;): void getCfgFiles(relPath: string, callback: AsyncCallback&lt;Array&lt;string&gt;&gt;)
按优先级从低到高,使用callback形式返回指定文件名所有的文件列表。例如,config.xml在设备中存在以下路径(优先级从低到高):/system/etc/config.xml、 按优先级从低到高,使用callback形式返回指定文件名所有的文件列表。例如,config.xml在设备中存在以下路径(优先级从低到高):/system/etc/config.xml、
/sys-pod/etc/config.xml,最终返回/system/etc/config.xml, /sys-pod/etc/config.xml。 /sys_pod/etc/config.xml,最终返回/system/etc/config.xml, /sys_pod/etc/config.xml。
**系统能力**:SystemCapability.Customization.ConfigPolicy **系统能力**:SystemCapability.Customization.ConfigPolicy
...@@ -86,7 +86,7 @@ getCfgFiles(relPath: string, callback: AsyncCallback&lt;Array&lt;string&gt;&gt;) ...@@ -86,7 +86,7 @@ getCfgFiles(relPath: string, callback: AsyncCallback&lt;Array&lt;string&gt;&gt;)
**示例:** **示例:**
```js ```js
configPolicy.getCfgFiles('config.xml', (error, value) => { configPolicy.getCfgFiles('etc/config.xml', (error, value) => {
if (error == undefined) { if (error == undefined) {
console.log("value is " + value); console.log("value is " + value);
} else { } else {
...@@ -116,7 +116,7 @@ getCfgFiles(relPath: string): Promise&lt;Array&lt;string&gt;&gt; ...@@ -116,7 +116,7 @@ getCfgFiles(relPath: string): Promise&lt;Array&lt;string&gt;&gt;
**示例:** **示例:**
```js ```js
configPolicy.getCfgFiles('config.xml').then(value => { configPolicy.getCfgFiles('etc/config.xml').then(value => {
console.log("value is " + value); console.log("value is " + value);
}).catch(error => { }).catch(error => {
console.log("getCfgFiles promise " + error); console.log("getCfgFiles promise " + error);
...@@ -126,7 +126,7 @@ getCfgFiles(relPath: string): Promise&lt;Array&lt;string&gt;&gt; ...@@ -126,7 +126,7 @@ getCfgFiles(relPath: string): Promise&lt;Array&lt;string&gt;&gt;
## getCfgDirList ## getCfgDirList
getCfgDirList(callback: AsyncCallback&lt;Array&lt;string&gt;&gt;): void getCfgDirList(callback: AsyncCallback&lt;Array&lt;string&gt;&gt;)
使用callback形式返回配置层级目录列表。 使用callback形式返回配置层级目录列表。
......
...@@ -46,10 +46,10 @@ isIdleState(bundleName: string, callback: AsyncCallback&lt;boolean&gt;): void ...@@ -46,10 +46,10 @@ isIdleState(bundleName: string, callback: AsyncCallback&lt;boolean&gt;): void
``` ```
bundleState.isIdleState("com.ohos.camera", (err, res) => { bundleState.isIdleState("com.ohos.camera", (err, res) => {
if(err.code === 0) { if (err) {
console.log('BUNDLE_ACTIVE isIdleState callback succeeded, result: ' + JSON.stringify(res));
} else {
console.log('BUNDLE_ACTIVE isIdleState callback failed, because: ' + err.code); console.log('BUNDLE_ACTIVE isIdleState callback failed, because: ' + err.code);
} else {
console.log('BUNDLE_ACTIVE isIdleState callback succeeded, result: ' + JSON.stringify(res));
} }
}); });
``` ```
...@@ -77,9 +77,9 @@ isIdleState(bundleName: string): Promise&lt;boolean&gt; ...@@ -77,9 +77,9 @@ isIdleState(bundleName: string): Promise&lt;boolean&gt;
**示例** **示例**
``` ```
bundleState.isIdleState("com.ohos.camera").then( res => { bundleState.isIdleState("com.ohos.camera").then(res => {
console.log('BUNDLE_ACTIVE isIdleState promise succeeded, result: ' + JSON.stringify(res)); console.log('BUNDLE_ACTIVE isIdleState promise succeeded, result: ' + JSON.stringify(res));
}).catch( err => { }).catch(err => {
console.log('BUNDLE_ACTIVE isIdleState promise failed, because: ' + err.code); console.log('BUNDLE_ACTIVE isIdleState promise failed, because: ' + err.code);
}); });
``` ```
...@@ -102,10 +102,10 @@ queryAppUsagePriorityGroup(callback: AsyncCallback&lt;number&gt;): void ...@@ -102,10 +102,10 @@ queryAppUsagePriorityGroup(callback: AsyncCallback&lt;number&gt;): void
``` ```
bundleState.queryAppUsagePriorityGroup((err, res) => { bundleState.queryAppUsagePriorityGroup((err, res) => {
if(err.code === 0) { if (err) {
console.log('BUNDLE_ACTIVE queryAppUsagePriorityGroup callback succeeded. result: ' + JSON.stringify(res));
} else {
console.log('BUNDLE_ACTIVE queryAppUsagePriorityGroup callback failed. because: ' + err.code); console.log('BUNDLE_ACTIVE queryAppUsagePriorityGroup callback failed. because: ' + err.code);
} else {
console.log('BUNDLE_ACTIVE queryAppUsagePriorityGroup callback succeeded. result: ' + JSON.stringify(res));
} }
}); });
``` ```
...@@ -127,9 +127,9 @@ queryAppUsagePriorityGroup(): Promise&lt;number&gt; ...@@ -127,9 +127,9 @@ queryAppUsagePriorityGroup(): Promise&lt;number&gt;
**示例** **示例**
``` ```
bundleState.queryAppUsagePriorityGroup().then( res => { bundleState.queryAppUsagePriorityGroup().then(res => {
console.log('BUNDLE_ACTIVE queryAppUsagePriorityGroup promise succeeded. result: ' + JSON.stringify(res)); console.log('BUNDLE_ACTIVE queryAppUsagePriorityGroup promise succeeded. result: ' + JSON.stringify(res));
}).catch( err => { }).catch(err => {
console.log('BUNDLE_ACTIVE queryAppUsagePriorityGroup promise failed. because: ' + err.code); console.log('BUNDLE_ACTIVE queryAppUsagePriorityGroup promise failed. because: ' + err.code);
}); });
``` ```
...@@ -158,16 +158,16 @@ queryBundleStateInfos(begin: number, end: number, callback: AsyncCallback&lt;Bun ...@@ -158,16 +158,16 @@ queryBundleStateInfos(begin: number, end: number, callback: AsyncCallback&lt;Bun
``` ```
bundleState.queryBundleStateInfos(0, 20000000000000, (err, res) => { bundleState.queryBundleStateInfos(0, 20000000000000, (err, res) => {
if(err.code == 0) { if (err) {
console.log('BUNDLE_ACTIVE queryBundleStateInfos callback failed, because: ' + err.code);
} else {
console.log('BUNDLE_ACTIVE queryBundleStateInfos callback success.'); console.log('BUNDLE_ACTIVE queryBundleStateInfos callback success.');
let i = 1; let i = 1;
for(let key in res){ for (let key in res) {
console.log('BUNDLE_ACTIVE queryBundleStateInfos callback number : ' + i); console.log('BUNDLE_ACTIVE queryBundleStateInfos callback number : ' + i);
console.log('BUNDLE_ACTIVE queryBundleStateInfos callback result ' + JSON.stringify(res[key])); console.log('BUNDLE_ACTIVE queryBundleStateInfos callback result ' + JSON.stringify(res[key]));
i++; i++;
} }
} else {
console.log('BUNDLE_ACTIVE queryBundleStateInfos callback failed, because: ' + err.code);
} }
}); });
``` ```
...@@ -200,15 +200,15 @@ queryBundleStateInfos(begin: number, end: number): Promise&lt;BundleActiveInfoRe ...@@ -200,15 +200,15 @@ queryBundleStateInfos(begin: number, end: number): Promise&lt;BundleActiveInfoRe
**示例** **示例**
``` ```
bundleState.queryBundleStateInfos(0, 20000000000000).then( res => { bundleState.queryBundleStateInfos(0, 20000000000000).then(res => {
console.log('BUNDLE_ACTIVE queryBundleStateInfos promise success.'); console.log('BUNDLE_ACTIVE queryBundleStateInfos promise success.');
let i = 1; let i = 1;
for(let key in res){ for (let key in res) {
console.log('BUNDLE_ACTIVE queryBundleStateInfos promise number : ' + i); console.log('BUNDLE_ACTIVE queryBundleStateInfos promise number : ' + i);
console.log('BUNDLE_ACTIVE queryBundleStateInfos promise result ' + JSON.stringify(res[key])); console.log('BUNDLE_ACTIVE queryBundleStateInfos promise result ' + JSON.stringify(res[key]));
i++; i++;
} }
}).catch( err => { }).catch(err => {
console.log('BUNDLE_ACTIVE queryBundleStateInfos promise failed, because: ' + err.code); console.log('BUNDLE_ACTIVE queryBundleStateInfos promise failed, because: ' + err.code);
}); });
``` ```
...@@ -238,14 +238,14 @@ queryBundleStateInfoByInterval(byInterval: IntervalType, begin: number, end: num ...@@ -238,14 +238,14 @@ queryBundleStateInfoByInterval(byInterval: IntervalType, begin: number, end: num
``` ```
bundleState.queryBundleStateInfoByInterval(0, 0, 20000000000000, (err, res) => { bundleState.queryBundleStateInfoByInterval(0, 0, 20000000000000, (err, res) => {
if(err.code == 0) { if (err) {
console.log('BUNDLE_ACTIVE queryBundleStateInfoByInterval callback failed, because: ' + err.code);
} else {
console.log('BUNDLE_ACTIVE queryBundleStateInfoByInterval callback success.'); console.log('BUNDLE_ACTIVE queryBundleStateInfoByInterval callback success.');
for (let i = 0; i < res.length; i++) { for (let i = 0; i < res.length; i++) {
console.log('BUNDLE_ACTIVE queryBundleStateInfoByInterval callback number : ' + (i + 1)); console.log('BUNDLE_ACTIVE queryBundleStateInfoByInterval callback number : ' + (i + 1));
console.log('BUNDLE_ACTIVE queryBundleStateInfoByInterval callback result ' + JSON.stringify(res[i])); console.log('BUNDLE_ACTIVE queryBundleStateInfoByInterval callback result ' + JSON.stringify(res[i]));
} }
} else {
console.log('BUNDLE_ACTIVE queryBundleStateInfoByInterval callback failed, because: ' + err.code);
} }
}); });
``` ```
...@@ -279,13 +279,13 @@ queryBundleStateInfoByInterval(byInterval: IntervalType, begin: number, end: num ...@@ -279,13 +279,13 @@ queryBundleStateInfoByInterval(byInterval: IntervalType, begin: number, end: num
**示例** **示例**
``` ```
bundleState.queryBundleStateInfoByInterval(0, 0, 20000000000000).then( res => { bundleState.queryBundleStateInfoByInterval(0, 0, 20000000000000).then(res => {
console.log('BUNDLE_ACTIVE queryBundleStateInfoByInterval promise success.'); console.log('BUNDLE_ACTIVE queryBundleStateInfoByInterval promise success.');
for (let i = 0; i < res.length; i++) { for (let i = 0; i < res.length; i++) {
console.log('BUNDLE_ACTIVE queryBundleStateInfoByInterval promise number : ' + (i + 1)); console.log('BUNDLE_ACTIVE queryBundleStateInfoByInterval promise number : ' + (i + 1));
console.log('BUNDLE_ACTIVE queryBundleStateInfoByInterval promise result ' + JSON.stringify(res[i])); console.log('BUNDLE_ACTIVE queryBundleStateInfoByInterval promise result ' + JSON.stringify(res[i]));
} }
}).catch( err => { }).catch(err => {
console.log('BUNDLE_ACTIVE queryBundleStateInfoByInterval promise failed, because: ' + err.code); console.log('BUNDLE_ACTIVE queryBundleStateInfoByInterval promise failed, because: ' + err.code);
}); });
``` ```
...@@ -314,14 +314,14 @@ queryBundleActiveStates(begin: number, end: number, callback: AsyncCallback&lt;A ...@@ -314,14 +314,14 @@ queryBundleActiveStates(begin: number, end: number, callback: AsyncCallback&lt;A
``` ```
bundleState.queryBundleActiveStates(0, 20000000000000, (err, res) => { bundleState.queryBundleActiveStates(0, 20000000000000, (err, res) => {
if(err.code == 0) { if (err) {
console.log('BUNDLE_ACTIVE queryBundleActiveStates callback failed, because: ' + err.code);
} else {
console.log('BUNDLE_ACTIVE queryBundleActiveStates callback success.'); console.log('BUNDLE_ACTIVE queryBundleActiveStates callback success.');
for (let i = 0; i < res.length; i++) { for (let i = 0; i < res.length; i++) {
console.log('BUNDLE_ACTIVE queryBundleActiveStates callback number : ' + (i + 1)); console.log('BUNDLE_ACTIVE queryBundleActiveStates callback number : ' + (i + 1));
console.log('BUNDLE_ACTIVE queryBundleActiveStates callback result ' + JSON.stringify(res[i])); console.log('BUNDLE_ACTIVE queryBundleActiveStates callback result ' + JSON.stringify(res[i]));
} }
} else {
console.log('BUNDLE_ACTIVE queryBundleActiveStates callback failed, because: ' + err.code);
} }
}); });
``` ```
...@@ -354,13 +354,13 @@ queryBundleActiveStates(begin: number, end: number): Promise&lt;Array&lt;BundleA ...@@ -354,13 +354,13 @@ queryBundleActiveStates(begin: number, end: number): Promise&lt;Array&lt;BundleA
**示例** **示例**
``` ```
bundleState.queryBundleActiveStates(0, 20000000000000).then( res => { bundleState.queryBundleActiveStates(0, 20000000000000).then(res => {
console.log('BUNDLE_ACTIVE queryBundleActiveStates promise success.'); console.log('BUNDLE_ACTIVE queryBundleActiveStates promise success.');
for (let i = 0; i < res.length; i++) { for (let i = 0; i < res.length; i++) {
console.log('BUNDLE_ACTIVE queryBundleActiveStates promise number : ' + (i + 1)); console.log('BUNDLE_ACTIVE queryBundleActiveStates promise number : ' + (i + 1));
console.log('BUNDLE_ACTIVE queryBundleActiveStates promise result ' + JSON.stringify(res[i])); console.log('BUNDLE_ACTIVE queryBundleActiveStates promise result ' + JSON.stringify(res[i]));
} }
}).catch( err => { }).catch(err => {
console.log('BUNDLE_ACTIVE queryBundleActiveStates promise failed, because: ' + err.code); console.log('BUNDLE_ACTIVE queryBundleActiveStates promise failed, because: ' + err.code);
}); });
``` ```
...@@ -385,14 +385,14 @@ queryCurrentBundleActiveStates(begin: number, end: number, callback: AsyncCallba ...@@ -385,14 +385,14 @@ queryCurrentBundleActiveStates(begin: number, end: number, callback: AsyncCallba
``` ```
bundleState.queryCurrentBundleActiveStates(0, 20000000000000, (err, res) => { bundleState.queryCurrentBundleActiveStates(0, 20000000000000, (err, res) => {
if(err.code == 0) { if (err) {
console.log('BUNDLE_ACTIVE queryCurrentBundleActiveStates callback failed, because: ' + err.code);
} else {
console.log('BUNDLE_ACTIVE queryCurrentBundleActiveStates callback success.'); console.log('BUNDLE_ACTIVE queryCurrentBundleActiveStates callback success.');
for (let i = 0; i < res.length; i++) { for (let i = 0; i < res.length; i++) {
console.log('BUNDLE_ACTIVE queryCurrentBundleActiveStates callback number : ' + (i + 1)); console.log('BUNDLE_ACTIVE queryCurrentBundleActiveStates callback number : ' + (i + 1));
console.log('BUNDLE_ACTIVE queryCurrentBundleActiveStates callback result ' + JSON.stringify(res[i])); console.log('BUNDLE_ACTIVE queryCurrentBundleActiveStates callback result ' + JSON.stringify(res[i]));
} }
} else {
console.log('BUNDLE_ACTIVE queryCurrentBundleActiveStates callback failed, because: ' + err.code);
} }
}); });
``` ```
...@@ -421,13 +421,13 @@ queryCurrentBundleActiveStates(begin: number, end: number): Promise&lt;Array&lt; ...@@ -421,13 +421,13 @@ queryCurrentBundleActiveStates(begin: number, end: number): Promise&lt;Array&lt;
**示例** **示例**
``` ```
bundleState.queryCurrentBundleActiveStates(0, 20000000000000).then( res => { bundleState.queryCurrentBundleActiveStates(0, 20000000000000).then(res => {
console.log('BUNDLE_ACTIVE queryCurrentBundleActiveStates promise success.'); console.log('BUNDLE_ACTIVE queryCurrentBundleActiveStates promise success.');
for (let i = 0; i < res.length; i++) { for (let i = 0; i < res.length; i++) {
console.log('BUNDLE_ACTIVE queryCurrentBundleActiveStates promise number : ' + (i + 1)); console.log('BUNDLE_ACTIVE queryCurrentBundleActiveStates promise number : ' + (i + 1));
console.log('BUNDLE_ACTIVE queryCurrentBundleActiveStates promise result ' + JSON.stringify(res[i])); console.log('BUNDLE_ACTIVE queryCurrentBundleActiveStates promise result ' + JSON.stringify(res[i]));
} }
}).catch( err => { }).catch(err => {
console.log('BUNDLE_ACTIVE queryCurrentBundleActiveStates promise failed, because: ' + err.code); console.log('BUNDLE_ACTIVE queryCurrentBundleActiveStates promise failed, because: ' + err.code);
}); });
``` ```
......
...@@ -12,28 +12,28 @@ import document from '@ohos.document'; ...@@ -12,28 +12,28 @@ import document from '@ohos.document';
## document.choose ## document.choose
choose(types:string[]): Promise&lt;string&gt; choose(types? : string[]): Promise&lt;string&gt;
通过文件管理器选择文件,异步返回文件URI,使用promise形式返回结果。 通过文件管理器选择文件,异步返回文件URI,使用promise形式返回结果。
**系统能力**:SystemCapability.FileManagement.UserFileService **系统能力**:SystemCapability.FileManagement.UserFileService
- 参数: **参数:**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
| ------ | ------ | ---- | ---------------------------- | | ------ | ------ | ---- | ---------------------------- |
| types | string[] | 否 | 限定文件选择的类型 | | types | string[] | 否 | 限定文件选择的类型 |
- 返回值: **返回值:**
| 类型 | 说明 | | 类型 | 说明 |
| --------------------- | -------------- | | --------------------- | -------------- |
| Promise&lt;string&gt; | 异步返回文件URI(注:当前返回错误码) | | Promise&lt;string&gt; | 异步返回文件URI(注:当前返回错误码) |
- 示例: **示例:**
```js ```js
let tpyes = []; let types = [];
document.choose(types); document.choose(types);
``` ```
## document.choose ## document.choose
...@@ -44,13 +44,13 @@ choose(callback:AsyncCallback&lt;string&gt;): void ...@@ -44,13 +44,13 @@ choose(callback:AsyncCallback&lt;string&gt;): void
**系统能力**:SystemCapability.FileManagement.UserFileService **系统能力**:SystemCapability.FileManagement.UserFileService
- 参数: **参数:**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
| -------- | --------------------------- | ---- | ---------------------------- | | -------- | --------------------------- | ---- | ---------------------------- |
| callback | AsyncCallback&lt;string&gt; | 是 | 异步获取对应文件URI(注:当前返回错误码) | | callback | AsyncCallback&lt;string&gt; | 是 | 异步获取对应文件URI(注:当前返回错误码) |
- 示例: **示例:**
```js ```js
let uri = ""; let uri = "";
...@@ -66,14 +66,14 @@ choose(types:string[], callback:AsyncCallback&lt;string&gt;): void ...@@ -66,14 +66,14 @@ choose(types:string[], callback:AsyncCallback&lt;string&gt;): void
**系统能力**:SystemCapability.FileManagement.UserFileService **系统能力**:SystemCapability.FileManagement.UserFileService
- 参数: **参数:**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
| -------- | --------------------------- | ---- | ---------------------------- | | -------- | --------------------------- | ---- | ---------------------------- |
| types | string[] | 否 | 限定选择文件的类型 | | types | string[] | 否 | 限定选择文件的类型 |
| callback | AsyncCallback&lt;string&gt; | 是 | 异步获取对应文件URI(注:当前返回错误码) | | callback | AsyncCallback&lt;string&gt; | 是 | 异步获取对应文件URI(注:当前返回错误码) |
- 示例: **示例:**
```js ```js
let types = []; let types = [];
...@@ -91,20 +91,20 @@ show(uri:string, type:string):Promise&lt;void&gt; ...@@ -91,20 +91,20 @@ show(uri:string, type:string):Promise&lt;void&gt;
**系统能力**:SystemCapability.FileManagement.UserFileService **系统能力**:SystemCapability.FileManagement.UserFileService
- 参数: **参数:**
| 参数 | 类型 | 必填 | 说明 | | 参数 | 类型 | 必填 | 说明 |
| ---- | ------ | ---- | ---------------------------- | | ---- | ------ | ---- | ---------------------------- |
| uri | string | 是 | 待打开的文件URI | | uri | string | 是 | 待打开的文件URI |
| type | string | 是 | 待打开文件的类型 | | type | string | 是 | 待打开文件的类型 |
- 返回值: **返回值:**
| 类型 | 说明 | | 类型 | 说明 |
| --------------------- | ------------ | | --------------------- | ------------ |
| Promise&lt;void&gt; | Promise回调返回void表示成功打开文件(注:当前返回错误码) | | Promise&lt;void&gt; | Promise回调返回void表示成功打开文件(注:当前返回错误码) |
- 示例: **示例:**
```js ```js
let type = ""; let type = "";
...@@ -120,7 +120,7 @@ show(uri:string, type:string, callback:AsyncCallback&lt;void&gt;): void ...@@ -120,7 +120,7 @@ show(uri:string, type:string, callback:AsyncCallback&lt;void&gt;): void
**系统能力**:SystemCapability.FileManagement.UserFileService **系统能力**:SystemCapability.FileManagement.UserFileService
- 参数: **参数:**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
| -------- | --------------------------- | ---- | ---------------------------- | | -------- | --------------------------- | ---- | ---------------------------- |
...@@ -128,7 +128,7 @@ show(uri:string, type:string, callback:AsyncCallback&lt;void&gt;): void ...@@ -128,7 +128,7 @@ show(uri:string, type:string, callback:AsyncCallback&lt;void&gt;): void
| type | string | 是 | 待打开文件的类型 | | type | string | 是 | 待打开文件的类型 |
| callback | AsyncCallback&lt;void&gt; | 是 | 异步打开uri对应文件(注:当前返回错误码) | | callback | AsyncCallback&lt;void&gt; | 是 | 异步打开uri对应文件(注:当前返回错误码) |
- 示例: **示例:**
```js ```js
let type = ""; let type = "";
......
# 目录环境能力 # 目录环境能力
该模块提供环境目录能力,获取内存存储根目录、公共文件根目录的JS接口。
> ![icon-note.gif](public_sys-resources/icon-note.gif) **说明:** > ![icon-note.gif](public_sys-resources/icon-note.gif) **说明:**
> >
> - 本模块首批接口从API version 8开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。 > - 本模块首批接口从API version 8开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。
> - 本模块接口为系统接口,三方应用不支持调用。 > - 本模块接口为系统接口,三方应用不支持调用。
该模块提供环境目录能力,获取内存存储根目录、公共文件根目录的JS接口。
## 导入模块 ## 导入模块
```js ```js
......
# 文件管理 # 文件管理
该模块提供文件存储管理能力,包括文件基本管理、文件目录管理、文件信息统计、文件流式读写等常用功能。
> ![icon-note.gif](public_sys-resources/icon-note.gif) **说明:** > ![icon-note.gif](public_sys-resources/icon-note.gif) **说明:**
> 本模块首批接口从API version 6开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。 > 本模块首批接口从API version 6开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。
该模块提供文件存储管理能力,包括文件基本管理、文件目录管理、文件信息统计、文件流式读写等常用功能。
## 导入模块 ## 导入模块
```js ```js
...@@ -22,7 +22,7 @@ import fileio from '@ohos.fileio'; ...@@ -22,7 +22,7 @@ import fileio from '@ohos.fileio';
context.getFilesDir().then((data) => { context.getFilesDir().then((data) => {
path = data; path = data;
}) })
``` ```
## fileio.stat ## fileio.stat
...@@ -546,7 +546,7 @@ open(path: string, flags?: number, mode?: number): Promise&lt;number&gt; ...@@ -546,7 +546,7 @@ open(path: string, flags?: number, mode?: number): Promise&lt;number&gt;
```js ```js
fileio.open(path, 0o1, 0o0200).then(function(number){ fileio.open(path, 0o1, 0o0200).then(function(number){
console.info("open file succeed"); console.info("open file succeed");
}).catch(function(error){ }).catch(function(err){
console.info("open file failed with error:"+ err); console.info("open file failed with error:"+ err);
}); });
``` ```
...@@ -639,11 +639,11 @@ read(fd: number, buffer: ArrayBuffer, options?: { ...@@ -639,11 +639,11 @@ read(fd: number, buffer: ArrayBuffer, options?: {
```js ```js
let fd = fileio.openSync(path, 0o2); let fd = fileio.openSync(path, 0o2);
let buf = new ArrayBuffer(4096); let buf = new ArrayBuffer(4096);
fileio.read(fd, buf).then(function(readout){ fileio.read(fd, buf).then(function(readOut){
console.info("read file data succeed"); console.info("read file data succeed");
console.log(String.fromCharCode.apply(null, new Uint8Array(readOut.buffer))); console.log(String.fromCharCode.apply(null, new Uint8Array(readOut.buffer)));
}).catch(function(error){ }).catch(function(err){
console.info("read file data failed with error:"+ error); console.info("read file data failed with error:"+ err);
}); });
``` ```
...@@ -879,7 +879,7 @@ write(fd: number, buffer: ArrayBuffer | string, options?: { ...@@ -879,7 +879,7 @@ write(fd: number, buffer: ArrayBuffer | string, options?: {
**示例:** **示例:**
```js ```js
let fd = fileio.openSync(fpath, 0o100 | 0o2, 0o666); let fd = fileio.openSync(path, 0o100 | 0o2, 0o666);
fileio.write(fd, "hello, world").then(function(number){ fileio.write(fd, "hello, world").then(function(number){
console.info("write data to file succeed and size is:"+ number); console.info("write data to file succeed and size is:"+ number);
}).catch(function(err){ }).catch(function(err){
...@@ -998,7 +998,7 @@ hash(path: string, algorithm: string, callback: AsyncCallback&lt;string&gt;): vo ...@@ -998,7 +998,7 @@ hash(path: string, algorithm: string, callback: AsyncCallback&lt;string&gt;): vo
**示例:** **示例:**
```js ```js
fileio.hash(fpath, "sha256", function(err, hashStr) { fileio.hash(path, "sha256", function(err, hashStr) {
if (hashStr) { if (hashStr) {
console.info("calculate file hash succeed:"+ hashStr); console.info("calculate file hash succeed:"+ hashStr);
} }
...@@ -1074,7 +1074,7 @@ chmodSync(path: string, mode: number): void ...@@ -1074,7 +1074,7 @@ chmodSync(path: string, mode: number): void
**示例:** **示例:**
```js ```js
fileio.chmodSync(fpath, mode); fileio.chmodSync(path, mode);
``` ```
...@@ -1409,7 +1409,7 @@ lstat(path: string): Promise&lt;Stat&gt; ...@@ -1409,7 +1409,7 @@ lstat(path: string): Promise&lt;Stat&gt;
**示例:** **示例:**
```js ```js
fileio.lstat(path).then(function(stat){ fileio.lstat(path).then(function(stat){
console.info("get link status succeed:"+ number); console.info("get link status succeed:"+ JSON.stringify(stat));
}).catch(function(err){ }).catch(function(err){
console.info("get link status failed with error:"+ err); console.info("get link status failed with error:"+ err);
}); });
...@@ -1663,7 +1663,7 @@ fsyncSync(fd: number): void ...@@ -1663,7 +1663,7 @@ fsyncSync(fd: number): void
**示例:** **示例:**
```js ```js
fileio.fyncsSync(fd); fileio.fsyncSync(fd);
``` ```
...@@ -1857,7 +1857,7 @@ chown(path: string, uid: number, gid: number, callback: AsyncCallback&lt;void&gt ...@@ -1857,7 +1857,7 @@ chown(path: string, uid: number, gid: number, callback: AsyncCallback&lt;void&gt
**示例:** **示例:**
```js ```js
let stat = fileio.statSync(fpath) let stat = fileio.statSync(path)
fileio.chown(path, stat.uid, stat.gid, function (err){ fileio.chown(path, stat.uid, stat.gid, function (err){
// do something // do something
}); });
...@@ -1881,7 +1881,7 @@ chownSync(path: string, uid: number, gid: number): void ...@@ -1881,7 +1881,7 @@ chownSync(path: string, uid: number, gid: number): void
**示例:** **示例:**
```js ```js
let stat = fileio.statSync(fpath) let stat = fileio.statSync(path)
fileio.chownSync(path, stat.uid, stat.gid); fileio.chownSync(path, stat.uid, stat.gid);
``` ```
...@@ -2078,7 +2078,7 @@ createStream(path: string, mode: string, callback: AsyncCallback&lt;Stream&gt;): ...@@ -2078,7 +2078,7 @@ createStream(path: string, mode: string, callback: AsyncCallback&lt;Stream&gt;):
**示例:** **示例:**
```js ```js
fileio.createStream(path, mode, function(err, stream){ fileio.createStream(path, "r+", function(err, stream){
// do something // do something
}); });
``` ```
...@@ -2130,7 +2130,8 @@ fdopenStream(fd: number, mode: string): Promise&lt;Stream&gt; ...@@ -2130,7 +2130,8 @@ fdopenStream(fd: number, mode: string): Promise&lt;Stream&gt;
**示例:** **示例:**
```js ```js
fileio.fdopenStream(fd, mode).then(function(stream){ let fd = fileio.openSync(path);
fileio.fdopenStream(fd, "r+").then(function(stream){
console.info("openStream succeed"); console.info("openStream succeed");
}).catch(function(err){ }).catch(function(err){
console.info("openStream failed with error:"+ err); console.info("openStream failed with error:"+ err);
...@@ -2155,7 +2156,8 @@ fdopenStream(fd: number, mode: string, callback: AsyncCallback&lt;Stream&gt;): v ...@@ -2155,7 +2156,8 @@ fdopenStream(fd: number, mode: string, callback: AsyncCallback&lt;Stream&gt;): v
**示例:** **示例:**
```js ```js
fileio.fdopenStream(fd, mode, function (err, stream) { let fd = fileio.openSync(path);
fileio.fdopenStream(fd, "r+", function (err, stream) {
// do something // do something
}); });
``` ```
...@@ -2182,6 +2184,7 @@ fdopenStreamSync(fd: number, mode: string): Stream ...@@ -2182,6 +2184,7 @@ fdopenStreamSync(fd: number, mode: string): Stream
**示例:** **示例:**
```js ```js
let fd = fileio.openSync(path);
let ss = fileio.fdopenStreamSync(fd, "r+"); let ss = fileio.fdopenStreamSync(fd, "r+");
``` ```
...@@ -2235,7 +2238,7 @@ fchown(fd: number, uid: number, gid: number, callback: AsyncCallback&lt;void&gt; ...@@ -2235,7 +2238,7 @@ fchown(fd: number, uid: number, gid: number, callback: AsyncCallback&lt;void&gt;
**示例:** **示例:**
```js ```js
let stat = fileio.statSync(fpath); let stat = fileio.statSync(path);
fileio.fchown(fd, stat.uid, stat.gid, function (err){ fileio.fchown(fd, stat.uid, stat.gid, function (err){
// do something // do something
}); });
...@@ -2259,7 +2262,7 @@ fchownSync(fd: number, uid: number, gid: number): void ...@@ -2259,7 +2262,7 @@ fchownSync(fd: number, uid: number, gid: number): void
**示例:** **示例:**
```js ```js
let stat = fileio.statSync(fpath); let stat = fileio.statSync(path);
fileio.fchownSync(fd, stat.uid, stat.gid); fileio.fchownSync(fd, stat.uid, stat.gid);
``` ```
...@@ -2364,9 +2367,11 @@ createWatcher(filename: string, events: number, callback: AsyncCallback&lt;numbe ...@@ -2364,9 +2367,11 @@ createWatcher(filename: string, events: number, callback: AsyncCallback&lt;numbe
**示例:** **示例:**
```js ```js
fileio.createWatcher(filename, events, function(watcher){ let filename = path +"/test.txt";
// do something fileio.createWatcher(filename, 1, function(number){
console.info("Monitoring times: "+number);
}); });
``` ```
...@@ -2498,7 +2503,7 @@ isFile(): boolean ...@@ -2498,7 +2503,7 @@ isFile(): boolean
**示例:** **示例:**
```js ```js
let isFile = fileio.statSync(fpath).isFile(); let isFile = fileio.statSync(path).isFile();
``` ```
...@@ -2555,7 +2560,13 @@ stop(): Promise&lt;void&gt; ...@@ -2555,7 +2560,13 @@ stop(): Promise&lt;void&gt;
**示例:** **示例:**
```js ```js
fileio.stop(); let filename = path +"/test.txt";
let watcher = await fileio.createWatcher(filename, 1, function(number){
console.info("Monitoring times: "+number);
});
watcher.stop().then(function(){
console.info("close watcher succeed");
});
``` ```
...@@ -2574,13 +2585,17 @@ stop(callback: AsyncCallback&lt;void&gt;): void ...@@ -2574,13 +2585,17 @@ stop(callback: AsyncCallback&lt;void&gt;): void
**示例:** **示例:**
```js ```js
fileio.stop(function(err){ let filename = path +"/test.txt";
// do something let watcher = await fileio.createWatcher(filename, 1, function(number){
console.info("Monitoring times: "+number);
}); });
watcher.stop(function(){
console.info("close watcher succeed");
})
``` ```
## Stream<sup>7+</sup> ## Stream
文件流,在调用Stream的方法前,需要先通过createStream()方法(同步或异步)来构建一个Stream实例。 文件流,在调用Stream的方法前,需要先通过createStream()方法(同步或异步)来构建一个Stream实例。
...@@ -2600,7 +2615,7 @@ close(): Promise&lt;void&gt; ...@@ -2600,7 +2615,7 @@ close(): Promise&lt;void&gt;
**示例:** **示例:**
```js ```js
let ss= fileio.createStreamSync(path); let ss= fileio.createStreamSync(path, "r+");
ss.close().then(function(){ ss.close().then(function(){
console.info("close fileStream succeed"); console.info("close fileStream succeed");
}).catch(function(err){ }).catch(function(err){
...@@ -2624,7 +2639,7 @@ close(callback: AsyncCallback&lt;void&gt;): void ...@@ -2624,7 +2639,7 @@ close(callback: AsyncCallback&lt;void&gt;): void
**示例:** **示例:**
```js ```js
let ss= fileio.createStreamSync(path); let ss= fileio.createStreamSync(path, "r+");
ss.close(function (err) { ss.close(function (err) {
// do something // do something
}); });
...@@ -2641,7 +2656,7 @@ closeSync(): void ...@@ -2641,7 +2656,7 @@ closeSync(): void
**示例:** **示例:**
```js ```js
let ss= fileio.createStreamSync(path); let ss= fileio.createStreamSync(path, "r+");
ss.closeSync(); ss.closeSync();
``` ```
...@@ -2661,7 +2676,7 @@ flush(): Promise&lt;void&gt; ...@@ -2661,7 +2676,7 @@ flush(): Promise&lt;void&gt;
**示例:** **示例:**
```js ```js
let ss= fileio.createStreamSync(path); let ss= fileio.createStreamSync(path, "r+");
ss.flush().then(function (){ ss.flush().then(function (){
console.info("flush succeed"); console.info("flush succeed");
}).catch(function(err){ }).catch(function(err){
...@@ -2685,7 +2700,7 @@ flush(callback: AsyncCallback&lt;void&gt;): void ...@@ -2685,7 +2700,7 @@ flush(callback: AsyncCallback&lt;void&gt;): void
**示例:** **示例:**
```js ```js
let ss= fileio.createStreamSync(path); let ss= fileio.createStreamSync(path, "r+");
ss.flush(function (err) { ss.flush(function (err) {
// do something // do something
}); });
...@@ -2702,7 +2717,7 @@ flushSync(): void ...@@ -2702,7 +2717,7 @@ flushSync(): void
**示例:** **示例:**
```js ```js
let ss= fileio.createStreamSync(path); let ss= fileio.createStreamSync(path, "r+");
ss.flushSync(); ss.flushSync();
``` ```
...@@ -2733,7 +2748,7 @@ write(buffer: ArrayBuffer | string, options?: { ...@@ -2733,7 +2748,7 @@ write(buffer: ArrayBuffer | string, options?: {
**示例:** **示例:**
```js ```js
let ss= fileio.createStreamSync(fpath, "r+"); let ss= fileio.createStreamSync(path, "r+");
ss.write("hello, world",{offset: 1,length: 5,position: 5,encoding :'utf-8'}).then(function (number){ ss.write("hello, world",{offset: 1,length: 5,position: 5,encoding :'utf-8'}).then(function (number){
console.info("write succeed and size is:"+ number); console.info("write succeed and size is:"+ number);
}).catch(function(err){ }).catch(function(err){
...@@ -2764,7 +2779,7 @@ write(buffer: ArrayBuffer | string, options: { ...@@ -2764,7 +2779,7 @@ write(buffer: ArrayBuffer | string, options: {
**示例:** **示例:**
```js ```js
let ss= fileio.createStreamSync(fpath, "r+"); let ss= fileio.createStreamSync(path, "r+");
ss.write("hello, world", {offset: 1, length: 5, position: 5, encoding :'utf-8'}, function (err, bytesWritten) { ss.write("hello, world", {offset: 1, length: 5, position: 5, encoding :'utf-8'}, function (err, bytesWritten) {
if (bytesWritten) { if (bytesWritten) {
// do something // do something
...@@ -2800,7 +2815,7 @@ writeSync(buffer: ArrayBuffer | string, options?: { ...@@ -2800,7 +2815,7 @@ writeSync(buffer: ArrayBuffer | string, options?: {
**示例:** **示例:**
```js ```js
let ss= fileio.createStreamSync(fpath,"r+"); let ss= fileio.createStreamSync(path,"r+");
let num = ss.writeSync("hello, world", {offset: 1, length: 5, position: 5, encoding :'utf-8'}); let num = ss.writeSync("hello, world", {offset: 1, length: 5, position: 5, encoding :'utf-8'});
``` ```
...@@ -2830,7 +2845,7 @@ read(buffer: ArrayBuffer, options?: { ...@@ -2830,7 +2845,7 @@ read(buffer: ArrayBuffer, options?: {
**示例:** **示例:**
```js ```js
let ss = fileio.createStreamSync(fpath, "r+"); let ss = fileio.createStreamSync(path, "r+");
ss.read(new ArrayBuffer(4096), {offset: 1, length: 5, position: 5}).then(function (readout){ ss.read(new ArrayBuffer(4096), {offset: 1, length: 5, position: 5}).then(function (readout){
console.info("read data succeed"); console.info("read data succeed");
console.log(String.fromCharCode.apply(null, new Uint8Array(readOut.buffer))); console.log(String.fromCharCode.apply(null, new Uint8Array(readOut.buffer)));
...@@ -2861,7 +2876,7 @@ read(buffer: ArrayBuffer, options: { ...@@ -2861,7 +2876,7 @@ read(buffer: ArrayBuffer, options: {
**示例:** **示例:**
```js ```js
let ss = fileio.createStreamSync(fpath, "r+"); let ss = fileio.createStreamSync(path, "r+");
ss.read(new ArrayBuffer(4096),{offset: 1, length: 5, position: 5},function (err, readOut) { ss.read(new ArrayBuffer(4096),{offset: 1, length: 5, position: 5},function (err, readOut) {
if (readOut) { if (readOut) {
console.info("read data succeed"); console.info("read data succeed");
...@@ -2898,7 +2913,7 @@ readSync(buffer: ArrayBuffer, options?: { ...@@ -2898,7 +2913,7 @@ readSync(buffer: ArrayBuffer, options?: {
**示例:** **示例:**
```js ```js
let ss = fileio.createStreamSync(fpath, "r+"); let ss = fileio.createStreamSync(path, "r+");
let num = ss.readSync(new ArrayBuffer(4096), {offset: 1, length: 5, position: 5}); let num = ss.readSync(new ArrayBuffer(4096), {offset: 1, length: 5, position: 5});
``` ```
......
# 公共文件访问与管理 # 公共文件访问与管理
该模块提供公共文件访问和管理的服务接口,向下对接底层文件管理服务,如媒体库、外卡管理;向上对应用程序提供公共文件查询、创建的能力。
>![icon-note.gif](public_sys-resources/icon-note.gif) **说明:** >![icon-note.gif](public_sys-resources/icon-note.gif) **说明:**
> >
>- 本模块首批接口从API version 9开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。 >- 本模块首批接口从API version 9开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。
>- 本模块接口为系统接口,三方应用不支持调用,当前只支持filepicker调用。 >- 本模块接口为系统接口,三方应用不支持调用,当前只支持filepicker调用。
该模块提供公共文件访问和管理的服务接口,向下对接底层文件管理服务,如媒体库、外卡管理;向上对应用程序提供公共文件查询、创建的能力。
## 导入模块 ## 导入模块
```js ```js
...@@ -20,18 +21,18 @@ getRoot(options? : {dev? : DevInfo}) : Promise&lt;FileInfo[]&gt; ...@@ -20,18 +21,18 @@ getRoot(options? : {dev? : DevInfo}) : Promise&lt;FileInfo[]&gt;
**系统能力**:SystemCapability.FileManagement.UserFileService **系统能力**:SystemCapability.FileManagement.UserFileService
- 参数 **参数:**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
| --- | --- | --- | -- | | --- | --- | --- | -- |
| options | Object | 否 | 支持如下选项:<br/>-&nbsp;dev,[DevInfo](#devinfo)类型,不填默认dev = {name: "local"}, 当前仅支持设备'local' | | options | Object | 否 | 支持如下选项:<br/>-&nbsp;dev,[DevInfo](#devinfo)类型,不填默认dev = {name: "local"}, 当前仅支持设备'local' |
- 返回值 **返回值:**
| 类型 | 说明 | | 类型 | 说明 |
| --- | -- | | --- | -- |
| Promise&lt;[FileInfo](#fileinfo)[]&gt; | 第一层目录相册信息 | | Promise&lt;[FileInfo](#fileinfo)[]&gt; | 第一层目录相册信息 |
- 示例 **示例:**
```js ```js
filemanager.getRoot().then((fileInfo) => { filemanager.getRoot().then((fileInfo) => {
...@@ -53,22 +54,22 @@ getRoot(options? : {dev? : DevInfo}, callback : AsyncCallback&lt;FileInfo[]&gt;) ...@@ -53,22 +54,22 @@ getRoot(options? : {dev? : DevInfo}, callback : AsyncCallback&lt;FileInfo[]&gt;)
**系统能力**:SystemCapability.FileManagement.UserFileService **系统能力**:SystemCapability.FileManagement.UserFileService
- 参数 **参数:**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
| -------- | ------------------------- | ---- | ----------------------------- | | -------- | ------------------------- | ---- | ----------------------------- |
| options | Object | 否 | 支持如下选项:<br/>-&nbsp;dev,[DevInfo](#devinfo)类型,不填默认dev = {name: "local"}, 当前仅支持设备'local' | | options | Object | 否 | 支持如下选项:<br/>-&nbsp;dev,[DevInfo](#devinfo)类型,不填默认dev = {name: "local"}, 当前仅支持设备'local' |
| callback | AsyncCallback&lt;[FileInfo](#fileinfo)[]&gt; | 是 | 异步获取文件的信息之后的回调 | | callback | AsyncCallback&lt;[FileInfo](#fileinfo)[]&gt; | 是 | 异步获取文件的信息之后的回调 |
- 示例 **示例:**
```js ```js
let option = { let options = {
"dev":{ "dev":{
name:"", "name":"local"
} }
}; };
filemanager.getRoot(option,(err, fileInfo)=>{ filemanager.getRoot(options, (err, fileInfo)=>{
if(Array.isArray(fileInfo)) { if(Array.isArray(fileInfo)) {
for (var i = 0; i < fileInfo.length; i++) { for (var i = 0; i < fileInfo.length; i++) {
console.log("file:"+JSON.stringify(fileInfo)); console.log("file:"+JSON.stringify(fileInfo));
...@@ -86,27 +87,28 @@ listFile(path : string, type : string, options? : {dev? : DevInfo, offset? : num ...@@ -86,27 +87,28 @@ listFile(path : string, type : string, options? : {dev? : DevInfo, offset? : num
**系统能力**:SystemCapability.FileManagement.UserFileService **系统能力**:SystemCapability.FileManagement.UserFileService
- 参数 **参数:**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
| --- | --- | --- | -- | | --- | --- | --- | -- |
| path | string | 是 | 待查询目录uri | | path | string | 是 | 待查询目录uri |
| type | string | 是 | 待查询文件类型, 支持以下类型 "file", "image", "audio", "video" | | type | string | 是 | 待查询文件类型, 支持以下类型 "file", "image", "audio", "video" |
| options | Object | 否 | 支持如下选项:<br/>-&nbsp;dev,[DevInfo](#devinfo)类型,不填默认dev = {name: "local"}, 当前仅支持设备'local'。<br/>-&nbsp;offset,number类型,待查询文件偏移个数。<br/>-&nbsp;count,number类型,待查询文件个数。 | | options | Object | 否 | 支持如下选项:<br/>-&nbsp;dev,[DevInfo](#devinfo)类型,不填默认dev = {name: "local"}, 当前仅支持设备'local'。<br/>-&nbsp;offset,number类型,待查询文件偏移个数。<br/>-&nbsp;count,number类型,待查询文件个数。 |
- 返回值 **返回值:**
| 类型 | 说明 | | 类型 | 说明 |
| --- | -- | | --- | -- |
| Promise&lt;FileInfo[]&gt; | 文件信息 | | Promise&lt;FileInfo[]&gt; | 文件信息 |
- 异常 **异常:**
| 错误名称 | 错误类型 | 错误码 |说明 | | 错误名称 | 错误类型 | 错误码 |说明 |
| --- | -- | --- | -- | | --- | -- | --- | -- |
| 对应的目录、相册不存在 | No such file or directory | 2 | uri对应的目录、相册不存在 | | 对应的目录、相册不存在 | No such file or directory | 2 | uri对应的目录、相册不存在 |
| 获取FMS服务失败 | No such process | 3 | 获取FMS服务失败 | | 获取FMS服务失败 | No such process | 3 | 获取FMS服务失败 |
| path对应uri不是相册、目录 | Not a directory | 20 | path对应uri不是相册、目录 | | path对应uri不是相册、目录 | Not a directory | 20 | path对应uri不是相册、目录 |
- 示例 **示例:**
```js ```js
// 获取目录下所有文件 // 获取目录下所有文件
...@@ -120,10 +122,7 @@ listFile(path : string, type : string, options? : {dev? : DevInfo, offset? : num ...@@ -120,10 +122,7 @@ listFile(path : string, type : string, options? : {dev? : DevInfo, offset? : num
} }
} }
}).catch((err) => { }).catch((err) => {
console.log("failed to get file"+err);
console.log(err)
}); });
``` ```
...@@ -135,23 +134,24 @@ listFile(path : string, type : string, options? : {dev? : DevInfo, offset? : num ...@@ -135,23 +134,24 @@ listFile(path : string, type : string, options? : {dev? : DevInfo, offset? : num
**系统能力**:SystemCapability.FileManagement.UserFileService **系统能力**:SystemCapability.FileManagement.UserFileService
- 参数 **参数:**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
| -------- | ------------------------- | ---- | ------------------------------------------------------------ | | -------- | ------------------------- | ---- | ------------------------------------------------------------ |
| path | string | 是 | 待查询目录uri | | path | string | 是 | 待查询目录uri |
| type | string | 是 | 待查询文件类型, 支持以下类型 "file", "image", "audio", "video" | | type | string | 是 | 待查询文件类型, 支持以下类型 "file", "image", "audio", "video" |
| options | Object | 否 | 支持如下选项:<br/>-&nbsp;dev,[DevInfo](#devinfo)类型,不填默认dev = {name: "local"}, 当前仅支持设备'local'。<br/>-&nbsp;offset,number类型,待查询文件偏移个数。<br/>-&nbsp;count,number类型,待查询文件个数。 | | options | Object | 否 | 支持如下选项:<br/>-&nbsp;dev,[DevInfo](#devinfo)类型,不填默认dev = {name: "local"}, 当前仅支持设备'local'。<br/>-&nbsp;offset,number类型,待查询文件偏移个数。<br/>-&nbsp;count,number类型,待查询文件个数。 |
| callback | AsyncCallback&lt;[FileInfo](#fileinfo)[]&gt; | 是 | 异步获取文件的信息之后的回调 | | callback | AsyncCallback&lt;[FileInfo](#fileinfo)[]&gt; | 是 | 异步获取文件的信息之后的回调 |
- 异常
| 错误名称 | 错误类型 | 错误码 | 说明 | **异常:**
| ------------------------- | ------------------------- | ------ | ------------------------- |
| 对应的目录、相册不存在 | No such file or directory | 2 | uri对应的目录、相册不存在 | | 错误名称 | 错误类型 | 错误码 | 说明 |
| 获取FMS服务失败 | No such process | 3 | 获取FMS服务失败 | | ------------------------- | ------------------------- | ------ | ------------------------- |
| path对应uri不是相册、目录 | Not a directory | 20 | path对应uri不是相册、目录 | | 对应的目录、相册不存在 | No such file or directory | 2 | uri对应的目录、相册不存在 |
| 获取FMS服务失败 | No such process | 3 | 获取FMS服务失败 |
| path对应uri不是相册、目录 | Not a directory | 20 | path对应uri不是相册、目录 |
- 示例 **示例:**
```js ```js
// 通过listFile、getRoot获取的文件path // 通过listFile、getRoot获取的文件path
...@@ -177,7 +177,7 @@ listFile(path : string, type : string, options? : {dev? : DevInfo, offset? : num ...@@ -177,7 +177,7 @@ listFile(path : string, type : string, options? : {dev? : DevInfo, offset? : num
} }
} }
}).catch((err) => { }).catch((err) => {
console.log(err) console.log("failed to get file"+err);
}); });
``` ```
...@@ -189,20 +189,21 @@ createFile(path : string, filename : string, options? : {dev? : DevInfo}) : P ...@@ -189,20 +189,21 @@ createFile(path : string, filename : string, options? : {dev? : DevInfo}) : P
**系统能力**:SystemCapability.FileManagement.UserFileService **系统能力**:SystemCapability.FileManagement.UserFileService
- 参数 **参数:**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
| --- | --- | --- | -- | | --- | --- | --- | -- |
| filename | string | 是 | 待创建的文件名 | | filename | string | 是 | 待创建的文件名 |
| path | string | 是 | 待保存目的相册uri | | path | string | 是 | 待保存目的相册uri |
| options | Object | 否 | 支持如下选项:<br/>-&nbsp;dev,[DevInfo](#devinfo)类型,不填默认dev = {name: "local"}, 当前仅支持设备'local' | | options | Object | 否 | 支持如下选项:<br/>-&nbsp;dev,[DevInfo](#devinfo)类型,不填默认dev = {name: "local"}, 当前仅支持设备'local' |
- 返回值 **返回值:**
| 类型 | 说明 | | 类型 | 说明 |
| --- | -- | | --- | -- |
| string | 文件uri | | Promise&lt;string&gt; | 文件uri |
**异常:**
- 异常
| 错误名称 | 错误类型 | 错误码 |说明 | | 错误名称 | 错误类型 | 错误码 |说明 |
| --- | -- | --- | -- | | --- | -- | --- | -- |
| 创建文件不允许 | Operation not permitted | 1 | 已有重名文件 | | 创建文件不允许 | Operation not permitted | 1 | 已有重名文件 |
...@@ -210,7 +211,7 @@ createFile(path : string, filename : string, options? : {dev? : DevInfo}) : P ...@@ -210,7 +211,7 @@ createFile(path : string, filename : string, options? : {dev? : DevInfo}) : P
| 获取FMS服务失败 | No such process | 3 | 获取FMS服务失败 | | 获取FMS服务失败 | No such process | 3 | 获取FMS服务失败 |
| path对应uri不是相册、目录 | Not a directory | 20 | path对应uri不是相册、目录 | | path对应uri不是相册、目录 | Not a directory | 20 | path对应uri不是相册、目录 |
- 示例 **示例:**
```js ```js
// 创建文件,返回文件uri // 创建文件,返回文件uri
...@@ -232,7 +233,7 @@ createFile(path : string, filename: string, options? : {dev? : DevInfo}, callbac ...@@ -232,7 +233,7 @@ createFile(path : string, filename: string, options? : {dev? : DevInfo}, callbac
**系统能力**:SystemCapability.FileManagement.UserFileService **系统能力**:SystemCapability.FileManagement.UserFileService
- 参数 **参数:**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
| -------- | ------------------------- | ---- | ----------------------------- | | -------- | ------------------------- | ---- | ----------------------------- |
...@@ -241,7 +242,7 @@ createFile(path : string, filename: string, options? : {dev? : DevInfo}, callbac ...@@ -241,7 +242,7 @@ createFile(path : string, filename: string, options? : {dev? : DevInfo}, callbac
| options | Object | 否 | 支持如下选项:<br/>-&nbsp;dev,[DevInfo](#devinfo)类型,不填默认dev = {name: "local"}, 当前仅支持设备'local' | | options | Object | 否 | 支持如下选项:<br/>-&nbsp;dev,[DevInfo](#devinfo)类型,不填默认dev = {name: "local"}, 当前仅支持设备'local' |
| callback | AsyncCallback&lt;[FileInfo](#fileinfo)[]&gt; | 是 | 异步获取文件的信息之后的回调 | | callback | AsyncCallback&lt;[FileInfo](#fileinfo)[]&gt; | 是 | 异步获取文件的信息之后的回调 |
- 异常 **异常:**
| 错误名称 | 错误类型 | 错误码 | 说明 | | 错误名称 | 错误类型 | 错误码 | 说明 |
| ------------------------- | ------------------------- | ------ | ------------------------- | | ------------------------- | ------------------------- | ------ | ------------------------- |
...@@ -250,7 +251,7 @@ createFile(path : string, filename: string, options? : {dev? : DevInfo}, callbac ...@@ -250,7 +251,7 @@ createFile(path : string, filename: string, options? : {dev? : DevInfo}, callbac
| 获取FMS服务失败 | No such process | 3 | 获取FMS服务失败 | | 获取FMS服务失败 | No such process | 3 | 获取FMS服务失败 |
| path对应uri不是相册、目录 | Not a directory | 20 | path对应uri不是相册、目录 | | path对应uri不是相册、目录 | Not a directory | 20 | path对应uri不是相册、目录 |
- 示例 **示例:**
```js ```js
// 创建文件,返回文件uri // 创建文件,返回文件uri
...@@ -258,8 +259,12 @@ createFile(path : string, filename: string, options? : {dev? : DevInfo}, callbac ...@@ -258,8 +259,12 @@ createFile(path : string, filename: string, options? : {dev? : DevInfo}, callbac
let media_path = "" let media_path = ""
// 待保存文件的后缀 // 待保存文件的后缀
let name = "xxx.jpg" let name = "xxx.jpg"
let dev = ""; let options = {
filemanager.createFile(media_path, name, { DevInfo: dev }, function(err, uri) { "dev":{
"name":"local"
}
};
filemanager.createFile(media_path, name, options, function(err, uri) {
// 返回uri给应用 // 返回uri给应用
console.log("file uri:"+uri); console.log("file uri:"+uri);
}); });
......
# 数据标签 # 数据标签
该模块提供文件数据安全等级的相关功能:向应用程序提供查询、设置文件数据安全等级的JS接口。
> ![icon-note.gif](public_sys-resources/icon-note.gif) **说明:** > ![icon-note.gif](public_sys-resources/icon-note.gif) **说明:**
> 本模块首批接口从API version 9开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。 > 本模块首批接口从API version 9开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。
该模块提供文件数据安全等级的相关功能:向应用程序提供查询、设置文件数据安全等级的JS接口。
## 导入模块 ## 导入模块
```js ```js
......
# statfs # statfs
该模块提供文件系统相关存储信息的功能,向应用程序提供获取文件系统总字节数、空闲字节数的JS接口。
> ![icon-note.gif](public_sys-resources/icon-note.gif) **说明:** > ![icon-note.gif](public_sys-resources/icon-note.gif) **说明:**
> 本模块首批接口从API version 8开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。 > 本模块首批接口从API version 8开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。
该模块提供文件系统相关存储信息的功能,向应用程序提供获取文件系统总字节数、空闲字节数的JS接口。
## 导入模块 ## 导入模块
```js ```js
......
# 应用空间统计 # 应用空间统计
该模块提供空间查询相关的常用功能:包括对内外卡的空间查询,对应用分类数据统计的查询,对应用数据的查询等。
> ![icon-note.gif](public_sys-resources/icon-note.gif) **说明:** > ![icon-note.gif](public_sys-resources/icon-note.gif) **说明:**
> >
> - 本模块首批接口从API version 8开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。 > - 本模块首批接口从API version 8开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。
> - API 9当前为Canary版本,仅供试用,不保证接口可稳定调用。 > - API 9当前为Canary版本,仅供试用,不保证接口可稳定调用。
该模块提供空间查询相关的常用功能:包括对内外卡的空间查询,对应用分类数据统计的查询,对应用数据的查询等。
## 导入模块 ## 导入模块
```js ```js
import storageStatistics from "@ohos.storageStatistics"; import storageStatistics from "@ohos.storageStatistics";
``` ```
## storagestatistics.getTotalSizeOfVolume ## storageStatistics.getTotalSizeOfVolume
getTotalSizeOfVolume(volumeUuid: string): Promise&lt;number&gt; getTotalSizeOfVolume(volumeUuid: string): Promise&lt;number&gt;
...@@ -23,32 +23,34 @@ getTotalSizeOfVolume(volumeUuid: string): Promise&lt;number&gt; ...@@ -23,32 +23,34 @@ getTotalSizeOfVolume(volumeUuid: string): Promise&lt;number&gt;
**系统能力**:SystemCapability.FileManagement.StorageService.SpatialStatistics **系统能力**:SystemCapability.FileManagement.StorageService.SpatialStatistics
该接口为系统接口,三方应用不支持调用 该接口为系统接口,三方应用不支持调用
- 参数
**参数:**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
| ---------- | ------ | ---- | ---- | | ---------- | ------ | ---- | ---- |
| volumeUuid | string | 是 | 卷id | | volumeUuid | string | 是 | 卷id |
- 返回值 **返回值:**
| 类型 | 说明 | | 类型 | 说明 |
| --------------------- | ---------------- | | --------------------- | ---------------- |
| Promise&lt;number&gt; | 返回指定卷总空间 | | Promise&lt;number&gt; | 返回指定卷总空间 |
- 示例 **示例:**
```js ```js
let uuid = ""; let uuid = "";
storagestatistics.getTotalSizeOfVolume(uuid).then(function(number){ storageStatistics.getTotalSizeOfVolume(uuid).then(function(number){
console.info("getTotalSizeOfVolume successfully:"+ number); console.info("getTotalSizeOfVolume successfully:"+ number);
}).catch(function(err){ }).catch(function(err){
console.info("getTotalSizeOfVolume failed with error:"+ err); console.info("getTotalSizeOfVolume failed with error:"+ err);
}); });
``` ```
## storagestatistics.getTotalSizeOfVolume ## storageStatistics.getTotalSizeOfVolume
getTotalSizeOfVolume(volumeUuid: string, callback:AsyncCallback&lt;number&gt;):void getTotalSizeOfVolume(volumeUuid: string, callback:AsyncCallback&lt;number&gt;):void
...@@ -58,28 +60,28 @@ getTotalSizeOfVolume(volumeUuid: string, callback:AsyncCallback&lt;number&gt;):v ...@@ -58,28 +60,28 @@ getTotalSizeOfVolume(volumeUuid: string, callback:AsyncCallback&lt;number&gt;):v
**系统能力**:SystemCapability.FileManagement.StorageService.SpatialStatistics **系统能力**:SystemCapability.FileManagement.StorageService.SpatialStatistics
该接口为系统接口,三方应用不支持调用 该接口为系统接口,三方应用不支持调用
- 参数
**参数:**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
| ---------- | ------------------------------------ | ---- | -------------------------- | | ---------- | ------------------------------------ | ---- | -------------------------- |
| volumeUuid | string | 是 | 卷id | | volumeUuid | string | 是 | 卷id |
| callback | callback:AsyncCallback&lt;number&gt; | 是 | 获取指定卷总空间之后的回调 | | callback | callback:AsyncCallback&lt;number&gt; | 是 | 获取指定卷总空间之后的回调 |
- 示例 **示例:**
```js ```js
let uuid = ""; let uuid = "";
storagestatistics.getTotalSizeOfVolume(uuid, function(error, number){ storageStatistics.getTotalSizeOfVolume(uuid, function(error, number){
// do something // do something
console.info("getTotalSizeOfVolume successfully:"+ number); console.info("getTotalSizeOfVolume successfully:"+ number);
}); });
``` ```
## storageStatistics.getFreeSizeOfVolume
## storagestatistics.getFreeSizeOfVolume
getFreeSizeOfVolume(volumeUuid: string): Promise&lt;number&gt; getFreeSizeOfVolume(volumeUuid: string): Promise&lt;number&gt;
...@@ -89,25 +91,27 @@ getFreeSizeOfVolume(volumeUuid: string): Promise&lt;number&gt; ...@@ -89,25 +91,27 @@ getFreeSizeOfVolume(volumeUuid: string): Promise&lt;number&gt;
**系统能力**:SystemCapability.FileManagement.StorageService.SpatialStatistics **系统能力**:SystemCapability.FileManagement.StorageService.SpatialStatistics
该接口为系统接口,三方应用不支持调用 该接口为系统接口,三方应用不支持调用
- 参数
**参数:**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
| ---------- | ------ | ---- | ---- | | ---------- | ------ | ---- | ---- |
| volumeUuid | string | 是 | 卷id | | volumeUuid | string | 是 | 卷id |
- 返回值 **返回值:**
| 类型 | 说明 | | 类型 | 说明 |
| --------------------- | ------------------ | | --------------------- | ------------------ |
| Promise&lt;number&gt; | 返回指定卷可用空间 | | Promise&lt;number&gt; | 返回指定卷可用空间 |
- 示例 **示例:**
```js ```js
let uuid = ""; let uuid = "";
storagestatistics.getFreeSizeOfVolume(uuid).then(function(number){ storageStatistics.getFreeSizeOfVolume(uuid).then(function(number){
console.info("getFreeSizeOfVolume successfully:"+ number); console.info("getFreeSizeOfVolume successfully:"+ number);
}).catch(function(err){ }).catch(function(err){
console.info("getFreeSizeOfVolume failed with error:"+ err); console.info("getFreeSizeOfVolume failed with error:"+ err);
...@@ -115,7 +119,7 @@ getFreeSizeOfVolume(volumeUuid: string): Promise&lt;number&gt; ...@@ -115,7 +119,7 @@ getFreeSizeOfVolume(volumeUuid: string): Promise&lt;number&gt;
``` ```
## storagestatistics.getFreeSizeOfVolume ## storageStatistics.getFreeSizeOfVolume
getFreeSizeOfVolume(volumeUuid: string, callback:AsyncCallback&lt;number&gt;):void getFreeSizeOfVolume(volumeUuid: string, callback:AsyncCallback&lt;number&gt;):void
...@@ -125,26 +129,28 @@ getFreeSizeOfVolume(volumeUuid: string, callback:AsyncCallback&lt;number&gt;):vo ...@@ -125,26 +129,28 @@ getFreeSizeOfVolume(volumeUuid: string, callback:AsyncCallback&lt;number&gt;):vo
**系统能力**:SystemCapability.FileManagement.StorageService.SpatialStatistics **系统能力**:SystemCapability.FileManagement.StorageService.SpatialStatistics
该接口为系统接口,三方应用不支持调用 该接口为系统接口,三方应用不支持调用
- 参数
**参数:**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
| ---------- | ------------------------------------ | ---- | ---------------------------- | | ---------- | ------------------------------------ | ---- | ---------------------------- |
| volumeUuid | string | 是 | 卷id | | volumeUuid | string | 是 | 卷id |
| callback | callback:AsyncCallback&lt;number&gt; | 是 | 获取指定卷可用空间之后的回调 | | callback | callback:AsyncCallback&lt;number&gt; | 是 | 获取指定卷可用空间之后的回调 |
- 示例 **示例:**
```js ```js
let uuid = ""; let uuid = "";
storagestatistics.getFreeSizeOfVolume(uuid, function(error, number){ storageStatistics.getFreeSizeOfVolume(uuid, function(error, number){
// do something // do something
console.info("getFreeSizeOfVolume successfully:"+ number); console.info("getFreeSizeOfVolume successfully:"+ number);
}); });
``` ```
## storagestatistics.getBundleStats<sup>9+</sup> ## storageStatistics.getBundleStats<sup>9+</sup>
getBundleStats(packageName: string): Promise&lt;BundleStats&gt; getBundleStats(packageName: string): Promise&lt;BundleStats&gt;
...@@ -154,32 +160,34 @@ getBundleStats(packageName: string): Promise&lt;BundleStats&gt; ...@@ -154,32 +160,34 @@ getBundleStats(packageName: string): Promise&lt;BundleStats&gt;
**系统能力**:SystemCapability.FileManagement.StorageService.SpatialStatistics **系统能力**:SystemCapability.FileManagement.StorageService.SpatialStatistics
该接口为系统接口,三方应用不支持调用 该接口为系统接口,三方应用不支持调用
- 参数
**参数:**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
| ----------- | ------ | ---- | -------- | | ----------- | ------ | ---- | -------- |
| packageName | string | 是 | 应用包名 | | packageName | string | 是 | 应用包名 |
- 返回值 **返回值:**
| 类型 | 说明 | | 类型 | 说明 |
| ------------------------------------------ | -------------------------- | | ------------------------------------------ | -------------------------- |
| Promise&lt;[Bundlestats](#bundlestats)&gt; | 返回指定卷上的应用存储数据 | | Promise&lt;[Bundlestats](#bundlestats)&gt; | 返回指定卷上的应用存储数据 |
- 示例 **示例:**
```js ```js
let packageName = ""; let packageName = "";
storagestatistics.getBundleStats(packageName).then(function(BundleStats){ storageStatistics.getBundleStats(packageName).then(function(BundleStats){
console.info("getBundleStats successfully:"+ JSON.stringify(BundleStats)); console.info("getBundleStats successfully:"+ JSON.stringify(BundleStats));
}).catch(function(err){ }).catch(function(err){
console.info("getBundleStats failed with error:"+ err); console.info("getBundleStats failed with error:"+ err);
}); });
``` ```
## storagestatistics.getBundleStats<sup>9+</sup> ## storageStatistics.getBundleStats<sup>9+</sup>
getBundleStats(packageName: string, callback: AsyncCallback&lt;BundleStats&gt;): void getBundleStats(packageName: string, callback: AsyncCallback&lt;BundleStats&gt;): void
...@@ -189,28 +197,28 @@ getBundleStats(packageName: string, callback: AsyncCallback&lt;BundleStats&gt;) ...@@ -189,28 +197,28 @@ getBundleStats(packageName: string, callback: AsyncCallback&lt;BundleStats&gt;)
**系统能力**:SystemCapability.FileManagement.StorageService.SpatialStatistics **系统能力**:SystemCapability.FileManagement.StorageService.SpatialStatistics
该接口为系统接口,三方应用不支持调用 该接口为系统接口,三方应用不支持调用
- 参数
**参数:**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
| -------- | --------------------------------------------------------- | ---- | ------------------------------------ | | -------- | --------------------------------------------------------- | ---- | ------------------------------------ |
| packageName | string | 是 | 应用包名 | | packageName | string | 是 | 应用包名 |
| callback | callback:AsyncCallback&lt;[Bundlestats](#bundlestats)&gt; | 是 | 获取指定卷上的应用存储数据之后的回调 | | callback | callback:AsyncCallback&lt;[Bundlestats](#bundlestats)&gt; | 是 | 获取指定卷上的应用存储数据之后的回调 |
- 示例 **示例:**
```js ```js
let packageName = ""; let packageName = "";
storagestatistics.getBundleStats(packageName, function(error, BundleStats){ storageStatistics.getBundleStats(packageName, function(error, BundleStats){
// do something // do something
console.info("getBundleStats successfully:"+ JSON.stringify(BundleStats)); console.info("getBundleStats successfully:"+ JSON.stringify(BundleStats));
}); });
``` ```
## storageStatistics.getCurrentBundleStats<sup>9+</sup>
## storagestatistics.getCurrentBundleStats<sup>9+</sup>
getCurrentBundleStats(): Promise&lt;BundleStats&gt; getCurrentBundleStats(): Promise&lt;BundleStats&gt;
...@@ -218,20 +226,20 @@ getCurrentBundleStats(): Promise&lt;BundleStats&gt; ...@@ -218,20 +226,20 @@ getCurrentBundleStats(): Promise&lt;BundleStats&gt;
**系统能力**:SystemCapability.FileManagement.StorageService.SpatialStatistics **系统能力**:SystemCapability.FileManagement.StorageService.SpatialStatistics
- 返回值 **返回值:**
| 类型 | 说明 | | 类型 | 说明 |
| ------------------------------------------ | -------------------------- | | ------------------------------------------ | -------------------------- |
| Promise&lt;[Bundlestats](#bundlestats)&gt; | 返回指定卷上的应用存储状态 | | Promise&lt;[Bundlestats](#bundlestats)&gt; | 返回指定卷上的应用存储状态 |
- 示例 **示例:**
```js ```js
let bundleStats = storageStatistics.getCurrentBundleStats(); let bundleStats = storageStatistics.getCurrentBundleStats();
console.info("getCurrentBundleStats successfully:"+ JSON.stringify(bundleStats)); console.info("getCurrentBundleStats successfully:"+ JSON.stringify(bundleStats));
``` ```
## storagestatistics.getCurrentBundleStats<sup>9+</sup> ## storageStatistics.getCurrentBundleStats<sup>9+</sup>
getCurrentBundleStats(callback: AsyncCallback&lt;BundleStats&gt;): void getCurrentBundleStats(callback: AsyncCallback&lt;BundleStats&gt;): void
...@@ -239,29 +247,30 @@ getCurrentBundleStats(callback: AsyncCallback&lt;BundleStats&gt;): void ...@@ -239,29 +247,30 @@ getCurrentBundleStats(callback: AsyncCallback&lt;BundleStats&gt;): void
**系统能力**:SystemCapability.FileManagement.StorageService.SpatialStatistics **系统能力**:SystemCapability.FileManagement.StorageService.SpatialStatistics
- 参数 **参数:**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
| -------- | --------------------------------------------------------- | ---- | ------------------------------------ | | -------- | --------------------------------------------------------- | ---- | ------------------------------------ |
| callback | callback:AsyncCallback&lt;[BundleStats](#bundlestats)&gt; | 是 | 获取指定卷上的应用存储状态之后的回调 | | callback | callback:AsyncCallback&lt;[BundleStats](#bundlestats)&gt; | 是 | 获取指定卷上的应用存储状态之后的回调 |
- 示例 **示例:**
```js ```js
storagestatistics.getCurrentBundleStats(function(error, bundleStats){ storageStatistics.getCurrentBundleStats(function(error, bundleStats){
// do something // do something
console.info("getCurrentBundleStats successfully:"+ JSON.stringify(bundleStats)); console.info("getCurrentBundleStats successfully:"+ JSON.stringify(bundleStats));
}); });
``` ```
## BundleStats<sup>9+</sup>
**系统能力**:以下各项对应的系统能力均为SystemCapability.FileManagement.StorageService.SpatialStatistics
## BundleStats<sup>9+</sup>
**系统能力**:以下各项对应的系统能力均为SystemCapability.FileManagement.StorageService.SpatialStatistics。<br>
该接口为系统接口,三方应用不支持调用 该接口为系统接口,三方应用不支持调用
- 属性
### 属性
| 名称 | 类型 | 说明 | | 名称 | 类型 | 说明 |
| --------- | ------ | -------------- | | --------- | ------ | -------------- |
...@@ -270,9 +279,7 @@ getCurrentBundleStats(callback: AsyncCallback&lt;BundleStats&gt;): void ...@@ -270,9 +279,7 @@ getCurrentBundleStats(callback: AsyncCallback&lt;BundleStats&gt;): void
| dataSize | number | 应用总数据大小 | | dataSize | number | 应用总数据大小 |
## storageStatistics.getTotalSize<sup>9+</sup>
## storagestatistics.getTotalSize<sup>9+</sup>
getTotalSize(): Promise&lt;number&gt; getTotalSize(): Promise&lt;number&gt;
...@@ -282,22 +289,24 @@ getTotalSize(): Promise&lt;number&gt; ...@@ -282,22 +289,24 @@ getTotalSize(): Promise&lt;number&gt;
**系统能力**:SystemCapability.FileManagement.StorageService.SpatialStatistics **系统能力**:SystemCapability.FileManagement.StorageService.SpatialStatistics
该接口为系统接口,三方应用不支持调用 该接口为系统接口,三方应用不支持调用
- 返回值
**返回值:**
| 类型 | 说明 | | 类型 | 说明 |
| --------------------- | ------------------ | | --------------------- | ------------------ |
| Promise&lt;number&gt; | 返回内卡的总空间大小 | | Promise&lt;number&gt; | 返回内卡的总空间大小 |
- 示例 **示例:**
```js ```js
let number = storageStatistics.getTotalSize(); let number = storageStatistics.getTotalSize();
console.info("getTotalSize successfully:"+ JSON.stringify(number)); console.info("getTotalSize successfully:"+ JSON.stringify(number));
``` ```
## storagestatistics.getTotalSize<sup>9+</sup> ## storageStatistics.getTotalSize<sup>9+</sup>
getTotalSize(callback: AsyncCallback&lt;number&gt;): void getTotalSize(callback: AsyncCallback&lt;number&gt;): void
...@@ -307,25 +316,27 @@ getTotalSize(callback: AsyncCallback&lt;number&gt;): void ...@@ -307,25 +316,27 @@ getTotalSize(callback: AsyncCallback&lt;number&gt;): void
**系统能力**:SystemCapability.FileManagement.StorageService.SpatialStatistics **系统能力**:SystemCapability.FileManagement.StorageService.SpatialStatistics
该接口为系统接口,三方应用不支持调用 该接口为系统接口,三方应用不支持调用
- 参数
**参数:**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
| -------- | ------------------------------------ | ---- | ------------------------ | | -------- | ------------------------------------ | ---- | ------------------------ |
| callback | callback:AsyncCallback&lt;number&gt; | 是 | 获取内卡的总空间大小之后的回调 | | callback | callback:AsyncCallback&lt;number&gt; | 是 | 获取内卡的总空间大小之后的回调 |
- 示例 **示例:**
```js ```js
storagestatistics.getTotalSize(function(error, number){ storageStatistics.getTotalSize(function(error, number){
// do something // do something
console.info("getTotalSize successfully:"+ JSON.stringify(number)); console.info("getTotalSize successfully:"+ JSON.stringify(number));
}); });
``` ```
## storagestatistics.getFreeSize<sup>9+</sup> ## storageStatistics.getFreeSize<sup>9+</sup>
getFreeSize(): Promise&lt;number&gt; getFreeSize(): Promise&lt;number&gt;
...@@ -335,15 +346,17 @@ getFreeSize(): Promise&lt;number&gt; ...@@ -335,15 +346,17 @@ getFreeSize(): Promise&lt;number&gt;
**系统能力**:SystemCapability.FileManagement.StorageService.SpatialStatistics **系统能力**:SystemCapability.FileManagement.StorageService.SpatialStatistics
该接口为系统接口,三方应用不支持调用 该接口为系统接口,三方应用不支持调用
- 返回值
**返回值:**
| 类型 | 说明 | | 类型 | 说明 |
| --------------------- | ------------------ | | --------------------- | ------------------ |
| Promise&lt;number&gt; | 返回内卡的可用空间大小 | | Promise&lt;number&gt; | 返回内卡的可用空间大小 |
- 示例 **示例:**
```js ```js
let number = storageStatistics.getFreeSize(); let number = storageStatistics.getFreeSize();
...@@ -351,7 +364,7 @@ getFreeSize(): Promise&lt;number&gt; ...@@ -351,7 +364,7 @@ getFreeSize(): Promise&lt;number&gt;
``` ```
## storagestatistics.getFreeSize<sup>9+</sup> ## storageStatistics.getFreeSize<sup>9+</sup>
getFreeSize(callback: AsyncCallback&lt;number&gt;): void getFreeSize(callback: AsyncCallback&lt;number&gt;): void
...@@ -361,26 +374,26 @@ getFreeSize(callback: AsyncCallback&lt;number&gt;): void ...@@ -361,26 +374,26 @@ getFreeSize(callback: AsyncCallback&lt;number&gt;): void
**系统能力**:SystemCapability.FileManagement.StorageService.SpatialStatistics **系统能力**:SystemCapability.FileManagement.StorageService.SpatialStatistics
该接口为系统接口,三方应用不支持调用 该接口为系统接口,三方应用不支持调用
- 参数
**参数:**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
| -------- | ------------------------------------ | ---- | ------------------------- | | -------- | ------------------------------------ | ---- | ------------------------- |
| callback | callback:AsyncCallback&lt;number&gt; | 是 | 获取内卡的可用空间大小之后的回调 | | callback | callback:AsyncCallback&lt;number&gt; | 是 | 获取内卡的可用空间大小之后的回调 |
- 示例 **示例:**
```js ```js
storagestatistics.getFreeSize(function(error, number){ storageStatistics.getFreeSize(function(error, number){
// do something // do something
console.info("getFreeSize successfully:"+ JSON.stringify(number)); console.info("getFreeSize successfully:"+ JSON.stringify(number));
}); });
``` ```
## storageStatistics.getSystemSize<sup>9+</sup>
## storagestatistics.getSystemSize<sup>9+</sup>
getSystemSize(): Promise&lt;number&gt; getSystemSize(): Promise&lt;number&gt;
...@@ -390,25 +403,27 @@ getSystemSize(): Promise&lt;number&gt; ...@@ -390,25 +403,27 @@ getSystemSize(): Promise&lt;number&gt;
**系统能力**:SystemCapability.FileManagement.StorageService.SpatialStatistics **系统能力**:SystemCapability.FileManagement.StorageService.SpatialStatistics
该接口为系统接口,三方应用不支持调用 该接口为系统接口,三方应用不支持调用
- 返回值
**返回值:**
| 类型 | 说明 | | 类型 | 说明 |
| --------------------- | ---------------- | | --------------------- | ---------------- |
| Promise&lt;number&gt; | 返回系统空间大小 | | Promise&lt;number&gt; | 返回系统空间大小 |
- 示例 **示例:**
```js ```js
storagestatistics.getSystemSize().then(function(number){ storageStatistics.getSystemSize().then(function(number){
console.info("getSystemSize successfully:"+ number); console.info("getSystemSize successfully:"+ number);
}).catch(function(err){ }).catch(function(err){
console.info("getSystemSize failed with error:"+ err); console.info("getSystemSize failed with error:"+ err);
}); });
``` ```
## storagestatistics.getSystemSize<sup>9+</sup> ## storageStatistics.getSystemSize<sup>9+</sup>
getSystemSize(callback:AsyncCallback&lt;number&gt;):void getSystemSize(callback:AsyncCallback&lt;number&gt;):void
...@@ -418,28 +433,28 @@ getSystemSize(callback:AsyncCallback&lt;number&gt;):void ...@@ -418,28 +433,28 @@ getSystemSize(callback:AsyncCallback&lt;number&gt;):void
**系统能力**:SystemCapability.FileManagement.StorageService.SpatialStatistics **系统能力**:SystemCapability.FileManagement.StorageService.SpatialStatistics
该接口为系统接口,三方应用不支持调用 该接口为系统接口,三方应用不支持调用
- 参数
**参数:**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
| ---------- | ------------------------------------ | ---- | -------------------------- | | ---------- | ------------------------------------ | ---- | -------------------------- |
| callback | callback:AsyncCallback&lt;number&gt; | 是 | 获取系统空间大小之后的回调 | | callback | callback:AsyncCallback&lt;number&gt; | 是 | 获取系统空间大小之后的回调 |
- 示例 **示例:**
```js ```js
storagestatistics.getSystemSize(function(error, number){ storageStatistics.getSystemSize(function(error, number){
// do something // do something
console.info("getSystemSize successfully:"+ number); console.info("getSystemSize successfully:"+ number);
}); });
``` ```
## storageStatistics.getUserStorageStats<sup>9+</sup>
getUserStorageStats(userId? : number): Promise&lt;StorageStats&gt;
## storagestatistics.getUserStorageStats<sup>9+</sup>
getUserStorageStats(userId: number): Promise&lt;StorageStats&gt;
异步获取用户各类别数据大小,以promise方式返回。 异步获取用户各类别数据大小,以promise方式返回。
...@@ -447,32 +462,34 @@ getUserStorageStats(userId: number): Promise&lt;StorageStats&gt; ...@@ -447,32 +462,34 @@ getUserStorageStats(userId: number): Promise&lt;StorageStats&gt;
**系统能力**:SystemCapability.FileManagement.StorageService.SpatialStatistics **系统能力**:SystemCapability.FileManagement.StorageService.SpatialStatistics
该接口为系统接口,三方应用不支持调用 该接口为系统接口,三方应用不支持调用
- 参数
**参数:**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
| ---------- | ------ | ---- | ---- | | ---------- | ------ | ---- | ---- |
| userId | string | 否 | 用户id <br/>确认当前用户:<br/>-&nbsp;有值:表示指定用户。<br/>-&nbsp;无值:表示当前用户。| | userId | string | 否 | 用户id <br/>确认当前用户:<br/>-&nbsp;有值:表示指定用户。<br/>-&nbsp;无值:表示当前用户。|
- 返回值 **返回值:**
| 类型 | 说明 | | 类型 | 说明 |
| --------------------- | ---------------- | | --------------------- | ---------------- |
| Promise&lt;[StorageStats](#StorageStats)&gt; | 返回各类别数据大小 | | Promise&lt;[StorageStats](#StorageStats)&gt; | 返回各类别数据大小 |
- 示例 **示例:**
```js ```js
let userId = ""; let userId = "";
storagestatistics.getUserStorageStats(userId).then(function(StorageStats){ storageStatistics.getUserStorageStats(userId).then(function(StorageStats){
console.info("getUserStorageStats successfully:"+ JSON.stringify(StorageStats)); console.info("getUserStorageStats successfully:"+ JSON.stringify(StorageStats));
}).catch(function(err){ }).catch(function(err){
console.info("getUserStorageStats failed with error:"+ err); console.info("getUserStorageStats failed with error:"+ err);
}); });
``` ```
## storagestatistics.getUserStorageStats<sup>9+</sup> ## storageStatistics.getUserStorageStats<sup>9+</sup>
getUserStorageStats(userId: number, callback:AsyncCallback&lt;StorageStats&gt;):void getUserStorageStats(userId: number, callback:AsyncCallback&lt;StorageStats&gt;):void
...@@ -482,32 +499,37 @@ getUserStorageStats(userId: number, callback:AsyncCallback&lt;StorageStats&gt;): ...@@ -482,32 +499,37 @@ getUserStorageStats(userId: number, callback:AsyncCallback&lt;StorageStats&gt;):
**系统能力**:SystemCapability.FileManagement.StorageService.SpatialStatistics **系统能力**:SystemCapability.FileManagement.StorageService.SpatialStatistics
该接口为系统接口,三方应用不支持调用 该接口为系统接口,三方应用不支持调用
- 参数
**参数:**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
| ---------- | ------------------------------------ | ---- | -------------------------- | | ---------- | ------------------------------------ | ---- | -------------------------- |
| userId | string | 否 | 用户id <br/>确认当前用户:<br/>-&nbsp;有值:表示指定用户。<br/>-&nbsp;无值:表示当前用户。 | | userId | string | 否 | 用户id <br/>确认当前用户:<br/>-&nbsp;有值:表示指定用户。<br/>-&nbsp;无值:表示当前用户。 |
| callback | callback:AsyncCallback&lt;[StorageStats](#StorageStats)&gt; | 是 | 返回各类别数据大小之后的回调 | | callback | callback:AsyncCallback&lt;[StorageStats](#StorageStats)&gt; | 是 | 返回各类别数据大小之后的回调 |
- 示例 **示例:**
```js ```js
let userId = ""; let userId = "";
storagestatistics.getUserStorageStats(userId, function(error, StorageStats){ storageStatistics.getUserStorageStats(userId, function(error, StorageStats){
// do something // do something
console.info("getUserStorageStats successfully:"+ JSON.stringify(StorageStats)); console.info("getUserStorageStats successfully:"+ JSON.stringify(StorageStats));
}); });
``` ```
## StorageStats<sup>9+</sup> ## StorageStats<sup>9+</sup>
**系统能力**:以下各项对应的系统能力均为SystemCapability.FileManagement.StorageService.SpatialStatistics。<br> **系统能力**:以下各项对应的系统能力均为SystemCapability.FileManagement.StorageService.SpatialStatistics
该接口为系统接口,三方应用不支持调用 该接口为系统接口,三方应用不支持调用
- 属性
### 属性
| 名称 | 类型 | 说明 | | 名称 | 类型 | 说明 |
| --------- | ------ | -------------- | | --------- | ------ | -------------- |
......
# USB管理 # USB管理
本模块主要提供管理USB设备的相关功能,包括查询USB设备列表、批量数据传输、控制命令传输、权限控制等。
> **说明:** > **说明:**
>
> 本模块首批接口从API version 8开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。 > 本模块首批接口从API version 8开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。
## 导入模块 ## 导入模块
......
# webgl # WebGL
WebGL提供图形绘制的能力,包括对当前绘制图形的位置、颜色等进行处理。
WebGL标准图形API,对应OpenGL ES 2.0特性集。更多信息请参考[WebGL™标准](https://www.khronos.org/registry/webgl/specs/latest/1.0/)
> **说明:** > **说明:**
>
> 本模块首批接口从API version 7开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。 > 本模块首批接口从API version 7开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。
WebGL标准图形API,对应OpenGL ES 2.0特性集。更多信息请参考[WebGL™标准](https://www.khronos.org/registry/webgl/specs/latest/1.0/)
## 调用方式 ## 调用方式
......
# webgl2 # WebGL2
WebGL2支持图形的绘制,包括对当前绘制图形的位置、颜色等进行处理,其中相对WebGL来说对渲染管道和着色语言进行了增强。
WebGL标准图形API,对应OpenGL ES 3.0特性集。更多信息请参考[WebGL™标准](https://www.khronos.org/registry/webgl/specs/latest/2.0/)
> **说明:** > **说明:**
>
> 本模块首批接口从API version 7开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。 > 本模块首批接口从API version 7开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。
WebGL标准图形API,对应OpenGL ES 3.0特性集。更多信息请参考[WebGL™标准](https://www.khronos.org/registry/webgl/specs/latest/2.0/)
## 调用方式 ## 调用方式
......
...@@ -33,10 +33,10 @@ Image(src: string | PixelMap | Resource) ...@@ -33,10 +33,10 @@ Image(src: string | PixelMap | Resource)
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| alt | string | - | 加载时显示的占位图。支持本地图片和网络路径。 | | alt | string | - | 加载时显示的占位图。支持本地图片和网络路径。 |
| objectFit | ImageFit | Cover | 设置图片的缩放类型。 | | objectFit | ImageFit | Cover | 设置图片的缩放类型。 |
| objectRepeat | [ImageRepeat](ts-appendix-enums.md#imagerepeat枚举说明) | NoRepeat | 设置图片的重复样式。<br/>>&nbsp;![icon-note.gif](public_sys-resources/icon-note.gif)&nbsp;**说明:**<br/>>&nbsp;-&nbsp;SVG类型图源不支持该属性。 | | objectRepeat | [ImageRepeat](ts-appendix-enums.md#imagerepeat枚举说明) | NoRepeat | 设置图片的重复样式。<br/>>&nbsp;![icon-note.gif](public_sys-resources/icon-note.gif)&nbsp;**说明:**<br/>>&nbsp;-&nbsp;svg类型图源不支持该属性。 |
| interpolation | ImageInterpolation | None | 设置图片的插值效果,仅针对图片放大插值。<br/>>&nbsp;![icon-note.gif](public_sys-resources/icon-note.gif)&nbsp;**说明:**<br/>>&nbsp;-&nbsp;SVG类型图源不支持该属性。<br/>>&nbsp;<br/>>&nbsp;-&nbsp;PixelMap资源不支持该属性。 | | interpolation | ImageInterpolation | None | 设置图片的插值效果,仅针对图片放大插值。<br/>>&nbsp;![icon-note.gif](public_sys-resources/icon-note.gif)&nbsp;**说明:**<br/>>&nbsp;-&nbsp;svg类型图源不支持该属性。<br/>>&nbsp;-&nbsp;PixelMap资源不支持该属性。 |
| renderMode | ImageRenderMode | Original | 设置图片渲染的模式。<br/>>&nbsp;![icon-note.gif](public_sys-resources/icon-note.gif)&nbsp;**说明:**<br/>>&nbsp;-&nbsp;SVG类型图源不支持该属性。 | | renderMode | ImageRenderMode | Original | 设置图片渲染的模式。<br/>>&nbsp;![icon-note.gif](public_sys-resources/icon-note.gif)&nbsp;**说明:**<br/>>&nbsp;-&nbsp;svg类型图源不支持该属性。 |
| sourceSize | {<br/>width:&nbsp;number,<br/>height:&nbsp;number<br/>} | - | 设置图片解码尺寸,将原始图片解码成指定尺寸的图片,number类型单位为px。<br/>>&nbsp;![icon-note.gif](public_sys-resources/icon-note.gif)&nbsp;**说明:**<br/>>&nbsp;PixelMap资源不支持该属性。 | | sourceSize | {<br/>width:&nbsp;number,<br/>height:&nbsp;number<br/>} | - | 设置图片解码尺寸,将原始图片解码成指定尺寸的图片,number类型单位为px。<br/>>&nbsp;![icon-note.gif](public_sys-resources/icon-note.gif)&nbsp;**说明:**<br/>>&nbsp;-&nbsp;PixelMap资源不支持该属性。 |
| syncLoad<sup>8+</sup> | boolean | false | 设置是否同步加载图片,默认是异步加载。同步加载时阻塞UI线程,不会显示占位图。 | | syncLoad<sup>8+</sup> | boolean | false | 设置是否同步加载图片,默认是异步加载。同步加载时阻塞UI线程,不会显示占位图。 |
- ImageFit枚举说明 - ImageFit枚举说明
......
...@@ -15,7 +15,7 @@ ...@@ -15,7 +15,7 @@
## 接口 ## 接口
Refresh\(value: \{refreshing: boolean, offset?: Length, friction?: number\}\) Refresh\(value: \{refreshing: boolean, offset?: Length, friction?: number | string\}\)
- 参数 - 参数
...@@ -23,7 +23,7 @@ Refresh\(value: \{refreshing: boolean, offset?: Length, friction?: number\}\) ...@@ -23,7 +23,7 @@ Refresh\(value: \{refreshing: boolean, offset?: Length, friction?: number\}\)
| -------- | -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- | -------- |
| refreshing | boolean | 是 | - | 当前组件是否正在刷新。 | | refreshing | boolean | 是 | - | 当前组件是否正在刷新。 |
| offset | Length | 否 | 16 | 刷新组件静止时距离父组件顶部的距离。| | offset | Length | 否 | 16 | 刷新组件静止时距离父组件顶部的距离。|
| friction | number | 否 | 62 | 下拉摩擦系数,取值范围为0到100。<br/>-&nbsp;0表示下拉刷新容器不跟随手势下拉而下拉。<br/>-&nbsp;100表示下拉刷新容器紧紧跟随手势下拉而下拉。<br/>-&nbsp;数值越大,下拉刷新容器跟随手势下拉的反应越灵敏。 | | friction | number&nbsp;\|&nbsp;string | 否 | 62 | 下拉摩擦系数,取值范围为0到100。<br/>-&nbsp;0表示下拉刷新容器不跟随手势下拉而下拉。<br/>-&nbsp;100表示下拉刷新容器紧紧跟随手势下拉而下拉。<br/>-&nbsp;数值越大,下拉刷新容器跟随手势下拉的反应越灵敏。 |
......
...@@ -165,7 +165,6 @@ struct VideoCreateComponent { ...@@ -165,7 +165,6 @@ struct VideoCreateComponent {
@State autoPlays: boolean = false; @State autoPlays: boolean = false;
@State controlsss: boolean = true; @State controlsss: boolean = true;
controller: VideoController = new VideoController(); controller: VideoController = new VideoController();
@State startStaus: boolean = true;
build() { build() {
Column() { Column() {
Video({ Video({
......
...@@ -29,8 +29,6 @@ ...@@ -29,8 +29,6 @@
@Entry @Entry
@Component @Component
struct SharedTransitionExample { struct SharedTransitionExample {
@State scale: number = 1
@State opacity: number = 1
@State active: boolean = false @State active: boolean = false
build() { build() {
......
# HiCollie开发指导<a name="ZH-CN_TOPIC_0000001231255509"></a> # HiCollie开发指导<a name="ZH-CN_TOPIC_0000001231255509"></a>
- [概述](#section3432134085116)
- [接口说明](#section139261151145116)
- [效果](#section1589120102458)
- [开发实例](#section13905646534)
- [C++接口开发实例](#section9797199145316)
- [线程卡死监控](#section1734221332)
- [超时监控](#section2186947140)
## 概述<a name="section3432134085116"></a> ## 概述<a name="section3432134085116"></a>
......
# HiLog\_Lite开发指导<a name="ZH-CN_TOPIC_0000001185815838"></a> # HiLog\_Lite开发指导<a name="ZH-CN_TOPIC_0000001185815838"></a>
- [概述](#section775017517390)
- [接口说明](#section114412157402)
- [开发实例](#section1482812550419)
## 概述<a name="section775017517390"></a> ## 概述<a name="section775017517390"></a>
......
# HiSysEvent订阅指导<a name="ZH-CN_TOPIC_0000001185655868"></a> # HiSysEvent订阅指导<a name="ZH-CN_TOPIC_0000001185655868"></a>
- [概述](#section315316685112)
- [功能简介](#section123181433335224)
- [约束与限制](#section123181433375224)
- [开发指导](#section315316685113)
- [接口说明](#section0342191810519)
- [开发实例](#section123181432175110)
## 概述<a name="section315316685112"></a> ## 概述<a name="section315316685112"></a>
......
# HiSysEvent查询指导<a name="ZH-CN_TOPIC_0000001231455461"></a> # HiSysEvent查询指导<a name="ZH-CN_TOPIC_0000001231455461"></a>
- [概述](#section279684125212)
- [开发指导](#section315316761113)
- [接口说明](#section03869128521)
- [开发实例](#section14286111855212)
## 概述<a name="section279684125212"></a> ## 概述<a name="section279684125212"></a>
......
# HiSysEvent工具使用指导<a name="ZH-CN_TOPIC_0000001231614021"></a> # HiSysEvent工具使用指导<a name="ZH-CN_TOPIC_0000001231614021"></a>
- [概述](#section1886702718521)
- [实时订阅HiSysEvent事件相关命令](#section1210623418527)
- [查询历史HiSysEvent事件相关命令](#section1210623418539)
## 概述<a name="section1886702718521"></a> ## 概述<a name="section1886702718521"></a>
......
# HiTrace开发指导<a name="ZH-CN_TOPIC_0000001186134310"></a> # HiTrace开发指导<a name="ZH-CN_TOPIC_0000001186134310"></a>
- [概述](#section3986195420436)
- [应用场景](#section134561822574)
- [业务使用示例](#section63861653124417)
- [接口说明](#section1517945334617)
- [接口形式对比](#section932504474)
- [接口功能参数](#section2514638125)
- [通信调用处理](#section11257133933)
- [开发实例](#section14310412491)
- [C++接口实例](#section114916381509)
- [C接口实例](#section108292107514)
## 概述<a name="section3986195420436"></a> ## 概述<a name="section3986195420436"></a>
......
# DFX概述<a name="ZH-CN_TOPIC_0000001185974398"></a> # DFX概述<a name="ZH-CN_TOPIC_0000001185974398"></a>
- [基本概念](#section5635178134811)
在OpenHarmony中,DFX\([Design for X](https://en.wikipedia.org/wiki/Design_for_X)\)是为了提升质量属性的软件设计,目前包含的内容主要有:DFR(Design for Reliability,可靠性)和DFT(Design for Testability,可测试性)特性。 在OpenHarmony中,DFX\([Design for X](https://en.wikipedia.org/wiki/Design_for_X)\)是为了提升质量属性的软件设计,目前包含的内容主要有:DFR(Design for Reliability,可靠性)和DFT(Design for Testability,可测试性)特性。
......
# 动画开发指导<a name="ZH-CN_TOPIC_0000001051451654"></a> # 动画开发指导<a name="ZH-CN_TOPIC_0000001051451654"></a>
- [使用场景](#section726685714018)
- [接口说明](#section85794718418)
- [开发步骤](#section14101161317435)
## 使用场景<a name="section726685714018"></a> ## 使用场景<a name="section726685714018"></a>
UI动画通过task处理机制每个tick调用一下用户设置的callback函数来实现,具体实现为AnimatorManager、Animator、AnimatorCallback三个类实现。 UI动画通过task处理机制每个tick调用一下用户设置的callback函数来实现,具体实现为AnimatorManager、Animator、AnimatorCallback三个类实现。
......
# 普通组件开发指导<a name="ZH-CN_TOPIC_0000001052170409"></a> # 普通组件开发指导<a name="ZH-CN_TOPIC_0000001052170409"></a>
- [UIButton](#section145353310214)
- [使用场景](#section1169616141577)
- [接口说明](#section341211538315)
- [开发步骤](#section22501726193214)
- [UIImageView](#section19523161611259)
- [使用场景](#section1274484210400)
- [接口说明](#section74981992411)
- [开发步骤(自适应)](#section144341333134114)
- [开发步骤(平铺模式)](#section97178160421)
- [UILabel](#section16588132012911)
- [使用场景](#section6870195634218)
- [接口说明](#section2012714510433)
- [开发步骤(默认模式)](#section83221538114410)
- [开发步骤(背景色和透明度)](#section933360204510)
- [开发步骤(字符间距)](#section19447826124518)
- [开发步骤(大小自适应)](#section101711842154617)
- [开发步骤(省略号模式)](#section1249519410471)
- [开发步骤(滚动模式)](#section15643122618478)
普通组件均继承于基类UIView,不可以添加子组件,常用的普通组件有button、image、label等。 普通组件均继承于基类UIView,不可以添加子组件,常用的普通组件有button、image、label等。
......
# 容器类组件开发指导<a name="ZH-CN_TOPIC_0000001052810390"></a> # 容器类组件开发指导<a name="ZH-CN_TOPIC_0000001052810390"></a>
- [UIViewGroup](#section145471898812)
- [使用场景](#section0916112362216)
- [接口说明](#section12641756192212)
- [开发步骤](#section5412161692311)
- [UIScrollView](#section174961523161315)
- [使用场景](#section8937101902413)
- [接口说明](#section14789133142420)
- [开发步骤](#section1769754422417)
容器类组件,指能包含其它UI组件的组件,容器类组件继承于UIViewGroup(带Add方法),基于实际组件的使用场景,将需要增加其他子组件的组件,放置到容器类继承结构下。如UIAnalogClock内,通常会Add需要的计步信息,时分秒图标等。 容器类组件,指能包含其它UI组件的组件,容器类组件继承于UIViewGroup(带Add方法),基于实际组件的使用场景,将需要增加其他子组件的组件,放置到容器类继承结构下。如UIAnalogClock内,通常会Add需要的计步信息,时分秒图标等。
......
# 布局容器类组件开发指导<a name="ZH-CN_TOPIC_0000001052661991"></a> # 布局容器类组件开发指导<a name="ZH-CN_TOPIC_0000001052661991"></a>
- [UISwipeView](#section13631719181717)
- [使用场景](#section11299120102617)
- [接口说明](#section767434119261)
- [开发步骤(水平滑动,不可循环)](#section111911175287)
- [开发步骤(水平滑动,可循环)](#section1976914915282)
- [GridLayout](#section46819199173)
- [使用场景](#section831618247294)
- [接口说明](#section597214622912)
- [开发步骤](#section1418253410306)
布局类容器组件由视图基础类组成,通过直接设置视图位置,可以达到嵌套和重叠布局的目的;通过设置布局类型和边距达到规格化布局子组件的目的;通过调用相关接口可实现根据父组件及兄弟节点布局视图的目的。 布局类容器组件由视图基础类组成,通过直接设置视图位置,可以达到嵌套和重叠布局的目的;通过设置布局类型和边距达到规格化布局子组件的目的;通过调用相关接口可实现根据父组件及兄弟节点布局视图的目的。
......
# 图形图像概述<a name="ZH-CN_TOPIC_0000001051770388"></a> # 图形图像概述<a name="ZH-CN_TOPIC_0000001051770388"></a>
- [UI组件](#section1987017145112)
- [布局](#section662016231612)
- [动画](#section73736284117)
- [Input事件](#section672194012114)
- [渲染](#section14338859916)
OpenHarmony图形系统,提供基础UI组件和容器类组件,包括button、image、label、list、animator、scroll view、swipe view、font、clock、chart、canvas、slider、layout等。同时提供截屏、导出组件树的DFX能力。模块内部实现组件渲染、动画、输入事件分发等功能。 OpenHarmony图形系统,提供基础UI组件和容器类组件,包括button、image、label、list、animator、scroll view、swipe view、font、clock、chart、canvas、slider、layout等。同时提供截屏、导出组件树的DFX能力。模块内部实现组件渲染、动画、输入事件分发等功能。
......
# 相机开发概述<a name="ZH-CN_TOPIC_0000001051690589"></a> # 相机开发概述<a name="ZH-CN_TOPIC_0000001051690589"></a>
- [基本概念](#section175012297491)
- [运作机制](#section193961322175011)
## 基本概念<a name="section175012297491"></a> ## 基本概念<a name="section175012297491"></a>
相机是OpenHarmony多媒体进程提供的服务之一,提供了相机的录像、预览、拍照功能,支持多用户并发取流。 相机是OpenHarmony多媒体进程提供的服务之一,提供了相机的录像、预览、拍照功能,支持多用户并发取流。
......
# 拍照开发指导<a name="ZH-CN_TOPIC_0000001052170554"></a> # 拍照开发指导<a name="ZH-CN_TOPIC_0000001052170554"></a>
- [使用场景](#section1963312376119)
- [接口说明](#section56549532016)
- [约束与限制](#section1165911177314)
- [开发步骤](#section138543918214)
## 使用场景<a name="section1963312376119"></a> ## 使用场景<a name="section1963312376119"></a>
......
# 预览开发指导<a name="ZH-CN_TOPIC_0000001051930577"></a> # 预览开发指导<a name="ZH-CN_TOPIC_0000001051930577"></a>
- [使用场景](#section186634310418)
- [接口说明](#section125479541744)
- [约束与限制](#section1165911177314)
- [开发步骤](#section34171333656)
## 使用场景<a name="section186634310418"></a> ## 使用场景<a name="section186634310418"></a>
......
# 录像开发指导<a name="ZH-CN_TOPIC_0000001051451869"></a> # 录像开发指导<a name="ZH-CN_TOPIC_0000001051451869"></a>
- [使用场景](#section186634310418)
- [接口说明](#section125479541744)
- [约束与限制](#section1165911177314)
- [开发步骤](#section1196016315516)
## 使用场景<a name="section186634310418"></a> ## 使用场景<a name="section186634310418"></a>
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册