diff --git a/CODEOWNERS b/CODEOWNERS index 9b36e3beb739abd5f7bd294dfb149297e93c0651..9ffdaf23ba7351b7dd5e18b54559e424f4a2b80a 100644 --- a/CODEOWNERS +++ b/CODEOWNERS @@ -317,6 +317,7 @@ zh-cn/application-dev/reference/apis/js-apis-system-parameter.md @qinxiaowang zh-cn/application-dev/reference/apis/js-apis-thermal.md @qinxiaowang zh-cn/application-dev/reference/apis/js-apis-update.md @HelloCrease zh-cn/application-dev/reference/apis/js-apis-usb.md @ge-yafang +zh-cn/application-dev/reference/apis/js-apis-colorSpaceManager.mdd @ge-yafang zh-cn/application-dev/reference/apis/js-apis-vibrator.md @HelloCrease zh-cn/application-dev/reference/apis/js-apis-appAccount.md @zengyawen zh-cn/application-dev/reference/apis/js-apis-distributed-account.md @zengyawen diff --git a/en/application-dev/Readme-EN.md b/en/application-dev/Readme-EN.md index bd194e23cf6c4715dfbc6fa9af0b2b273d2e8478..f3fa0e7ac0e9b829f2418e4b1bf96001e66553d2 100644 --- a/en/application-dev/Readme-EN.md +++ b/en/application-dev/Readme-EN.md @@ -37,7 +37,7 @@ - Tools - [DevEco Studio (OpenHarmony) User Guide](quick-start/deveco-studio-user-guide-for-openharmony.md) - Hands-On Tutorials - - [Samples](https://gitee.com/openharmony/app_samples/blob/master/README.md) + - [Samples](https://gitee.com/openharmony/applications_app_samples/blob/master/README.md) - [Codelabs](https://gitee.com/openharmony/codelabs) - API References - [Component Reference (JavaScript-based Web-like Development Paradigm)](reference/arkui-js/Readme-EN.md) diff --git a/en/application-dev/ability/stage-ability-continuation.md b/en/application-dev/ability/stage-ability-continuation.md index 6945f49db8ef05109452fc1b3dcad3dc1e5ddeca..701b730a833a7b97f00398746cddae4d2856a248 100644 --- a/en/application-dev/ability/stage-ability-continuation.md +++ b/en/application-dev/ability/stage-ability-continuation.md @@ -41,7 +41,7 @@ The code snippets provided below are all from [Sample](https://gitee.com/openhar "module": { "abilities": [ { - "continuable": true, + "continuable": true } ] } @@ -62,7 +62,7 @@ The code snippets provided below are all from [Sample](https://gitee.com/openhar "module": { "abilities": [ { - "launchType": "standard", + "launchType": "standard" } ] } @@ -76,7 +76,7 @@ The code snippets provided below are all from [Sample](https://gitee.com/openhar "module": { "abilities": [ { - "launchType": "singleton", + "launchType": "singleton" } ] } diff --git a/en/application-dev/ability/wantagent.md b/en/application-dev/ability/wantagent.md index eacc92936960cca3bd022e6438a63c15a8f2688a..5a85bab15b8422aaabb0a173ad888126e08fc038 100644 --- a/en/application-dev/ability/wantagent.md +++ b/en/application-dev/ability/wantagent.md @@ -1,6 +1,8 @@ # WantAgent Development ## When to Use -The **WantAgent** class encapsulates want information that specifies a particular action, which can be starting an ability or publishing a common event. You can either call **wantAgent.trigger** to trigger a **WantAgent** directly or add a **WantAgent** to a notification so that it will be triggered when users tap the notification. +The **WantAgent** class encapsulates want information that specifies a particular action, which can be starting an ability or publishing a common event. You can either call **wantAgent.trigger** to trigger a **WantAgent** directly or add a **WantAgent** to a notification so that it will be triggered when users tap the notification. + + ## Available APIs | API | Description| @@ -21,7 +23,7 @@ The **WantAgent** class encapsulates want information that specifies a particula ``` private wantAgentObj = null // Save the WantAgent object created. It will be used to complete the trigger operations. - //wantAgentInfo + // wantAgentInfo var wantAgentInfo = { wants: [ { @@ -45,7 +47,7 @@ The **WantAgent** class encapsulates want information that specifies a particula ``` private wantAgentObj = null // Save the WantAgent object created. It will be used to complete the trigger operations. - //wantAgentInfo + // wantAgentInfo var wantAgentInfo = { wants: [ { diff --git a/en/application-dev/application-dev-guide-for-gitee.md b/en/application-dev/application-dev-guide-for-gitee.md index e60f2c01333c1bef7324b3ef6cfe2c83821a95cd..f074e1906535d708b193adea3b1ee3308fb0de4e 100644 --- a/en/application-dev/application-dev-guide-for-gitee.md +++ b/en/application-dev/application-dev-guide-for-gitee.md @@ -47,7 +47,7 @@ DevEco Studio is a high-performance integrated development environment (IDE) rec ### Hands-On Tutorials -To make you better understand how functions work together and jumpstart your application development projects, we provide stripped-down, real-world [samples](https://gitee.com/openharmony/app_samples/blob/master/README.md) and [codelabs](https://gitee.com/openharmony/codelabs). +To make you better understand how functions work together and jumpstart your application development projects, we provide stripped-down, real-world [samples](https://gitee.com/openharmony/applications_app_samples/blob/master/README.md) and [codelabs](https://gitee.com/openharmony/codelabs). ### API References diff --git a/en/application-dev/application-dev-guide.md b/en/application-dev/application-dev-guide.md index 7065480d1c4a12bd0984f4916d678c1bed7a4997..2b22839820539e2919f1a705595a47cc491df8d0 100644 --- a/en/application-dev/application-dev-guide.md +++ b/en/application-dev/application-dev-guide.md @@ -47,7 +47,7 @@ DevEco Studio is a high-performance integrated development environment (IDE) rec ### Hands-On Tutorials -To make you better understand how functions work together and jumpstart your application development projects, we provide stripped-down, real-world [samples](https://gitee.com/openharmony/app_samples/blob/master/README.md) and [codelabs](https://gitee.com/openharmony/codelabs). +To make you better understand how functions work together and jumpstart your application development projects, we provide stripped-down, real-world [samples](https://gitee.com/openharmony/applications_app_samples/blob/master/README.md) and [codelabs](https://gitee.com/openharmony/codelabs). ### API References diff --git a/en/application-dev/database/database-distributedobject-guidelines.md b/en/application-dev/database/database-distributedobject-guidelines.md index 8cc0a8aca0a6b8f6fad3f1a03f452e8ea9d3eb97..ec77d5330b57751e36b3ba2d96b57028c340dd36 100644 --- a/en/application-dev/database/database-distributedobject-guidelines.md +++ b/en/application-dev/database/database-distributedobject-guidelines.md @@ -4,7 +4,7 @@ The **distributedDataObject** module provides APIs to implement data collaboration of the same application across multiple devices. In addition, the devices that form a Super Device can listen for object status and data changes with each other. -For example, when the data of the a distributed data object is added, deleted, or modified for application A on device 1, application A on device 2 can obtain the updated data. In addition, device 2 can listen for data changes and online/offline of the data objects on device 1. +For example, when the data of a distributed data object is added, deleted, or modified for application A on device 1, application A on device 2 can obtain the updated data. In addition, device 2 can listen for data changes and online/offline of the data objects on device 1. ## Available APIs @@ -18,7 +18,7 @@ Call **createDistributedObject()** to create a distributed data object instance. **Table 1** API for creating a distributed data object instance | Package| API| Description| | -------- | -------- | -------- | -| ohos.data.distributedDataObject| createDistributedObject(source: object): DistributedObject | Creates a distributed data object instance for data operations.
- **source**: attributes of the **distributedObject** set.
- **DistributedObject**: returns the distributed object created.| +| ohos.data.distributedDataObject| createDistributedObject(source: object): DistributedObject | Creates a distributed data object instance for data operations.
- **source**: attributes of the distributed data object to set.
- **DistributedObject**: returns the distributed data object created. | ### Generating a Session ID @@ -29,14 +29,14 @@ Call **genSessionId()** to generate a session ID randomly. The generated session | -------- | -------- | -------- | | ohos.data.distributedDataObject| genSessionId(): string | Generates a session ID, which can be used as the session ID of a distributed data object.| -### Setting a SessionID for a Distributed Data Object +### Setting a Session ID for a Distributed Data Object Call **setSessionId()** to set a session ID for a distributed data object. The session ID is a unique identifier for one collaboration across devices. The distributed data objects to be synchronized must be associated with the same session ID. **Table 3** API for setting a session ID | Class| API| Description| | -------- | -------- | -------- | -| DistributedDataObject | setSessionId(sessionId?: string): boolean | Sets a session ID for a distributed data object.
**sessionId**: session ID of a distributed object in a trusted network. To remove a distributed data object from the network, set this parameter to "" or leave it empty.| +| DistributedDataObject | setSessionId(sessionId?: string): boolean | Sets a session ID for a distributed data object.
**sessionId**: session ID of a distributed data object in a trusted network. To remove a distributed data object from the network, set this parameter to "" or leave it empty. | ### Observing Data Changes @@ -47,7 +47,7 @@ Call **on()** to subscribe to data changes of a distributed data object. When th | Class| API| Description| | -------- | -------- | -------- | | DistributedDataObject| on(type: 'change', callback: Callback<{ sessionId: string, fields: Array<string> }>): void | Subscribes to data changes.| -| DistributedDataObject| off(type: 'change', callback?: Callback<{ sessionId: string, fields: Array<string> }>): void | Unsubscribes from data changes. **Callback**: specifies the data changes to unsubscribe from. If this parameter is not specified, all data changes of this distributed data object will be unsubscribed from.| +| DistributedDataObject| off(type: 'change', callback?: Callback<{ sessionId: string, fields: Array<string> }>): void | Unsubscribes from data changes.
**Callback**: callback to unregister. If this parameter is not specified, all data changes of this distributed data object will be unsubscribed from. | ### Observing Online or Offline Status @@ -59,7 +59,7 @@ Call **on()** to subscribe to status changes of a distributed data object. The s | DistributedDataObject| on(type: 'status', callback: Callback<{ sessionId: string, networkId: string, status: 'online' \| 'offline' }>): void | Subscribes to the status changes of a distributed data object.| | DistributedDataObject| off(type: 'status', callback?: Callback<{ sessionId: string, deviceId: string, status: 'online' \| 'offline' }>): void | Unsubscribes from status changes of a distributed data object.| -### Saving a Distributed Data Object and Revoking the Data Saving Operation +### Saving or Deleting a Distributed Data Object Call **save()** to save a distributed data object. When the application is active, the saved data will not be released. When the application exits and restarts, the data saved on the device will be restored. @@ -71,11 +71,12 @@ The saved data will be released in the following cases: - The application has been uninstalled. - Data is successfully restored. -**Table 6** APIs for saving a distributed data object and revoking the saving operation +**Table 6** APIs for saving and deleting a distributed data object + | Class| API| Description| | -------- | -------- | -------- | | DistributedDataObject | save(deviceId: string): Promise<SaveSuccessResponse> | Saves a distributed data object.| -| DistributedDataObject| revokeSave(): Promise<RevokeSaveSuccessResponse> | Revokes the data saving operation.| +| DistributedDataObject| revokeSave(): Promise<RevokeSaveSuccessResponse> | Deletes a distributed data object. | ## How to Develop @@ -89,12 +90,10 @@ The following example shows how to implement distributed data object synchroniza 2. Apply for the permission. - Add the required permission (FA model) in the **config.json** file. + Add the permissions required (FA model) to the **config.json** file. The sample code is as follows: - The sample code is as follows: - - ```json - { + ```json + { "module": { "reqPermissions": [ { @@ -103,30 +102,27 @@ The following example shows how to implement distributed data object synchroniza ] } } - ``` - + ``` For the apps based on the stage model, see [Declaring Permissions](../security/accesstoken-guidelines.md#stage-model). - + This permission must also be granted by the user when the application is started for the first time. The sample code is as follows: - - ```json + + ```js import featureAbility from '@ohos.ability.featureAbility'; - - function grantPermission() { - console.info('grantPermission'); - let context = featureAbility.getContext(); - context.requestPermissionsFromUser(['ohos.permission.DISTRIBUTED_DATASYNC'], 666, function (result) { - console.info(`result.requestCode=${result.requestCode}`) - - }) - console.info('end grantPermission'); - } - - grantPermission(); - ``` - + + function grantPermission() { + console.info('grantPermission'); + let context = featureAbility.getContext(); + context.requestPermissionsFromUser(['ohos.permission.DISTRIBUTED_DATASYNC'], 666, function (result) { + console.info(`result.requestCode=${result.requestCode}`) + + }) + console.info('end grantPermission'); + } + + grantPermission(); + ``` - 3. Obtain a distributed data object instance. The sample code is as follows: @@ -142,12 +138,10 @@ The following example shows how to implement distributed data object synchroniza var sessionId = distributedObject.genSessionId(); ``` -4. Add the distributed data object instance to the synchronization network. +4. Add the distributed data object instance to a network for data synchronization. The data objects in the synchronization network include the local and remote objects. - The data objects in the synchronization network include the local and remote objects. - The sample code is as follows: - + ```js // Local object var local_object = distributedObject.createDistributedObject({ @@ -167,16 +161,16 @@ The following example shows how to implement distributed data object synchroniza parent: undefined, list: undefined }); - // After learning that the device goes online, the remote object synchronizes data. That is, name changes to jack and age to 18. + // After learning that the local device goes online, the remote object synchronizes data. That is, name changes to jack and age to 18. remote_object.setSessionId(sessionId); ``` 5. Observe the data changes of the distributed data object. You can subscribe to data changes of the remote object. When the data in the remote object changes, a callback will be called to return the data changes. - + The sample code is as follows: - + ```js function changeCallback(sessionId, changeData) { console.info("change" + sessionId); @@ -185,13 +179,13 @@ The following example shows how to implement distributed data object synchroniza changeData.forEach(element => { console.info("changed !" + element + " " + local_object[element]); }); - } + } } // To refresh the page in changeCallback, correctly bind (this) to the changeCallback. local_object.on("change", this.changeCallback.bind(this)); ``` - + 6. Modify attributes of the distributed data object. The object attributes support basic data types (such as number, Boolean, and string) and complex data types (array and nested basic types). @@ -250,7 +244,7 @@ The following example shows how to implement distributed data object synchroniza local_object.on("status", this.statusCallback); ``` -10. Save a distributed data object and revoke the data saving operation. +10. Save a distributed data object and delete it. ```js // Save a distributed data object. @@ -261,7 +255,7 @@ The following example shows how to implement distributed data object synchroniza }, (result) => { console.info("save local failed."); }); - // Revoke the data saving operation. + // Delete a distributed data object.. g_object.revokeSave().then((result) => { console.info("revokeSave success."); }, (result) => { @@ -271,7 +265,7 @@ The following example shows how to implement distributed data object synchroniza 11. Unsubscribe from the status changes of the distributed data object. - You can specify the callback to unregister. If you do not specify the callback, this API unregisters all status change callbacks of this distributed data object. + You can specify the callback to unregister. If you do not specify the callback, all status change callbacks of this distributed data object will be unregistered. The sample code is as follows: @@ -282,9 +276,7 @@ The following example shows how to implement distributed data object synchroniza local_object.off("status"); ``` -12. Remove a distributed data object from the synchronization network. - - Data changes on the local object will not be synchronized to the removed distributed data object. +12. Remove a distributed data object from the synchronization network. Data changes on the local object will not be synchronized to the removed distributed data object. The sample code is as follows: diff --git a/en/application-dev/device-usage-statistics/device-usage-statistics-overview.md b/en/application-dev/device-usage-statistics/device-usage-statistics-overview.md index fc2a79e0990457a483c7dc75d3ab1fd88c55f126..69fca5fb8177eddc65ddfc0ffade70350446a8a1 100644 --- a/en/application-dev/device-usage-statistics/device-usage-statistics-overview.md +++ b/en/application-dev/device-usage-statistics/device-usage-statistics-overview.md @@ -7,21 +7,21 @@ With device usage statistics APIs, you can have a better understanding of the ap Currently you can have access to statistics on the application usage, and the notification and system usage statistics feature will be available for use in later versions. - **The application usage statistics is updated**: -1. Every 30 minutes -2. Upon system time change -3. Upon start of a new day + 1. Every 30 minutes + 2. Upon system time change + 3. Upon start of a new day - **The application usage statistics can include the following**: -1. Events of all applications based on the specified start time and end time -2. Application usage duration statistics based on the specified start time and end time -3. Events of the current application based on the specified start time and end time -4. Application usage duration statistics in the specified time frame at the specified interval (daily, weekly, monthly, or annually) -5. Priority group of the current invoker application -6. Whether a specific application is in the idle state -7. Number of FA usage records specified by **maxNum**, sorted by time (most recent first). If **maxNum** is not specified, the default value **1000** will be used. -8. Number of notifications from applications based on the specified start time and end time -9. Statistics about system events (hibernation, wakeup, unlocking, and screen locking) that occur between the specified start time and end time -10. Priority group of the invoker application or a specified application + 1. Events of all applications based on the specified start time and end time + 2. Application usage duration statistics based on the specified start time and end time + 3. Events of the current application based on the specified start time and end time + 4. Application usage duration statistics in the specified time frame at the specified interval (daily, weekly, monthly, or annually) + 5. Priority group of the current invoker application + 6. Whether a specific application is in the idle state + 7. Number of FA usage records specified by **maxNum**, sorted by time (most recent first). If **maxNum** is not specified, the default value **1000** will be used. + 8. Number of notifications from applications based on the specified start time and end time + 9. Statistics about system events (hibernation, wakeup, unlocking, and screen locking) that occur between the specified start time and end time + 10. Priority group of the invoker application or a specified application - **The setters can be used to:** @@ -35,6 +35,6 @@ Currently you can have access to statistics on the application usage, and the no Deregister the callback for application group changes. -### Required Permissions +## Required Permissions - Before calling the following system APIs, you need to apply for the **ohos.permission.BUNDLE_ACTIVE_INFO** permission: **queryBundleActiveStates**, **queryBundleStateInfos**, **queryBundleStateInfoByInterval**, **queryBundleActiveEventStates**, **queryAppNotificationNumber**, **queryAppUsagePriorityGroup(bundleName?)**, **setBundleGroup**, **registerGroupCallBack**, and **unRegisterGroupCallBack**. - This permission is not required for calling third-party APIs: **queryCurrentBundleActiveStates**, **queryAppUsagePriorityGroup()**, and **isIdleState**. diff --git a/en/application-dev/device/vibrator-guidelines.md b/en/application-dev/device/vibrator-guidelines.md index 4f49e7996188a7bc668e23fc2a21a1a29ec6e562..97f9f5933b55c9a1b57b5555db5812b6576a262a 100644 --- a/en/application-dev/device/vibrator-guidelines.md +++ b/en/application-dev/device/vibrator-guidelines.md @@ -16,7 +16,7 @@ For details about the APIs, see [Vibrator](../reference/apis/js-apis-vibrator.md | ohos.vibrator | vibrate(duration: number, callback?: AsyncCallback<void>): void | Triggers vibration with the specified duration. This API uses a callback to return the result. | | ohos.vibrator | vibrate(effectId: EffectId): Promise<void> | Triggers vibration with the specified effect. This API uses a promise to return the result. | | ohos.vibrator | vibrate(effectId: EffectId, callback?: AsyncCallback<void>): void | Triggers vibration with the specified effect. This API uses a callback to return the result.| -| ohos.vibrator | stop(stopMode: VibratorStopMode): Promise<void> | Stops vibration. This API uses a promise to return the result. | +| ohos.vibrator | stop(stopMode: VibratorStopMode): Promise<void>| Stops vibration. This API uses a promise to return the result. | | ohos.vibrator | stop(stopMode: VibratorStopMode, callback?: AsyncCallback<void>): void | Stops vibration. This API uses a callback to return the result. | @@ -55,7 +55,7 @@ For details about the APIs, see [Vibrator](../reference/apis/js-apis-vibrator.md ], "when": "inuse" } - }, + } ] ``` diff --git a/en/application-dev/media/Readme-EN.md b/en/application-dev/media/Readme-EN.md index 131114d67cb3e1c8519d6d5f3a85b438e5846f6f..5f6e88fc07c88d3e5913058a26887e818a3cc3bc 100755 --- a/en/application-dev/media/Readme-EN.md +++ b/en/application-dev/media/Readme-EN.md @@ -20,4 +20,4 @@ - Camera - [Camera Development](camera.md) - + - [Distributed Camera Development](remote-camera.md) diff --git a/en/application-dev/media/audio-capturer.md b/en/application-dev/media/audio-capturer.md index 64566aba64e213ca8e088ad3a71e036625153187..0815ef31a288440271a27a8f03fb417923a46190 100644 --- a/en/application-dev/media/audio-capturer.md +++ b/en/application-dev/media/audio-capturer.md @@ -8,7 +8,7 @@ You can use the APIs provided by **AudioCapturer** to record raw audio files. During application development, you are advised to use **on('stateChange')** to subscribe to state changes of the **AudioCapturer** instance. This is because some operations can be performed only when the audio capturer is in a given state. If the application performs an operation when the audio capturer is not in the given state, the system may throw an exception or generate other undefined behavior. -For details about the APIs, see [AudioCapturer in Audio Management](../reference/apis/js-apis-audio.md). +For details about the APIs, see [AudioCapturer in Audio Management](../reference/apis/js-apis-audio.md#audiocapturer8). **Figure 1** Audio capturer state diff --git a/en/application-dev/media/audio-playback.md b/en/application-dev/media/audio-playback.md index 131cacdb3f39ecf6eafb5088525d97d209c9cf18..5227f6cdd1b9ec89818b0d1762c99267ec7eba97 100644 --- a/en/application-dev/media/audio-playback.md +++ b/en/application-dev/media/audio-playback.md @@ -18,7 +18,7 @@ You can use audio playback APIs to convert audio data into audible analog signal ## How to Develop -For details about the APIs, see [AudioPlayer in the Media API](../reference/apis/js-apis-media.md). +For details about the APIs, see [AudioPlayer in the Media API](../reference/apis/js-apis-media.md#audioplayer). ### Full-Process Scenario diff --git a/en/application-dev/media/audio-recorder.md b/en/application-dev/media/audio-recorder.md index 6fb1c28efa8bd8bd69e16b09cd577ec4bdeff6e6..f465db2b88118b77c9a4e64307170da07c3e8918 100644 --- a/en/application-dev/media/audio-recorder.md +++ b/en/application-dev/media/audio-recorder.md @@ -16,7 +16,7 @@ During audio recording, audio signals are captured, encoded, and saved to files. ## How to Develop -For details about the APIs, see [AudioRecorder in the Media API](../reference/apis/js-apis-media.md). +For details about the APIs, see [AudioRecorder in the Media API](../reference/apis/js-apis-media.md#audiorecorder). ### Full-Process Scenario @@ -185,4 +185,3 @@ export class AudioRecorderDemo { } } ``` - diff --git a/en/application-dev/media/audio-stream-manager.md b/en/application-dev/media/audio-stream-manager.md index 4f0f88c8fa2c3357e7a8d582642cf4efbb7bf1db..9a8176b4bdab20b681ad9b3e96343a2ccfc10829 100644 --- a/en/application-dev/media/audio-stream-manager.md +++ b/en/application-dev/media/audio-stream-manager.md @@ -12,7 +12,7 @@ For details about the APIs, see [AudioStreamManager](../reference/apis/js-apis-a **Figure 1** Audio stream management invoking relationship -![](figures/zh-ch_image_audio_stream_manager.png) +![](figures/en-us_image_audio_stream_manager.png) ## How to Develop diff --git a/en/application-dev/media/camera.md b/en/application-dev/media/camera.md index bdbccf975c64a6df4cef6845c850cc8de1b2de26..06439dd049be835cdf5a96a35e2a2a42012ee6f8 100644 --- a/en/application-dev/media/camera.md +++ b/en/application-dev/media/camera.md @@ -292,7 +292,7 @@ await captureSession.start().then(() => { ##### Switching a Session ```js -// Stop the current session. +// Stop the session. await captureSession.stop((err) => { if (err) { console.error('Failed to stop the session ${err.message}'); @@ -347,8 +347,8 @@ await captureSession.start().then(() => { ```js let settings = { - quality: camera.QualityLevel.QUALITY_LEVEL_HIGH // Set the image quality to high. - rotation: camera.ImageRotation.ROTATION_0, // Set the image rotation angle to 0. + quality: camera.QualityLevel.QUALITY_LEVEL_HIGH, // Set the image quality to high. + rotation: camera.ImageRotation.ROTATION_0 // Set the image rotation angle to 0. } // Use the current photographing settings to take photos. photoOutput.capture(settings, (err) => { @@ -395,7 +395,7 @@ await videoOutput.stop((err) => { #### Releasing Resources ```js -// Stop the current session. +// Stop the session. await captureSession.stop((err) => { if (err) { console.error('Failed to stop the session ${err.message}'); diff --git a/en/application-dev/media/figures/zh-ch_image_audio_stream_manager.png b/en/application-dev/media/figures/en-us_image_audio_stream_manager.png similarity index 100% rename from en/application-dev/media/figures/zh-ch_image_audio_stream_manager.png rename to en/application-dev/media/figures/en-us_image_audio_stream_manager.png diff --git a/en/application-dev/media/remote-camera.md b/en/application-dev/media/remote-camera.md index b63946d6a03a9fbb4d4e6b8e20c3e4920364523b..8d9bd0eb7b7568e9cb46dd6c2a37b4380933b0bf 100644 --- a/en/application-dev/media/remote-camera.md +++ b/en/application-dev/media/remote-camera.md @@ -52,7 +52,7 @@ await cameraManager.getCameras((err, cameras) => { cameraArray = cameras }) -for(let cameraIndex = 0; cameraIndex < cameraArray.length; cameraIndex) { +for(let cameraIndex = 0; cameraIndex < cameraArray.length; cameraIndex++) { console.log('cameraId : ' + cameraArray[cameraIndex].cameraId) // Obtain the camera ID. console.log('cameraPosition : ' + cameraArray[cameraIndex].cameraPosition) // Obtain the camera position. console.log('cameraType : ' + cameraArray[cameraIndex].cameraType) // Obtain the camera type. diff --git a/en/application-dev/media/video-playback.md b/en/application-dev/media/video-playback.md index cfc09db79fc853066e03205010f43c2f63c27ce5..6ee5cf660069294f717c5cac614ed707db9f1a8c 100644 --- a/en/application-dev/media/video-playback.md +++ b/en/application-dev/media/video-playback.md @@ -33,7 +33,7 @@ The table below lists the mainstream playback formats and resolutions. ## How to Develop -For details about the APIs, see [VideoPlayer in the Media API](../reference/apis/js-apis-media.md). +For details about the APIs, see [VideoPlayer in the Media API](../reference/apis/js-apis-media.md#videoplayer8). ### Full-Process Scenario diff --git a/en/application-dev/media/video-recorder.md b/en/application-dev/media/video-recorder.md index 2982675bd37ff683c83f253d23d3a6c71014d66b..62e81cf05c384a7cd1a780c562697be046153d05 100644 --- a/en/application-dev/media/video-recorder.md +++ b/en/application-dev/media/video-recorder.md @@ -14,7 +14,7 @@ During video recording, audio and video signals are captured, encoded, and saved ## How to Develop -For details about the APIs, see [VideoRecorder in the Media API](../reference/apis/js-apis-media.md). +For details about the APIs, see [VideoRecorder in the Media API](../reference/apis/js-apis-media.md#videorecorder9). ### Full-Process Scenario diff --git a/en/application-dev/reference/apis/development-intro.md b/en/application-dev/reference/apis/development-intro.md index 8528a10ab6f4ba3dd14186079357ce28e650ee6a..f1cc73aa8437b7cb20bf5fe16b284da2a788d570 100644 --- a/en/application-dev/reference/apis/development-intro.md +++ b/en/application-dev/reference/apis/development-intro.md @@ -26,6 +26,12 @@ A description regarding system APIs will be provided in the document. - If all the APIs of a module are system APIs, the following description is provided at the beginning of the reference document: "All the APIs of this module are system APIs." - If a specific API of a module is a system API, the following description is provided individually for the API: "This is a system API." +Non-system applications are applications whose Ability Privilege Level (APL) is **normal**. The default application level is **normal**. + +For details about the APL and how to declare the APL of an application higher than **normal**, see [Access Control Overview - App APLs](../../security/accesstoken-overview.md#app-apls). + +The public SDK, which does not include system APIs, is provided as standard in DevEco Studio. To use system APIs, switch to the full SDK. For details on the operation, see [Guide to Switching to Full SDK](../../quick-start/full-sdk-switch-guide.md). + ## Permission Description By default, applications can access limited system resources. However, in some cases, an application needs to access excess data (including personal data) and functions of the system or another application to implement extended functions. For details, see [Access Control Overview](../../security/accesstoken-overview.md). diff --git a/en/application-dev/reference/apis/js-apis-bundle-LauncherAbilityInfo.md b/en/application-dev/reference/apis/js-apis-bundle-LauncherAbilityInfo.md index 7b932cacbc2195e8c52976aa80e71bd3b638921d..3a00ac698a3529d153ef3741979238569555f12c 100644 --- a/en/application-dev/reference/apis/js-apis-bundle-LauncherAbilityInfo.md +++ b/en/application-dev/reference/apis/js-apis-bundle-LauncherAbilityInfo.md @@ -10,6 +10,8 @@ The **LauncherAbilityInfo** module provides information about a launcher ability **System capability**: SystemCapability.BundleManager.BundleFramework +**System API**: This is a system API and cannot be called by third-party applications. + | Name | Type | Readable| Writable| Description | | --------------- | ---------------------------------------------------- | ---- | ---- | ------------------------------------ | | applicationInfo | [ApplicationInfo](js-apis-bundle-ApplicationInfo.md) | Yes | No | Application information of the launcher ability.| diff --git a/en/application-dev/reference/apis/js-apis-camera.md b/en/application-dev/reference/apis/js-apis-camera.md index 5a88150801a77616a6954139376edead865f55a8..78db0562f97cf687e26c210d870519c829b691ee 100644 --- a/en/application-dev/reference/apis/js-apis-camera.md +++ b/en/application-dev/reference/apis/js-apis-camera.md @@ -20,9 +20,9 @@ Obtains a **CameraManager** instance. This API uses an asynchronous callback to **Parameters** -| Name | Type | Mandatory| Description | -| -------- | ----------------------------------------------- | ---- | ---------------------------- | -| context | Context | Yes | Application context. | +| Name | Type | Mandatory| Description | +| -------- | ----------------------------------------------- | ---- | ---------------------------------- | +| context | Context | Yes | Application context. | | callback | AsyncCallback<[CameraManager](#cameramanager)\> | Yes | Callback used to return the **CameraManager** instance.| **Example** @@ -30,7 +30,7 @@ Obtains a **CameraManager** instance. This API uses an asynchronous callback to ```js camera.getCameraManager(context, (err, cameraManager) => { if (err) { - console.error(`Failed to get the CameraManager instance ${err.message}`); + console.error('Failed to get the CameraManager instance ${err.message}'); return; } console.log('Callback returned with the CameraManager instance'); @@ -53,8 +53,8 @@ Obtains a **CameraManager** instance. This API uses a promise to return the resu **Return value** -| Type | Description | -| ----------------------------------------- | ----------------------------------- | +| Type | Description | +| ----------------------------------------- | ----------------------------------------- | | Promise<[CameraManager](#cameramanager)\> | Promise used to return the **CameraManager** instance.| **Example** @@ -78,1149 +78,947 @@ Enumerates the camera statuses. | CAMERA_STATUS_AVAILABLE | 2 | The camera is available. | | CAMERA_STATUS_UNAVAILABLE | 3 | The camera is unavailable.| -## Profile -Defines the camera profile. +## CameraPosition + +Enumerates the camera positions. **System capability**: SystemCapability.Multimedia.Camera.Core -| Name | Type | Read only| Description | -| -------- | ----------------------------- |---- | ------------- | -| format | [CameraFormat](#cameraformat) | Yes | Output format. | -| size | [Size](#size) | Yes | Resolution. | +| Name | Value | Description | +| --------------------------- | ---- | ---------------- | +| CAMERA_POSITION_UNSPECIFIED | 0 | Unspecified position.| +| CAMERA_POSITION_BACK | 1 | Rear camera. | +| CAMERA_POSITION_FRONT | 2 | Front camera. | -## FrameRateRange +## CameraType - Defines the frame rate range. +Enumerates the camera types. **System capability**: SystemCapability.Multimedia.Camera.Core -| Name | Type | Read only| Description | -| ------------------------- | ------ | ---- | ------------------- | -| min | number | Yes | Minimum rate, in fps. | -| max | number | Yes | Maximum rate, in fps. | +| Name | Value | Description | +| ----------------------- | ---- | ---------------- | +| CAMERA_TYPE_UNSPECIFIED | 0 | Unspecified camera type.| +| CAMERA_TYPE_WIDE_ANGLE | 1 | Wide camera. | +| CAMERA_TYPE_ULTRA_WIDE | 2 | Ultra wide camera. | +| CAMERA_TYPE_TELEPHOTO | 3 | Telephoto camera. | +| CAMERA_TYPE_TRUE_DEPTH | 4 | Camera with depth of field information. | + -## VideoProfile +## ConnectionType -Defines the video profile. +Enumerates the camera connection types. **System capability**: SystemCapability.Multimedia.Camera.Core -| Name | Type | Read only| Description | -| ------------------------- | ----------------------------------------- | --- |------------ | -| frameRateRanges | [FrameRateRange](#frameraterange) | Yes | Frame rate range. | +| Name | Value | Description | +| ---------------------------- | ---- | ------------- | +| CAMERA_CONNECTION_BUILT_IN | 0 | Built-in camera. | +| CAMERA_CONNECTION_USB_PLUGIN | 1 | Camera connected using USB.| +| CAMERA_CONNECTION_REMOTE | 2 | Remote camera. | -## CameraOutputCapability +## Size -Defines the camera output capability. +Defines the image size that can be used in previewing, photographing, and video recording. **System capability**: SystemCapability.Multimedia.Camera.Core -| Name | Type | Read only| Description | -| ----------------------------- | -------------------------------------------------- | --- |------------------- | -| previewProfiles | Array<[Profile](#profile)\> | Yes | Supported preview profiles. | -| photoProfiles | Array<[Profile](#profile)\> | Yes | Supported shooting profiles. | -| videoProfiles | Array<[VideoProfile](#videoprofile)\> | Yes | Supported video recording profiles. | -| supportedMetadataObjectTypes | Array<[MetadataObjectType](#metadataobjecttype)\> | Yes | Supported metadata object types.| +| Name | Type | Readable| Writable| Description | +| ------ | ------ | ---- | ---- | ------------ | +| height | string | Yes | Yes | Image height.| +| width | number | Yes | Yes | Image width.| ## CameraManager Implements camera management. Before calling any API in **CameraManager**, you must use **getCameraManager** to obtain a **CameraManager** instance. -### getSupportedCameras +### getCameras -getSupportedCameras(callback: AsyncCallback\>): void +getCameras(callback: AsyncCallback\>): void -Obtains supported cameras. This API uses an asynchronous callback to return the result. +Obtains all cameras supported by the device. This API uses an asynchronous callback to return the array of supported cameras. **System capability**: SystemCapability.Multimedia.Camera.Core **Parameters** -| Name | Type | Mandatory| Description | -| -------- | ----------------------------------------------------- | ---- | ------------------------------- | -| callback | AsyncCallback\> | Yes | Callback used to return the array of supported cameras.| +| Name | Type | Mandatory| Description | +| -------- | ----------------------------------------- | ---- | ------------------------------------ | +| callback | AsyncCallback\> | Yes | Callback used to return the array of supported cameras.| **Example** ```js -cameraManager.getSupportedCameras((err, cameras) => { +cameraManager.getCameras((err, cameras) => { if (err) { - console.error(`Failed to get the cameras. ${err.message}`); + console.error('Failed to get the cameras. ${err.message}'); return; } - console.log(`Callback returned with an array of supported cameras: ${cameras.length}`); + console.log('Callback returned with an array of supported cameras: ' + cameras.length); }) ``` -### getSupportedCameras +### getCameras -getSupportedCameras(): Promise\> +getCameras(): Promise\> -Obtains supported cameras. This API uses a promise to return the result. +Obtains all cameras supported by the device. This API uses a promise to return the array of supported cameras. **System capability**: SystemCapability.Multimedia.Camera.Core **Return value** -| Type | Description | -| ----------------------------------------------- | ------------------------- | -| Promise\> | Promise used to return the array of supported cameras.| +| Type | Description | +| ----------------------------------- | ----------------------------- | +| Promise\> | Promise used to return the array of supported cameras.| **Example** ```js -cameraManager.getSupportedCameras().then((cameraArray) => { - console.log(`Promise returned with an array of supported cameras: ${cameraArray.length}`); +cameraManager.getCameras().then((cameraArray) => { + console.log('Promise returned with an array of supported cameras: ' + cameraArray.length); }) ``` -### getSupportedOutputCapability +### createCameraInput + +createCameraInput(cameraId: string, callback: AsyncCallback): void -getSupportedOutputCapability(camera:CameraDevice, callback: AsyncCallback): void +Creates a **CameraInput** instance with the specified camera ID. This API uses an asynchronous callback to return the result. -Obtains the output capability supported by a camera. This API uses an asynchronous callback to return the result. +**Required permissions**: ohos.permission.CAMERA **System capability**: SystemCapability.Multimedia.Camera.Core **Parameters** -| Name | Type | Mandatory| Description | -| -------- | ---------------------------------------------------------------- | -- | -------------------------- | -| camera | [CameraDevice](#cameradevice) | Yes| **CameraDevice** object. | -| callback | AsyncCallback<[CameraOutputCapability](#cameraoutputcapability)\> | Yes| Callback used to return the output capability.| +| Name | Type | Mandatory| Description | +| -------- | ------------------------------------------- | ---- | ----------------------------------- | +| cameraId | string | Yes | ID of the target camera. | +| callback | AsyncCallback<[CameraInput](#camerainput)\> | Yes | Callback used to return the **CameraInput** instance.| **Example** ```js -cameraManager.getSupportedOutputCapability(cameraDevice, (err, cameras) => { +cameraManager.createCameraInput(cameraId, (err, cameraInput) => { if (err) { - console.error(`Failed to get the cameras. ${err.message}`); + console.error('Failed to create the CameraInput instance. ${err.message}'); return; } - console.log('Callback returned with an array of supported outputCapability'); + console.log('Callback returned with the CameraInput instance.'); }) ``` -### getSupportedOutputCapability +### createCameraInput + +createCameraInput(cameraId: string): Promise -getSupportedOutputCapability(camera:CameraDevice): Promise +Creates a **CameraInput** instance with the specified camera ID. This API uses a promise to return the result. -Obtains the output capability supported by a camera. This API uses a promise to return the result. +**Required permissions**: ohos.permission.CAMERA **System capability**: SystemCapability.Multimedia.Camera.Core **Parameters** -| Name | Type | Mandatory | Description | -| -------- | --------------------------------- | ---- | ---------- | -| camera | [CameraDevice](#cameradevice) | Yes | **CameraDevice** object.| +| Name | Type | Mandatory| Description | +| -------- | ------ | ---- | ------------ | +| cameraId | string | Yes | ID of the target camera.| **Return value** -| Type | Description | -| -------------------------------------------------------------- | ----------------------------- | -| Promise<[CameraOutputCapability](#cameraoutputcapability)\> | Promise used to return the output capability.| - +| Type | Description | +| ------------------------------------- | ---------------------------------------- | +| Promise<[CameraInput](#camerainput)\> | Promise used to return the **CameraInput** instance.| **Example** ```js -cameraManager.getSupportedOutputCapability(cameraDevice).then((cameraoutputcapability) => { - console.log('Promise returned with an array of supported outputCapability'); +cameraManager.createCameraInput(cameraId).then((cameraInput) => { + console.log('Promise returned with the CameraInput instance'); }) ``` -### getSupportedMetadataObjectType +### createCameraInput + +createCameraInput(position: CameraPosition, type: CameraType, callback: AsyncCallback): void -getSupportedMetadataObjectType(callback: AsyncCallback\>): void +Creates a **CameraInput** instance with the specified camera position and type. This API uses an asynchronous callback to return the result. -Obtains the metadata object types supported by this camera. This API uses an asynchronous callback to return the result. +**Required permissions**: ohos.permission.CAMERA **System capability**: SystemCapability.Multimedia.Camera.Core **Parameters** -| Name | Type | Mandatory| Description | -| -------- | ---------------------------------------------------------------- | -- | -------------------------- | -| callback | AsyncCallback\> | Yes| Callback used to return the metadata object types.| +| Name | Type | Mandatory| Description | +| -------- | ------------------------------------------- | ---- | ----------------------------------- | +| position | [CameraPosition](#cameraposition) | Yes | Camera position. | +| type | [CameraType](#cameratype) | Yes | Camera type. | +| callback | AsyncCallback<[CameraInput](#camerainput)\> | Yes | Callback used to return the **CameraInput** instance.| **Example** ```js -cameraManager.getSupportedMetadataObjectType((err, metadataobject) => { +cameraManager.createCameraInput(camera.CameraPosition.CAMERA_POSITION_BACK, camera.CameraType.CAMERA_TYPE_UNSPECIFIED, (err, cameraInput) => { if (err) { - console.error(`Failed to get the supported metadataObjectType. ${err.message}`); + console.error('Failed to create the CameraInput instance. ${err.message}'); return; } - console.log('Callback returned with an array of supported metadataObjectType.' ); + console.log('Callback returned with the CameraInput instance'); }) ``` -### getSupportedMetadataObjectType +### createCameraInput + +createCameraInput(position: CameraPosition, type: CameraType): Promise -getSupportedMetadataObjectType(camera:CameraDevice): Promise +Creates a **CameraInput** instance with the specified camera position and type. This API uses a promise to return the result. -Obtains the metadata object types supported by this camera. This API uses a promise to return the result. +**Required permissions**: ohos.permission.CAMERA **System capability**: SystemCapability.Multimedia.Camera.Core -**Return value** +**Parameters** -| Type | Description | -| -------------------------------------------------------------- | ----------------------------- | -| Promise\> | Promise used to return the metadata object types.| +| Name | Type | Mandatory| Description | +| -------- | --------------------------------- | ---- | ---------- | +| position | [CameraPosition](#cameraposition) | Yes | Camera position.| +| type | [CameraType](#cameratype) | Yes | Camera type.| + +**Return value** +| Type | Description | +| ------------------------------------- | ---------------------------------------- | +| Promise<[CameraInput](#camerainput)\> | Promise used to return the **CameraInput** instance.| **Example** ```js -cameraManager.getSupportedMetadataObjectType().then((metadataobject) => { - console.log('Promise returned with an array of supported metadataObjectType.' ); +cameraManager.createCameraInput(camera.CameraPosition.CAMERA_POSITION_BACK, camera.CameraType.CAMERA_TYPE_UNSPECIFIED).then((cameraInput) => { + console.log('Promise returned with the CameraInput instance.'); }) ``` -### isCameraMuted +### on('cameraStatus') -isCameraMuted(callback: AsyncCallback): void +on(type: 'cameraStatus', callback: AsyncCallback): void -Checks whether this camera is muted. This API uses an asynchronous callback to return the result. +Listens for camera status changes. This API uses an asynchronous callback to return the result. **System capability**: SystemCapability.Multimedia.Camera.Core **Parameters** -| Name | Type | Mandatory| Description | -| -------- | ---------------------------------------- | ---- | ------------------------------------ | -| callback | AsyncCallback | Yes | Callback used to return the result. The value **true** means that the camera is muted, and **false** means the opposite.| +| Name | Type | Mandatory| Description | +| :------- | :---------------------------------------------------- | :--- | :--------------------------------------------------- | +| type | string | Yes | Event type. The value is fixed at **`cameraStatus`**, indicating the camera status change event.| +| callback | AsyncCallback<[CameraStatusInfo](#camerastatusinfo)\> | Yes | Callback used to return the camera status change. | **Example** ```js -cameraManager.isCameraMuted((err, status) => { +cameraManager.on('cameraStatus', (err, cameraStatusInfo) => { if (err) { - console.error(`Failed to get the cameraMuted status. ${err.message}`); + console.error('Failed to get cameraStatus callback. ${err.message}'); return; } - console.log('Callback returned with cameraMuted status'); + console.log('camera : ' + cameraStatusInfo.camera.cameraId); + console.log('status: ' + cameraStatusInfo.status); }) ``` -### isCameraMuted - -isCameraMuted(): Promise +## Camera -Checks whether this camera is muted. This API uses a promise to return the result. +After **[camera.getCameraManager](#cameragetcameramanager)** is called, a camera instance is returned, with camera-related metadata such as **cameraId**, **cameraPosition**, **cameraType**, and **connectionType**. **System capability**: SystemCapability.Multimedia.Camera.Core -**Return value** - -| Type | Description | -| ------------------------------------ | --------------------------------------------- | -| Promise | Promise used to return the result. The value **true** means that the camera is muted, and **false** means the opposite. | - +| Name | Type | Read only| Description | +| -------------- | --------------------------------- | ---- | -------------- | +| cameraId | string | Yes | Camera ID. | +| cameraPosition | [CameraPosition](#cameraposition) | Yes | Camera position. | +| cameraType | [CameraType](#cameratype) | Yes | Camera type. | +| connectionType | [ConnectionType](#connectiontype) | Yes | Camera connection type.| **Example** ```js -cameraManager.isCameraMuted().then((status) => { - console.log('Promise returned with the status whether camera is muted.'); -}) +async function getCameraInfo("cameraId") { + var cameraManager = await camera.getCameraManager(context); + var cameras = await cameraManager.getCameras(); + var cameraObj = cameras[0]; + var cameraId = cameraObj.cameraId; + var cameraPosition = cameraObj.cameraPosition; + var cameraType = cameraObj.cameraType; + var connectionType = cameraObj.connectionType; +} ``` -### isCameraMuteSupported +## CameraStatusInfo + +Describes the camera status information. + +**System capability**: SystemCapability.Multimedia.Camera.Core -isCameraMuteSupported(callback: AsyncCallback): void +| Name | Type | Description | +| ------ | ----------------------------- | ---------- | +| camera | [Camera](#camera) | Camera object.| +| status | [CameraStatus](#camerastatus) | Camera status.| -Checks whether this camera can be muted. This API uses an asynchronous callback to return the result. -This is a system API. +## CameraInput -**Required permissions**: ohos.permission.CAMERA +Implements a **CameraInput** instance. Before calling any API in **CameraInput**, you must create a **CameraInput** instance. + +### getCameraId + +getCameraId(callback: AsyncCallback\): void + +Obtains the camera ID based on which this **CameraInput** instance is created. This API uses an asynchronous callback to return the camera ID. **System capability**: SystemCapability.Multimedia.Camera.Core **Parameters** -| Name | Type | Mandatory| Description | -| -------- | --------------------------------------- | ---- | ------------------------------------ | -| callback | AsyncCallback | Yes | Callback used to return the result. The value **true** means that the camera can be muted, and **false** means the opposite. | +| Name | Type | Mandatory| Description | +| -------- | ---------------------- | ---- | -------------------------- | +| callback | AsyncCallback | Yes | Callback used to return the camera ID.| **Example** ```js -cameraManager.isCameraMuteSupported((err, status) => { +cameraInput.getCameraId((err, cameraId) => { if (err) { - console.error(`Failed to get the cameraMuteSupported. ${err.message}`); + console.error('Failed to get the camera ID. ${err.message}'); return; } - console.log('Callback returned with the status whether cameraMuteSupported.'); + console.log('Callback returned with the camera ID: ' + cameraId); }) ``` -### isCameraMuteSupported +### getCameraId -isCameraMuteSupported(): Promise +getCameraId(): Promise -Checks whether this camera can be muted. This API uses a promise to return the result. - -This is a system API. - -**Required permissions**: ohos.permission.CAMERA +Obtains the camera ID based on which this **CameraInput** instance is created. This API uses a promise to return the camera ID. **System capability**: SystemCapability.Multimedia.Camera.Core **Return value** -| Type | Description | -| --------------------- | ----------------------------- | -| Promise | Promise used to return the result. The value **true** means that the camera can be muted, and **false** means the opposite.| - +| Type | Description | +| ---------------- | ----------------------------- | +| Promise | Promise used to return the camera ID.| **Example** ```js -cameraManager.isCameraMuteSupported().then((status) => { - console.log('Promise returned with the status whether cameraMuteSupported.'); +cameraInput.getCameraId().then((cameraId) => { + console.log('Promise returned with the camera ID:' + cameraId); }) ``` -### muteCamera -muteCamera(mute:boolean, callback: AsyncCallback): void - -Mutes this camera. This API uses an asynchronous callback to return the result. +### hasFlash -This is a system API. +hasFlash(callback: AsyncCallback): void -**Required permissions**: ohos.permission.CAMERA +Checks whether the device has flash. This API uses an asynchronous callback to return the result. **System capability**: SystemCapability.Multimedia.Camera.Core **Parameters** -| Name | Type | Mandatory | Description | -| -------- | ----------------------------------------- | ---- | ------------------------------------ | -| mute | boolean | Yes | Whether to mute the camera. The value **true** means to mute the camera, and **false** means the opposite. | -| callback | AsyncCallback | Yes | Callback used to return the result.| +| Name | Type | Mandatory| Description | +| -------- | ----------------------- | ---- | -------------------------------------- | +| callback | AsyncCallback | Yes | Callback used to return the flash support status. The value **true** means that the device has flash.| **Example** ```js -cameraManager.muteCamera(isMuted, (err) => { +cameraInput.hasFlash((err, status) => { if (err) { - console.error(`Failed to mute the camera. ${err.message}`); + console.error('Failed to check whether the device has flash light. ${err.message}'); return; } - console.log('Callback returned with the muteCamera.'); + console.log('Callback returned with flash light support status: ' + status); }) ``` -### muteCamera - -muteCamera(mute:boolean): Promise - -Mutes this camera. This API uses a promise to return the result. +### hasFlash -This is a system API. +hasFlash(): Promise -**Required permissions**: ohos.permission.CAMERA +Checks whether the device has flash. This API uses a promise to return the result. **System capability**: SystemCapability.Multimedia.Camera.Core -**Parameters** - -| Name | Type | Mandatory| Description | -| -------- | ----------------------------------------- | ---- | ------------ | -| mute | boolean | Yes | Whether to mute the camera. The value **true** means to mute the camera, and **false** means the opposite. | - **Return value** -| Type | Description | -| ----------------------------------- | ----------------------------- | -| Promise | Promise used to return the result.| - +| Type | Description | +| ----------------- | ------------------------------------------------------- | +| Promise | Promise used to return the flash support status. The value **true** means that the device has flash.| **Example** -```js -cameraManager.muteCamera(isMuted).then(() => { - console.log('Promise returned muteCamera.'); +```js +cameraInput.hasFlash().then((status) => { + console.log('Promise returned with the flash light support status:' + status); }) ``` -### createCameraInput - -createCameraInput(camera: CameraDevice, callback: AsyncCallback): void - -Creates a **CameraInput** instance with the specified **CameraDevice** object. This API uses an asynchronous callback to return the result. +### isFlashModeSupported -This is a system API. +isFlashModeSupported(flashMode: FlashMode, callback: AsyncCallback): void -**Required permissions**: ohos.permission.CAMERA +Checks whether a specified flash mode is supported. This API uses an asynchronous callback to return the result. **System capability**: SystemCapability.Multimedia.Camera.Core **Parameters** -| Name | Type | Mandatory| Description | -| -------- | ------------------------------------------- | ---- | --------------------------------- | -| camera | [CameraDevice](#cameradevice) | Yes | **CameraDevice** object. | -| callback | AsyncCallback<[CameraInput](#camerainput)\> | Yes | Callback used to return the **CameraInput** instance. | +| Name | Type | Mandatory| Description | +| --------- | ----------------------- | ---- | ---------------------------------------- | +| flashMode | [FlashMode](#flashmode) | Yes | Flash mode. | +| callback | AsyncCallback | Yes | Callback used to return the flash mode support status. The value **true** means that the flash mode is supported, and **false** means the opposite.| **Example** ```js -cameraManager.createCameraInput(camera, (err, cameraInput) => { +cameraInput.isFlashModeSupported(camera.FlashMode.FLASH_MODE_AUTO, (err, status) => { if (err) { - console.error(`Failed to create the CameraInput instance. ${err.message}`); + console.error('Failed to check whether the flash mode is supported. ${err.message}'); return; } - console.log('Callback returned with the CameraInput instance.'); + console.log('Callback returned with the flash mode support status: ' + status); }) ``` -### createCameraInput - -createCameraInput(camera: CameraDevice): Promise - -Creates a **CameraInput** instance with the specified **CameraDevice** object. This API uses a promise to return the result. +### isFlashModeSupported -This is a system API. +isFlashModeSupported(flashMode: FlashMode): Promise -**Required permissions**: ohos.permission.CAMERA +Checks whether a specified flash mode is supported. This API uses a promise to return the result. **System capability**: SystemCapability.Multimedia.Camera.Core **Parameters** -| Name | Type | Mandatory| Description | -| -------- | ----------------------------- | ---- | ---------- | -| camera | [CameraDevice](#cameradevice) | Yes | **CameraDevice** object.| +| Name | Type | Mandatory| Description | +| --------- | ----------------------- | ---- | ---------------- | +| flashMode | [FlashMode](#flashmode) | Yes | Flash mode.| **Return value** -| Type | Description | -| ------------------------------------- | ------------------------------------ | -| Promise<[CameraInput](#camerainput)\> | Promise used to return the **CameraInput** instance.| +| Type | Description | +| ----------------- | ------------------------------------------------------------ | +| Promise | Promise used to return the flash mode support status. The value **true** means that the flash mode is supported, and **false** means the opposite.| **Example** ```js -cameraManager.createCameraInput(camera).then((cameraInput) => { - console.log('Promise returned with the CameraInput instance'); +cameraInput.isFlashModeSupported(camera.FlashMode.FLASH_MODE_AUTO).then((status) => { + console.log('Promise returned with flash mode support status.' + status); }) ``` -### createCameraInput +### setFlashMode -createCameraInput(position: CameraPosition, type: CameraType, callback: AsyncCallback): void +setFlashMode(flashMode: FlashMode, callback: AsyncCallback): void -Creates a **CameraInput** instance with the specified camera position and type. This API uses an asynchronous callback to return the result. +Sets the flash mode. This API uses an asynchronous callback to return the result. -This is a system API. +Before the setting, do the following checks: -**Required permissions**: ohos.permission.CAMERA +1. Use **[hasFlash](#hasflash)** to check whether the device has flash. +2. Use **[isFlashModeSupported](#isflashmodesupported)** to check whether the device supports the flash mode. **System capability**: SystemCapability.Multimedia.Camera.Core **Parameters** -| Name | Type | Mandatory| Description | -| -------- | ------------------------------------------- | ---- | --------------------------------- | -| position | [CameraPosition](#cameraposition) | Yes | Camera position. | -| type | [CameraType](#cameratype) | Yes | Camera type. | -| callback | AsyncCallback<[CameraInput](#camerainput)\> | Yes | Callback used to return the **CameraInput** instance. | +| Name | Type | Mandatory| Description | +| --------- | ----------------------- | ---- | ------------------------ | +| flashMode | [FlashMode](#flashmode) | Yes | Flash mode. | +| callback | AsyncCallback | Yes | Callback used to return the result.| **Example** ```js -cameraManager.createCameraInput(camera.CameraPosition.CAMERA_POSITION_BACK, camera.CameraType.CAMERA_TYPE_UNSPECIFIED, (err, cameraInput) => { +cameraInput.setFlashMode(camera.FlashMode.FLASH_MODE_AUTO, (err) => { if (err) { - console.error(`Failed to create the CameraInput instance. ${err.message}`); + console.error('Failed to set the flash mode ${err.message}'); return; } - console.log('Callback returned with the CameraInput instance'); + console.log('Callback returned with the successful execution of setFlashMode.'); }) ``` -### createCameraInput +### setFlashMode -createCameraInput(position: CameraPosition, type:CameraType ): Promise +setFlashMode(flashMode: FlashMode): Promise -Creates a **CameraInput** instance with the specified camera position and type. This API uses a promise to return the result. +Sets a flash mode. This API uses a promise to return the result. -This is a system API. +Before the setting, do the following checks: -**Required permissions**: ohos.permission.CAMERA +1. Use **[hasFlash](#hasflash)** to check whether the device has flash. +2. Use **[isFlashModeSupported](#isflashmodesupported)** to check whether the device supports the flash mode. **System capability**: SystemCapability.Multimedia.Camera.Core **Parameters** -| Name | Type | Mandatory| Description | -| -------- | --------------------------------- | ---- | ------------ | -| position | [CameraPosition](#cameraposition) | Yes | Camera position. | -| type | [CameraType](#cameratype) | Yes | Camera type. | +| Name | Type | Mandatory| Description | +| --------- | ----------------------- | ---- | ---------------- | +| flashMode | [FlashMode](#flashmode) | Yes | Flash mode.| **Return value** -| Type | Description | -| ------------------------------------- | ------------------------------------ | -| Promise<[CameraInput](#camerainput)\> | Promise used to return the **CameraInput** instance.| +| Type | Description | +| -------------- | --------------------------- | +| Promise| Promise used to return the result.| **Example** ```js -cameraManager.createCameraInput(camera.CameraPosition.CAMERA_POSITION_BACK, camera.CameraType.CAMERA_TYPE_UNSPECIFIED).then((cameraInput) => { - console.log('Promise returned with the CameraInput instance'); +cameraInput.setFlashMode(camera.FlashMode.FLASH_MODE_AUTO).then(() => { + console.log('Promise returned with the successful execution of setFlashMode.'); }) ``` -### createPreviewOutput +### getFlashMode -createPreviewOutput(profile: Profile, surfaceId: string, callback: AsyncCallback): void +getFlashMode(callback: AsyncCallback): void -Creates a **PreviewOutput** instance. This API uses an asynchronous callback to return the result. +Obtains the flash mode in use. This API uses an asynchronous callback to return the result. **System capability**: SystemCapability.Multimedia.Camera.Core **Parameters** -| Name | Type | Mandatory| Description | -| -------- | ----------------------------------------------- | ---- | ------------------------------- | -| profile | [Profile](#profile) | Yes | Supported preview profile. | -| surfaceId| string | Yes | Surface ID, which is obtained from **[XComponent](../arkui-ts/ts-basic-components-xcomponent.md)** or **[ImageReceiver](js-apis-image.md#imagereceiver9)**.| -| callback | AsyncCallback<[PreviewOutput](#previewoutput)\> | Yes | Callback used to return the **PreviewOutput** instance.| +| Name | Type | Mandatory| Description | +| -------- | --------------------------------------- | ---- | ---------------------------------------- | +| callback | AsyncCallback<[FlashMode](#flashmode)\> | Yes | Callback used to return the flash mode.| **Example** ```js -cameraManager.createPreviewOutput(profile, surfaceId, (err, previewoutput) => { +cameraInput.getFlashMode((err, flashMode) => { if (err) { - console.error(`Failed to gcreate previewOutput. ${err.message}`); + console.error('Failed to get the flash mode ${err.message}'); return; } - console.log('Callback returned with previewOutput created.'); + console.log('Callback returned with current flash mode: ' + flashMode); }) ``` -### createPreviewOutput +### getFlashMode -createPreviewOutput(profile: Profile, surfaceId: string): Promise +getFlashMode(): Promise -Creates a **PreviewOutput** instance. This API uses a promise to return the result. +Obtains the flash mode in use. This API uses a promise to return the result. **System capability**: SystemCapability.Multimedia.Camera.Core -**Parameters** - -| Name | Type | Mandatory| Description | -| -------- | ---------------------------------| ---- | ----------------- | -| profile | [Profile](#profile) | Yes | Supported preview profile. | -| surfaceId| string | Yes | Surface ID, which is obtained from **[XComponent](../arkui-ts/ts-basic-components-xcomponent.md)** or **[ImageReceiver](js-apis-image.md#imagereceiver9)**.| - **Return value** -| Type | Description | -| ---------------------------------------- | ---------------------------------------- | -| Promise<[PreviewOutput](#previewoutput)\> | Promise used to return the **PreviewOutput** instance. | +| Type | Description | +| --------------------------------- | --------------------------------------- | +| Promise<[FlashMode](#flashmode)\> | Promise used to return the flash mode.| **Example** ```js -cameraManager.createPreviewOutput(profile, surfaceId).then((previewoutput) => { - console.log('Promise returned with previewOutput created.'); +cameraInput.getFlashMode().then((flashMode) => { + console.log('Promise returned with current flash mode : ' + flashMode); }) ``` -### createDeferredPreviewOutput +### isFocusModeSupported -createDeferredPreviewOutput(profile: Profile, callback: AsyncCallback): void +isFocusModeSupported(afMode: FocusMode, callback: AsyncCallback): void -Creates a **PreviewOutput** instance without a surface ID. This API uses an asynchronous callback to return the result. +Checks whether a specified focus mode is supported. This API uses an asynchronous callback to return the result. **System capability**: SystemCapability.Multimedia.Camera.Core **Parameters** -| Name | Type | Mandatory| Description | -| -------- | ----------------------------------------------- | ---- | --------------------------------- | -| profile | [Profile](#profile) | Yes | Supported preview profile. | -| callback | AsyncCallback<[PreviewOutput](#previewoutput)\> | Yes | Callback used to return the **PreviewOutput** instance. | +| Name | Type | Mandatory| Description | +| -------- | ----------------------- | ---- | -------------------------------------- | +| afMode | [FocusMode](#focusmode) | Yes | Focus mode. | +| callback | AsyncCallback | Yes | Callback used to return the focus mode support status. The value **true** means that the focus mode is supported, and **false** means the opposite.| **Example** ```js -cameraManager.createDeferredPreviewOutput(profile, (err, previewoutput) => { +cameraInput.isFocusModeSupported(camera.FocusMode.FOCUS_MODE_AUTO, (err, status) => { if (err) { - console.error(`Failed to create deferredPreviewOutput. ${err.message}`); + console.error('Failed to check whether the focus mode is supported. ${err.message}'); return; } - console.log('Callback returned with deferredPreviewOutput created.'); + console.log('Callback returned with the focus mode support status: ' + status); }) ``` -### createDeferredPreviewOutput +### isFocusModeSupported -createDeferredPreviewOutput(profile: Profile): Promise +isFocusModeSupported(afMode: FocusMode): Promise -Creates a **PreviewOutput** instance without a surface ID. This API uses a promise to return the result. +Checks whether a specified focus mode is supported. This API uses a promise to return the result. **System capability**: SystemCapability.Multimedia.Camera.Core **Parameters** -| Name | Type | Mandatory | Description | -| -------- | ---------------------------------| ---- | ---------- | -| profile | [Profile](#profile) | Yes | Supported preview profile. | +| Name | Type | Mandatory| Description | +| ------ | ----------------------- | ---- | ---------------- | +| afMode | [FocusMode](#focusmode) | Yes | Focus mode.| **Return value** -| Type | Description | -| ----------------------------------------- | --------------------------------------- | -| Promise<[PreviewOutput](#previewoutput)\> | Promise used to return the **PreviewOutput** instance.| +| Type | Description | +| ----------------- | ----------------------------------------------------------- | +| Promise | Promise used to return the focus mode support status. The value **true** means that the focus mode is supported, and **false** means the opposite.| **Example** ```js -cameraManager.createDeferredPreviewOutput(profile).then((previewoutput) => { - console.log('Promise returned with DefeerredPreviewOutput created.'); +cameraInput.isFocusModeSupported(camera.FocusMode.FOCUS_MODE_AUTO).then((status) => { + console.log('Promise returned with focus mode support status.' + status); }) ``` -### createPhotoOutput +### setFocusMode -createPhotoOutput(profile: Profile, surfaceId: string, callback: AsyncCallback): void +setFocusMode(afMode: FocusMode, callback: AsyncCallback): void -Creates a **PhotoOutput** instance. This API uses an asynchronous callback to return the result. +Sets a focus mode. This API uses an asynchronous callback to return the result. + +Before the setting, use **[isFocusModeSupported](#isfocusmodesupported)** to check whether the focus mode is supported. **System capability**: SystemCapability.Multimedia.Camera.Core **Parameters** -| Name | Type | Mandatory| Description | -| -------- | ------------------------------------------- | ---- | ----------------------------------- | -| profile | [Profile](#profile) | Yes | Supported shooting profile. | -| surfaceId| string | Yes | Surface ID, which is obtained from **[ImageReceiver](js-apis-image.md#imagereceiver9)**.| -| callback | AsyncCallback<[PhotoOutput](#photooutput)\> | Yes | Callback used to return the **PhotoOutput** instance. | +| Name | Type | Mandatory| Description | +| -------- | ----------------------- | ---- | ------------------------ | +| afMode | [FocusMode](#focusmode) | Yes | Focus mode. | +| callback | AsyncCallback | Yes | Callback used to return the result.| **Example** ```js -cameraManager.createPhotoOutput(profile, surfaceId, (err, photooutput) => { +cameraInput.setFocusMode(camera.FocusMode.FOCUS_MODE_AUTO, (err) => { if (err) { - console.error(`Failed to create photoOutput. ${err.message}`); + console.error('Failed to set the focus mode ${err.message}'); return; } - console.log('Callback returned with photoOutput created.'); + console.log('Callback returned with the successful execution of setFocusMode.'); }) ``` -### createPhotoOutput +### setFocusMode + +setFocusMode(afMode: FocusMode): Promise -createPhotoOutput(profile: Profile, surfaceId: string): Promise +Sets a focus mode. This API uses a promise to return the result. -Creates a **PhotoOutput** instance. This API uses a promise to return the result. +Before the setting, use **[isFocusModeSupported](#isfocusmodesupported)** to check whether the focus mode is supported. **System capability**: SystemCapability.Multimedia.Camera.Core **Parameters** -| Name | Type | Mandatory| Description | -| -------- | ---------------------------------| ---- | ----------- | -| profile | [Profile](#profile) | Yes | Supported shooting profile. | -| surfaceId| string | Yes | Surface ID, which is obtained from **[ImageReceiver](js-apis-image.md#imagereceiver9)**.| +| Name | Type | Mandatory| Description | +| ------ | ----------------------- | ---- | ---------------- | +| afMode | [FocusMode](#focusmode) | Yes | Focus mode.| **Return value** -| Type | Description | -| ------------------------------------- | -------------------------------------- | -| Promise<[PhotoOutput](#photooutput)\> | Promise used to return the **PhotoOutput** instance. | +| Type | Description | +| -------------- | --------------------------- | +| Promise| Promise used to return the result.| **Example** ```js -cameraManager.createPhotoOutput(profile, surfaceId).then((photooutput) => { - console.log('Promise returned with photoOutput created.'); +cameraInput.setFocusMode(camera.FocusMode.FOCUS_MODE_AUTO).then(() => { + console.log('Promise returned with the successful execution of setFocusMode.'); }) ``` -### createVideoOutput +### getFocusMode -createVideoOutput(profile: VideoProfile, surfaceId: string, callback: AsyncCallback): void +getFocusMode(callback: AsyncCallback): void -Creates a **VideoOutput** instance. This API uses an asynchronous callback to return the result. +Obtains the focus mode in use. This API uses an asynchronous callback to return the result. **System capability**: SystemCapability.Multimedia.Camera.Core **Parameters** -| Name | Type | Mandatory| Description | -| -------- | ------------------------------------------- | ---- | ------------------------------ | -| profile | [VideoProfile](#videoprofile) | Yes | Supported video recording profile. | -| surfaceId| string | Yes | Surface ID, which is obtained from **[VideoRecorder](js-apis-media.md#videorecorder9)**.| -| callback | AsyncCallback<[VideoOutput](#videooutput)\> | Yes | Callback used to return the **VideoOutput** instance.| +| Name | Type | Mandatory| Description | +| -------- | --------------------------------------- | ---- | -------------------------------------- | +| callback | AsyncCallback<[FocusMode](#focusmode)\> | Yes | Callback used to return the focus mode.| **Example** ```js -cameraManager.createVideoOutput(profile, surfaceId, (err, videooutput) => { +cameraInput.getFocusMode((err, afMode) => { if (err) { - console.error(`Failed to create videoOutput. ${err.message}`); + console.error('Failed to get the focus mode ${err.message}'); return; } - console.log('Callback returned with an array of supported outputCapability' ); + console.log('Callback returned with current focus mode: ' + afMode); }) ``` -### createVideoOutput +### getFocusMode -createVideoOutput(profile: VideoProfile, surfaceId: string): Promise +getFocusMode(): Promise -Creates a **VideoOutput** instance. This API uses a promise to return the result. +Obtains the focus mode in use. This API uses a promise to return the result. **System capability**: SystemCapability.Multimedia.Camera.Core -**Parameters** - -| Name | Type | Mandatory| Description | -| -------- | ---------------------------------| ---- | ---------- | -| profile | [VideoProfile](#videoprofile) | Yes | Supported video recording profile. | -| surfaceId| string | Yes | Surface ID, which is obtained from **[VideoRecorder](js-apis-media.md#videorecorder9)**.| - **Return value** -| Type | Description | -| ------------------------------------- | -------------------------------------- | -| Promise<[VideoOutput](#videooutput)\> | Promise used to return the **VideoOutput** instance. | +| Type | Description | +| ------------------- | ------------------------------------- | +| Promise | Promise used to return the focus mode.| **Example** ```js -cameraManager.createVideoOutput(profile, surfaceId).then((videooutput) => { - console.log('Promise returned with videoOutput created.'); +cameraInput.getFocusMode().then((afMode) => { + console.log('Promise returned with current focus mode : ' + afMode); }) ``` -### createMetadataOutput +### getZoomRatioRange -createMetadataOutput(metadataObjectTypes: Array, callback: AsyncCallback): void +getZoomRatioRange\(callback: AsyncCallback\>\): void -Creates a **MetadataOutput** instance. This API uses an asynchronous callback to return the result. +Obtains the zoom ratio range. This API uses an asynchronous callback to return the result. **System capability**: SystemCapability.Multimedia.Camera.Core **Parameters** -| Name | Type | Mandatory| Description | -| -------------------- | -------------------------------------------------- | --- | ---------------------------- | -| metadataObjectTypes | Array<[MetadataObjectType](#metadataobjecttype)\> | Yes | Supported metadata object types. | -| callback | AsyncCallback<[MetadataOutput](#metadataoutput)\> | Yes | Callback used to return the **MetadataOutput** instance. | +| Name | Type | Mandatory| Description | +| -------- | ------------------------------ | ---- | ------------------------ | +| callback | AsyncCallback\> | Yes | Callback used to return the result.| **Example** ```js -cameraManager.createMetadataOutput(metadataObjectTypes, (err, metadataoutput) => { +cameraInput.getZoomRatioRange((err, zoomRatioRange) => { if (err) { - console.error(`Failed to create metadataOutput. ${err.message}`); + console.error('Failed to get the zoom ratio range. ${err.message}'); return; } - console.log('Callback returned with metadataOutput created.'); + console.log('Callback returned with zoom ratio range: ' + zoomRatioRange.length); }) ``` -### createMetadataOutput +### getZoomRatioRange -createMetadataOutput(metadataObjectTypes: Array): Promise +getZoomRatioRange\(\): Promise\> -Creates a **MetadataOutput** instance. This API uses a promise to return the result. +Obtains the zoom ratio range. This API uses a promise to return the result. **System capability**: SystemCapability.Multimedia.Camera.Core -**Parameters** - -| Name | Type | Mandatory| Description | -| -------------------- | -------------------------------------------------- | --- | -------------- | -| metadataObjectTypes | Array<[MetadataObjectType](#metadataobjecttype)\> | Yes | Supported metadata object types.| - **Return value** -| Type | Description | -| ------------------------------------------ | ----------------------------------------- | -| Promise<[MetadataOutput](#metadataoutput)\> | Promise used to return the **MetadataOutput** instance.| +| Type | Description | +| ------------------------ | ------------------------------------------- | +| Promise\> | Promise used to return the zoom ratio range.| **Example** ```js -cameraManager.createMetadataOutput(metadataObjectTypes).then((metadataoutput) => { - console.log('Promise returned with metadataOutput created.'); +cameraInput.getZoomRatioRange().then((zoomRatioRange) => { + console.log('Promise returned with zoom ratio range: ' + zoomRatioRange.length); }) ``` -### createCaptureSession +### setZoomRatio -createCaptureSession(callback: AsyncCallback): void +setZoomRatio(zoomRatio: number, callback: AsyncCallback): void -Creates a **CaptureSession** instance. This API uses an asynchronous callback to return the result. +Sets a zoom ratio. This API uses an asynchronous callback to return the result. **System capability**: SystemCapability.Multimedia.Camera.Core **Parameters** -| Name | Type | Mandatory | Description | -| -------------------- | ----------------------------------------- | ----------- | ---------------------------- | -| callback | AsyncCallback<[CaptureSession](#capturesession)\> | Yes | Callback used to return the **CaptureSession** instance.| +| Name | Type | Mandatory| Description | +| --------- | -------------------- | ---- | ------------------------ | +| zoomRatio | number | Yes | Zoom ratio. | +| callback | AsyncCallback | Yes | Callback used to return the result.| **Example** ```js -cameraManager.createCaptureSession((err, capturesession) => { +cameraInput.setZoomRatio(1, (err) => { if (err) { - console.error(`Failed to create captureSession. ${err.message}`); + console.error('Failed to set the zoom ratio value ${err.message}'); return; } - console.log('Callback returned with captureSession created.'); -}) -``` - -### createCaptureSession - -createCaptureSession(): Promise - -Creates a **CaptureSession** instance. This API uses a promise to return the result. - -**System capability**: SystemCapability.Multimedia.Camera.Core - -**Return value** - -| Type | Description | -| ------------------------------------------- | ---------------------------------------- | -| Promise<[CaptureSession](#capturesession)\> | Promise used to return the **CaptureSession** instance.| - -**Example** - -```js -cameraManager.createCaptureSession().then((capturesession) => { - console.log('Promise returned with captureSession created.'); + console.log('Callback returned with the successful execution of setZoomRatio.'); }) ``` -### on('cameraStatus') +### setZoomRatio -on(type: 'cameraStatus', callback: AsyncCallback): void +setZoomRatio(zoomRatio: number): Promise -Listens for camera status changes. This API uses an asynchronous callback to return the result. +Sets a zoom ratio. This API uses a promise to return the result. **System capability**: SystemCapability.Multimedia.Camera.Core **Parameters** -| Name | Type | Mandatory| Description | -| -------- | ----------------------------------------------------- | ---- | --------- | -| type | string | Yes | Event type. The value is fixed at **'cameraStatus'**, indicating the camera status change event.| -| callback | AsyncCallback<[CameraStatusInfo](#camerastatusinfo)\> | Yes | Callback used to return the camera status change. | - -**Example** - -```js -cameraManager.on('cameraStatus', (err, cameraStatusInfo) => { - if (err) { - console.error(`Failed to get cameraStatus callback. ${err.message}`); - return; - } - console.log(`camera : ${cameraStatusInfo.camera.cameraId}`); - console.log(`status: ${cameraStatusInfo.status}`); -}) -``` - -### on('cameraMute') - -on(type: 'cameraMute', callback: AsyncCallback): void - -Listens for camera mute status changes. This API uses an asynchronous callback to return the result. - -This is a system API. - -**Required permissions**: ohos.permission.CAMERA - -**System capability**: SystemCapability.Multimedia.Camera.Core +| Name | Type | Mandatory| Description | +| --------- | ------ | ---- | ------------ | +| zoomRatio | number | Yes | Zoom ratio.| -**Parameters** +**Return value** -| Name | Type | Mandatory| Description | -| -------- | --------------------------------------- | ---- | ------------------------------- | -| type | string | Yes | Event type. The value is fixed at **'cameraMute'**, indicating the camera mute status change event.| -| callback | AsyncCallback | Yes | Callback used to return the camera mute status. | +| Type | Description | +| -------------- | --------------------------- | +| Promise| Promise used to return the result.| **Example** ```js -cameraManager.on('cameraMute', (err, status) => { - if (err) { - console.error(`Failed to get cameraMute callback. ${err.message}`); - return; - } - console.log(`status: ${status}`); +cameraInput.setZoomRatio(1).then(() => { + console.log('Promise returned with the successful execution of setZoomRatio.'); }) ``` -## CameraStatusInfo - -Describes the camera status information. - -**System capability**: SystemCapability.Multimedia.Camera.Core - -| Name | Type | Description | -| ------ | ----------------------------- | ---------- | -| camera | [CameraDevice](#cameradevice) | Camera object.| -| status | [CameraStatus](#camerastatus) | Camera status.| - -## CameraPosition - -Enumerates the camera positions. - -**System capability**: SystemCapability.Multimedia.Camera.Core - -| Name | Value | Description | -| --------------------------- | ---- | -------------- | -| CAMERA_POSITION_UNSPECIFIED | 0 | Unspecified position. | -| CAMERA_POSITION_BACK | 1 | Rear camera. | -| CAMERA_POSITION_FRONT | 2 | Front camera. | - -## CameraType - -Enumerates the camera types. - -**System capability**: SystemCapability.Multimedia.Camera.Core - -| Name | Value | Description | -| ----------------------- | ---- | -------------- | -| CAMERA_TYPE_UNSPECIFIED | 0 | Unspecified camera type. | -| CAMERA_TYPE_WIDE_ANGLE | 1 | Wide camera. | -| CAMERA_TYPE_ULTRA_WIDE | 2 | Ultra wide camera. | -| CAMERA_TYPE_TELEPHOTO | 3 | Telephoto camera. | -| CAMERA_TYPE_TRUE_DEPTH | 4 | Camera with depth of field information.| - -## ConnectionType - -Enumerates the camera connection types. - -**System capability**: SystemCapability.Multimedia.Camera.Core - -| Name | Value | Description | -| ---------------------------- | ---- | ------------- | -| CAMERA_CONNECTION_BUILT_IN | 0 | Built-in camera. | -| CAMERA_CONNECTION_USB_PLUGIN | 1 | Camera connected using USB.| -| CAMERA_CONNECTION_REMOTE | 2 | Remote camera.| - -## CameraDevice - -Defines the camera device information. - -**System capability**: SystemCapability.Multimedia.Camera.Core - -| Name | Type | Read only| Description | -| -------------- | --------------------------------- | ---- | ---------- | -| cameraId | string | Yes | **CameraDevice** object.| -| cameraPosition | [CameraPosition](#cameraposition) | Yes | Camera position. | -| cameraType | [CameraType](#cameratype) | Yes | Camera type. | -| connectionType | [ConnectionType](#connectiontype) | Yes | Camera connection type.| - -**Example** - -```js -async function getCameraInfo("cameraId") { - let cameraManager = await camera.getCameraManager(context); - let cameras = await cameraManager.getSupportedCameras(); - let cameraObj = cameras[0]; - let cameraId = cameraObj.cameraId; - let cameraPosition = cameraObj.cameraPosition; - let cameraType = cameraObj.cameraType; - let connectionType = cameraObj.connectionType; -} -``` - -## Size - -Enumerates the camera output capability. - -**System capability**: SystemCapability.Multimedia.Camera.Core - -| Name | Type | Readable| Writable| Description | -| ------ | ------ | ---- | ---- | ------------ | -| height | number | Yes | Yes | Image height, in pixels.| -| width | number | Yes | Yes | Image width, in pixels.| - -## Point - -Enumerates the point coordinates, which are used for focus and exposure configuration. - -**System capability**: SystemCapability.Multimedia.Camera.Core - -| Name | Type | Mandatory | Description | -| ------ | ------ | ---- | ------------ | -| x | number | Yes | X coordinate of a point. | -| y | number | Yes | Y coordinate of a point. | - -## CameraFormat - -Enumerates the camera output formats. - -**System capability**: SystemCapability.Multimedia.Camera.Core - -| Name | Default Value | Description | -| ----------------------- | --------- | ------------ | -| CAMERA_FORMAT_YUV_420_SP| 1003 | YUV 420 SP image. | -| CAMERA_FORMAT_JPEG | 2000 | JPEG image. | - -## CameraInput - -Provides camera information used in **[CaptureSession](#capturesession)**. - -### open +### getZoomRatio -open\(callback: AsyncCallback\): void +getZoomRatio(callback: AsyncCallback): void -Opens this camera. This API uses an asynchronous callback to return the result. +Obtains the zoom ratio in use. This API uses an asynchronous callback to return the result. **System capability**: SystemCapability.Multimedia.Camera.Core **Parameters** -| Name | Type | Mandatory| Description | -| -------- | -------------------- | ---- | ------------------- | -| callback | AsyncCallback | Yes | Callback used to return the result.| +| Name | Type | Mandatory| Description | +| -------- | ---------------------- | ---- | ------------------------ | +| callback | AsyncCallback | Yes | Callback used to return the result.| **Example** ```js -cameraInput.open((err) => { +cameraInput.getZoomRatio((err, zoomRatio) => { if (err) { - console.error(`Failed to open the camera. ${err.message}`); + console.error('Failed to get the zoom ratio ${err.message}'); return; } - console.log('Callback returned with camera opened.'); + console.log('Callback returned with current zoom ratio: ' + zoomRatio); }) ``` -### open +### getZoomRatio -open(): Promise +getZoomRatio(): Promise -Opens this camera. This API uses a promise to return the result. +Obtains the zoom ratio in use. This API uses a promise to return the result. **System capability**: SystemCapability.Multimedia.Camera.Core **Return value** -| Type | Description | -| -------------- | ----------------------- | -| Promise| Promise used to return the result.| +| Type | Description | +| ---------------- | --------------------------- | +| Promise | Promise used to return the zoom ratio.| **Example** ```js -cameraInput.open().then(() => { - console.log('Promise returned with camera opened.'); +cameraInput.getZoomRatio().then((zoomRatio) => { + console.log('Promise returned with current zoom ratio : ' + zoomRatio); }) ``` -### close +### release -close\(callback: AsyncCallback\): void +release\(callback: AsyncCallback\): void -Closes this camera. This API uses an asynchronous callback to return the result. +Releases this **CameraInput** instance. This API uses an asynchronous callback to return the result. **System capability**: SystemCapability.Multimedia.Camera.Core **Parameters** -| Name | Type | Mandatory| Description | -| -------- | -------------------- | ---- | -------------------- | +| Name | Type | Mandatory| Description | +| -------- | -------------------- | ---- | ------------------------ | | callback | AsyncCallback | Yes | Callback used to return the result.| **Example** ```js -cameraInput.close((err) => { +cameraInput.release((err) => { if (err) { - console.error(`Failed to close the cameras. ${err.message}`); + console.error('Failed to release the CameraInput instance ${err.message}'); return; } - console.log('Callback returned with camera closed.'); -}) + console.log('Callback invoked to indicate that the CameraInput instance is released successfully.'); +}); ``` -### close +### release -close(): Promise +release(): Promise -Closes this camera. This API uses a promise to return the result. +Releases this **CameraInput** instance. This API uses a promise to return the result. **System capability**: SystemCapability.Multimedia.Camera.Core **Return value** -| Type | Description | -| -------------- | ----------------------- | +| Type | Description | +| -------------- | --------------------------- | | Promise| Promise used to return the result.| **Example** ```js -cameraInput.close().then(() => { - console.log('Promise returned with camera closed.'); +cameraInput.release().then(() => { + console.log('Promise returned to indicate that the CameraInput instance is released successfully.'); }) ``` -### release +### on('focusStateChange') -release\(callback: AsyncCallback\): void +on(type: 'focusStateChange', callback: AsyncCallback): void -Releases this camera. This API uses an asynchronous callback to return the result. +Listens for focus state changes. This API uses an asynchronous callback to return the result. **System capability**: SystemCapability.Multimedia.Camera.Core **Parameters** -| Name | Type | Mandatory| Description | -| -------- | -------------------- | ---- | ------------------- | -| callback | AsyncCallback | Yes | Callback used to return the result.| - -**Example** - -```js -cameraInput.release((err) => { - if (err) { - console.error(`Failed to release the CameraInput instance ${err.message}`); - return; - } - console.log('Callback invoked to indicate that the CameraInput instance is released successfully.'); -}); -``` - -### release - -release(): Promise - -Releases this camera. This API uses a promise to return the result. - -**System capability**: SystemCapability.Multimedia.Camera.Core - -**Return value** - -| Type | Description | -| -------------- | ----------------------- | -| Promise| Promise used to return the result.| +| Name | Type | Mandatory| Description | +| :------- | :---------------------------------------- | :--- | :------------------------------------------------------- | +| type | string | Yes | Event type. The value is fixed at **'focusStateChange'**, indicating the focus state change event.| +| callback | AsyncCallback<[FocusState](#focusstate)\> | Yes | Callback used to return the focus state change. | **Example** ```js -cameraInput.release().then(() => { - console.log('Promise returned to indicate that the CameraInput instance is released successfully.'); +cameraInput.on('focusStateChange', (focusState) => { + console.log('Focus state : ' + focusState); }) ``` @@ -1234,42 +1032,37 @@ Listens for **CameraInput** errors. This API uses a callback to return the resul **Parameters** -| Name | Type | Mandatory| Description | -| -------- | -------------------------------- | ---- | ------------------------------------------- | +| Name | Type | Mandatory| Description | +| :------- | :------------------------------- | :--- | :----------------------------------------------- | | type | string | Yes | Event type. The value is fixed at **'error'**, indicating the camera input error event.| -| callback | ErrorCallback<[CameraInputError](#camerainputerror)\> | Yes | Callback used to return the result. | +| callback | ErrorCallback<[CameraInputError](#camerainputerror)\> | Yes | Callback used to return the result. | **Example** ```js cameraInput.on('error', (cameraInputError) => { - console.log(`Camera input error code: ${cameraInputError.code}`); + console.log('Camera input error code: ' + cameraInputError.code); }) ``` -## CameraInputErrorCode +## CameraInputErrorCode -Enumerates the error codes used for camera input. +Enumerates the error codes used in a **CameraInput** instance. **System capability**: SystemCapability.Multimedia.Camera.Core -| Name | Value | Description | -| ------------------------- | ---- | ---------- | -| ERROR_UNKNOWN | -1 | Unknown error.| -| ERROR_NO_PERMISSION | 0 | You do not have the required permission.| -| ERROR_DEVICE_PREEMPTED | 1 | The camera is preempted.| -| ERROR_DEVICE_DISCONNECTED | 2 | The camera is disconnected.| -| ERROR_DEVICE_IN_USE | 3 | The camera is in use.| -| ERROR_DRIVER_ERROR | 4 | Driver error. | +| Name | Value | Description | +| ------------- | ---- | ---------- | +| ERROR_UNKNOWN | -1 | Unknown error.| -## CameraInputError +## CameraInputError -Defines an error object used for **[CameraInput](#camerainput)**. +Defines a **CameraInput** error. **System capability**: SystemCapability.Multimedia.Camera.Core -| Name| Type | Description | -| ---- | --------------------------------------------- | --------------------- | +| Name| Type | Description | +| ---- | ------------------------------------------- | -------------------------- | | code | [CameraInputErrorCode](#camerainputerrorcode) | **CameraInput** error code.| @@ -1279,37 +1072,25 @@ Enumerates the flash modes. **System capability**: SystemCapability.Multimedia.Camera.Core -| Name | Value | Description | -| ---------------------- | ---- | ---------- | +| Name | Value | Description | +| ---------------------- | ---- | ------------ | | FLASH_MODE_CLOSE | 0 | The flash is off.| | FLASH_MODE_OPEN | 1 | The flash is on.| | FLASH_MODE_AUTO | 2 | The flash mode is auto, indicating that the flash fires automatically depending on the shooting conditions.| | FLASH_MODE_ALWAYS_OPEN | 3 | The flash is steady on.| -## ExposureMode - -Enumerates the exposure modes. - -**System capability**: SystemCapability.Multimedia.Camera.Core - -| Name | Value | Description | -| ----------------------------- | ---- | ----------- | -| EXPOSURE_MODE_LOCKED | 0 | Exposure locked.| -| EXPOSURE_MODE_AUTO | 1 | Auto exposure.| -| EXPOSURE_MODE_CONTINUOUS_AUTO | 2 | Continuous auto exposure.| - ## FocusMode Enumerates the focus modes. **System capability**: SystemCapability.Multimedia.Camera.Core -| Name | Value | Description | -| -------------------------- | ---- | ------------ | +| Name | Value | Description | +| -------------------------- | ---- | ------------------ | | FOCUS_MODE_MANUAL | 0 | Manual focus. | | FOCUS_MODE_CONTINUOUS_AUTO | 1 | Continuous auto focus.| | FOCUS_MODE_AUTO | 2 | Auto focus. | -| FOCUS_MODE_LOCKED | 3 | Focus locked. | +| FOCUS_MODE_LOCKED | 3 | Focus locked. | ## FocusState @@ -1317,40 +1098,70 @@ Enumerates the focus states. **System capability**: SystemCapability.Multimedia.Camera.Core -| Name | Value | Description | -| --------------------- | ---- | --------- | -| FOCUS_STATE_SCAN | 0 | Focusing. | -| FOCUS_STATE_FOCUSED | 1 | Focused. | +| Name | Value | Description | +| --------------------- | ---- | ------------ | +| FOCUS_STATE_SCAN | 0 | Focusing. | +| FOCUS_STATE_FOCUSED | 1 | Focused.| | FOCUS_STATE_UNFOCUSED | 2 | Unfocused.| -## ExposureState +## camera.createCaptureSession + +createCaptureSession\(context: Context, callback: AsyncCallback\): void -Enumerates the exposure states. +Creates a **CaptureSession** instance. This API uses an asynchronous callback to return the result. **System capability**: SystemCapability.Multimedia.Camera.Core -| Name | Value | Description | -| ------------------------- | ---- | -------- | -| EXPOSURE_STATE_SCAN | 0 | Exposing. | -| EXPOSURE_STATE_CONVERGED | 1 | Exposure converged.| +**Parameters** + +| Name | Type | Mandatory| Description | +| -------- | ------------------------------------------------- | ---- | -------------------------------------- | +| context | Context | Yes | Application context. | +| callback | AsyncCallback<[CaptureSession](#capturesession)\> | Yes | Callback used to return the **CaptureSession** instance.| + +**Example** + +```js +camera.createCaptureSession((context), (err, captureSession) => { + if (err) { + console.error('Failed to create the CaptureSession instance. ${err.message}'); + return; + } + console.log('Callback returned with the CaptureSession instance.' + captureSession); +}); +``` + +## camera.createCaptureSession -## VideoStabilizationMode +createCaptureSession(context: Context\): Promise; -Enumerates the video stabilization modes. +Creates a **CaptureSession** instance. This API uses a promise to return the result. **System capability**: SystemCapability.Multimedia.Camera.Core -| Name | Value | Description | -| --------- | ---- | ------------ | -| OFF | 0 | Video stabilization is disabled. | -| LOW | 1 | The basic video stabilization algorithm is used. | -| MIDDLE | 2 | A video stabilization algorithm with a stabilization effect better than that of the **LOW** type is used. | -| HIGH | 3 | A video stabilization algorithm with a stabilization effect better than that of the **MIDDLE** type is used. | -| AUTO | 4 | Automatic video stabilization is used. | +**Parameters** + +| Name | Type | Mandatory| Description | +| ------- | ------- | ---- | ------------ | +| context | Context | Yes | Application context.| + +**Return value** + +| Type | Description | +| ------------------------------------------- | ----------------------------------------- | +| Promise<[CaptureSession](#capturesession)\> | Promise used to return the **CaptureSession** instance.| + +**Example** + +```js +camera.createCaptureSession(context).then((captureSession) => { + console.log('Promise returned with the CaptureSession instance'); +}) +``` ## CaptureSession -Implements a shooting session, which saves all **[CameraInput](#camerainput)** and **[CameraOutput](#cameraoutput)** instances required to run the camera and requests the camera to complete shooting or video recording. +Implements a shooting session. ### beginConfig @@ -1362,8 +1173,8 @@ Starts configuration for this **CaptureSession** instance. This API uses an asyn **Parameters** -| Name | Type | Mandatory| Description | -| -------- | -------------------- | ---- | ------------------- | +| Name | Type | Mandatory| Description | +| -------- | -------------------- | ---- | ------------------------ | | callback | AsyncCallback | Yes | Callback used to return the result.| **Example** @@ -1371,7 +1182,7 @@ Starts configuration for this **CaptureSession** instance. This API uses an asyn ```js captureSession.beginConfig((err) => { if (err) { - console.error(`Failed to start the configuration. ${err.message}`); + console.error('Failed to start the configuration. ${err.message}'); return; } console.log('Callback invoked to indicate the begin config success.'); @@ -1388,8 +1199,8 @@ Starts configuration for this **CaptureSession** instance. This API uses a promi **Return value** -| Type | Description | -| -------------- | ------------------------ | +| Type | Description | +| -------------- | --------------------------- | | Promise| Promise used to return the result.| @@ -1411,8 +1222,8 @@ Commits the configuration for this **CaptureSession** instance. This API uses an **Parameters** -| Name | Type | Mandatory| Description | -| -------- | -------------------- | ---- | -------------------- | +| Name | Type | Mandatory| Description | +| -------- | -------------------- | ---- | ------------------------ | | callback | AsyncCallback | Yes | Callback used to return the result.| **Example** @@ -1420,7 +1231,7 @@ Commits the configuration for this **CaptureSession** instance. This API uses an ```js captureSession.commitConfig((err) => { if (err) { - console.error(`Failed to commit the configuration. ${err.message}`); + console.error('Failed to commit the configuration. ${err.message}'); return; } console.log('Callback invoked to indicate the commit config success.'); @@ -1437,8 +1248,8 @@ Commits the configuration for this **CaptureSession** instance. This API uses a **Return value** -| Type | Description | -| -------------- | ------------------------ | +| Type | Description | +| -------------- | --------------------------- | | Promise| Promise used to return the result.| **Example** @@ -1449,529 +1260,546 @@ captureSession.commitConfig().then(() => { }) ``` -### canAddInput +### addInput -canAddInput(cameraInput: CameraInput, callback: AsyncCallback): void +addInput\(cameraInput: CameraInput, callback: AsyncCallback\): void -Checks whether a **[CameraInput](#camerainput)** instance can be added to this **CaptureSession**. This API uses an asynchronous callback to return the result. +Adds a **CameraInput** instance to this **CaptureSession** instance. This API uses an asynchronous callback to return the result. **System capability**: SystemCapability.Multimedia.Camera.Core **Parameters** -| Name | Type | Mandatory| Description | -| ----------- | --------------------------- | ---- | ------------------------ | +| Name | Type | Mandatory| Description | +| ----------- | --------------------------- | ---- | --------------------------- | | cameraInput | [CameraInput](#camerainput) | Yes | **CameraInput** instance to add.| -| callback | AsyncCallback | Yes | Callback used to return the result. | +| callback | AsyncCallback | Yes | Callback used to return the result. | **Example** ```js -captureSession.canAddInput(cameraInput, (err, status) => { +captureSession.addInput(cameraInput, (err) => { if (err) { - console.error(`Can not add cameraInput. ${err.message}`); + console.error('Failed to add the CameraInput instance. ${err.message}'); return; } - console.log('Callback returned with cameraInput can added.'); -}) + console.log('Callback invoked to indicate that the CameraInput instance is added.'); +}); ``` -### canAddInput +### addInput -canAddInput(cameraInput: CameraInput): Promise +addInput\(cameraInput: CameraInput\): Promise -Checks whether a **[CameraInput](#camerainput)** instance can be added to this **CaptureSession**. This API uses a promise to return the result. +Adds a **CameraInput** instance to this **CaptureSession** instance. This API uses a promise to return the result. **System capability**: SystemCapability.Multimedia.Camera.Core **Parameters** -| Name | Type | Mandatory| Description | -| ----------- | --------------------------- | ---- | ------------------------ | +| Name | Type | Mandatory| Description | +| ----------- | --------------------------- | ---- | --------------------------- | | cameraInput | [CameraInput](#camerainput) | Yes | **CameraInput** instance to add.| **Return value** -| Type | Description | -| -------------- | -------------------------- | -| Promise | Promise used to return the result.| +| Type | Description | +| -------------- | --------------------------- | +| Promise| Promise used to return the result.| **Example** ```js -captureSession.canAddInput(cameraInput).then(() => { - console.log('Promise returned with cameraInput can added.'); +captureSession.addInput(cameraInput).then(() => { + console.log('Promise used to indicate that the CameraInput instance is added.'); }) ``` -### addInput +### addOutput -addInput\(cameraInput: CameraInput, callback: AsyncCallback\): void +addOutput\(previewOutput: PreviewOutput, callback: AsyncCallback\): void -Adds a **[CameraInput](#camerainput)** instance to this **CaptureSession**. This API uses an asynchronous callback to return the result. +Adds a **PreviewOutput** instance to this **CaptureSession** instance. This API uses an asynchronous callback to return the result. **System capability**: SystemCapability.Multimedia.Camera.Core **Parameters** -| Name | Type | Mandatory| Description | -| ----------- | --------------------------- | ---- | ------------------------ | -| cameraInput | [CameraInput](#camerainput) | Yes | **CameraInput** instance to add.| -| callback | AsyncCallback | Yes | Callback used to return the result. | +| Name | Type | Mandatory| Description | +| ------------- | ------------------------------- | ---- | ----------------------------- | +| previewOutput | [PreviewOutput](#previewoutput) | Yes | **PreviewOutput** instance to add.| +| callback | AsyncCallback | Yes | Callback used to return the result. | **Example** ```js -captureSession.addInput(cameraInput, (err) => { +captureSession.addOutput(previewOutput, (err) => { if (err) { - console.error(`Failed to add the CameraInput instance. ${err.message}`); + console.error('Failed to add the PreviewOutput instance ${err.message}'); return; } - console.log('Callback invoked to indicate that the CameraInput instance is added.'); + console.log('Callback invoked to indicate that the PreviewOutput instance is added.'); }); ``` -### addInput +### addOutput -addInput\(cameraInput: CameraInput\): Promise +addOutput\(previewOutput: PreviewOutput\): Promise -Adds a **[CameraInput](#camerainput)** instance to this **CaptureSession**. This API uses a promise to return the result. +Adds a **PreviewOutput** instance to this **CaptureSession** instance. This API uses a promise to return the result. **System capability**: SystemCapability.Multimedia.Camera.Core **Parameters** -| Name | Type | Mandatory| Description | -| ----------- | --------------------------- | ---- | ------------------------ | -| cameraInput | [CameraInput](#camerainput) | Yes | **CameraInput** instance to add.| +| Name | Type | Mandatory| Description | +| ------------- | ------------------------------- | ---- | ----------------------------- | +| previewOutput | [PreviewOutput](#previewoutput) | Yes | **PreviewOutput** instance to add.| **Return value** -| Type | Description | -| -------------- | ------------------------ | +| Type | Description | +| -------------- | --------------------------- | | Promise| Promise used to return the result.| **Example** ```js -captureSession.addInput(cameraInput).then(() => { - console.log('Promise used to indicate that the CameraInput instance is added.'); +captureSession.addOutput(previewOutput).then(() => { + console.log('Promise used to indicate that the PreviewOutput instance is added.'); }) ``` -### removeInput +### addOutput -removeInput\(cameraInput: CameraInput, callback: AsyncCallback\): void +addOutput\(photoOutput: PhotoOutput, callback: AsyncCallback\): void -Removes a **[CameraInput](#camerainput)** instance from this **CaptureSession**. This API uses an asynchronous callback to return the result. +Adds a **PhotoOutput** instance to this **CaptureSession** instance. This API uses an asynchronous callback to return the result. **System capability**: SystemCapability.Multimedia.Camera.Core **Parameters** -| Name | Type | Mandatory| Description | -| ----------- | --------------------------- | ---- | ------------------------ | -| cameraInput | [CameraInput](#camerainput) | Yes | **CameraInput** instance to remove.| +| Name | Type | Mandatory| Description | +| ----------- | --------------------------- | ---- | --------------------------- | +| photoOutput | [PhotoOutput](#photooutput) | Yes | **PhotoOutput** instance to add.| | callback | AsyncCallback | Yes | Callback used to return the result. | **Example** ```js -captureSession.removeInput(cameraInput, (err) => { +captureSession.addOutput(photoOutput, (err) => { if (err) { - console.error(`Failed to remove the CameraInput instance. ${err.message}`); + console.error('Failed to add the PhotoOutput instance ${err.message}'); return; } - console.log('Callback invoked to indicate that the cameraInput instance is removed.'); + console.log('Callback invoked to indicate that the PhotoOutput instance is added.'); }); ``` -### removeInput +### addOutput -removeInput\(cameraInput: CameraInput\): Promise +addOutput\(photoOutput: PhotoOutput\): Promise -Removes a **[CameraInput](#camerainput)** instance from this **CaptureSession**. This API uses a promise to return the result. +Adds a **PhotoOutput** instance to this **CaptureSession** instance. This API uses a promise to return the result. **System capability**: SystemCapability.Multimedia.Camera.Core **Parameters** -| Name | Type | Mandatory| Description | -| ----------- | --------------------------- | ---- | ------------------------ | -| cameraInput | [CameraInput](#camerainput) | Yes | **CameraInput** instance to remove.| +| Name | Type | Mandatory| Description | +| ----------- | --------------------------- | ---- | --------------------------- | +| photoOutput | [PhotoOutput](#photooutput) | Yes | **PhotoOutput** instance to add.| **Return value** -| Type | Description | -| -------------- | ------------------------- | -| Promise\ | Promise used to return the result.| +| Type | Description | +| -------------- | --------------------------- | +| Promise\ | Promise used to return the result.| **Example** ```js -captureSession.removeInput(cameraInput).then(() => { - console.log('Promise returned to indicate that the cameraInput instance is removed.'); +captureSession.addOutput(photoOutput).then(() => { + console.log('Promise used to indicate that the PhotoOutput instance is added.'); }) ``` -### canAddOutput +### addOutput -canAddOutput(cameraOutput: CameraOutput, callback: AsyncCallback\): void +addOutput\(videoOutput: VideoOutput, callback: AsyncCallback\): void -Checks whether a **[CameraOutput](#cameraoutput)** instance can be added to this **CaptureSession**. This API uses an asynchronous callback to return the result. +Adds a **VideoOutput** instance to this **CaptureSession** instance. This API uses an asynchronous callback to return the result. **System capability**: SystemCapability.Multimedia.Camera.Core **Parameters** -| Name | Type | Mandatory| Description | -| ------------- | ------------------------------- | ---- | ------------------------- | -| cameraOutput | [CameraOutput](#cameraoutput) | Yes | **CameraOutput** instance to add.| -| callback | AsyncCallback | Yes | Callback used to return the result. | +| Name | Type | Mandatory| Description | +| ----------- | --------------------------- | ---- | --------------------------- | +| videoOutput | [VideoOutput](#videooutput) | Yes | **VideoOutput** instance to add.| +| callback | AsyncCallback | Yes | Callback used to return the result. | **Example** ```js -captureSession.canAddOutput(cameraOutput, (err, status) => { +captureSession.addOutput(videoOutput, (err) => { if (err) { - console.error(`Can not add cameraOutput. ${err.message}`); + console.error('Failed to add the VideoOutput instance ${err.message}'); return; } - console.log('Callback returned with cameraOutput can added.'); -}) + console.log('Callback invoked to indicate that the VideoOutput instance is added.'); +}); ``` -### canAddOutput +### addOutput -canAddOutput(cameraOutput: CameraOutput): Promise +addOutput\(videoOutput: VideoOutput\): Promise -Checks whether a **[CameraOutput](#cameraoutput)** instance can be added to this **CaptureSession**. This API uses a promise to return the result. +Adds a **VideoOutput** instance to this **CaptureSession** instance. This API uses a promise to return the result. **System capability**: SystemCapability.Multimedia.Camera.Core **Parameters** -| Name | Type | Mandatory| Description | -| ------------- | ------------------------------- | ---- | ------------------------- | -| cameraOutput | [CameraOutput](#cameraoutput) | Yes | **CameraOutput** instance to add.| - +| Name | Type | Mandatory| Description | +| ----------- | --------------------------- | ---- | --------------------------- | +| videoOutput | [VideoOutput](#videooutput) | Yes | **VideoOutput** instance to add.| **Return value** -| Type | Description | +| Type | Description | | -------------- | --------------------------- | -| Promise | Promise used to return the result.| - +| Promise\ | Promise used to return the result.| **Example** ```js -captureSession.canAddOutput(cameraOutput).then(() => { - console.log('Promise returned with cameraOutput can added.'); +captureSession.addOutput(videoOutput).then(() => { + console.log('Promise used to indicate that the VideoOutput instance is added.'); }) ``` -### addOutput +### removeInput -addOutput\(cameraOutput: CameraOutput, callback: AsyncCallback\): void +removeInput\(cameraInput: CameraInput, callback: AsyncCallback\): void -Adds a **[CameraOutput](#cameraoutput)** instance to this **CaptureSession**. This API uses an asynchronous callback to return the result. +Removes a **CameraInput** instance from this **CaptureSession** instance. This API uses an asynchronous callback to return the result. **System capability**: SystemCapability.Multimedia.Camera.Core **Parameters** -| Name | Type | Mandatory| Description | -| ------------- | ------------------------------- | ---- | ------------------------ | -| cameraOutput | [CameraOutput](#cameraoutput) | Yes | **CameraOutput** instance to add.| -| callback | AsyncCallback | Yes | Callback used to return the result. | +| Name | Type | Mandatory| Description | +| ----------- | --------------------------- | ---- | --------------------------- | +| cameraInput | [CameraInput](#camerainput) | Yes | **CameraInput** instance to remove.| +| callback | AsyncCallback | Yes | Callback used to return the result. | **Example** ```js -captureSession.addOutput(cameraOutput, (err) => { +captureSession.removeInput(cameraInput, (err) => { if (err) { - console.error(`Failed to add output. ${err.message}`); + console.error('Failed to remove the CameraInput instance. ${err.message}'); return; } - console.log('Callback returned with output added.'); -}) + console.log('Callback invoked to indicate that the cameraInput instance is removed.'); +}); ``` -### addOutput +### removeInput -addOutput\(cameraOutput: CameraOutput\): Promise +removeInput\(cameraInput: CameraInput\): Promise -Adds a **[CameraOutput](#cameraoutput)** instance to this **CaptureSession**. This API uses a promise to return the result. +Removes a **CameraInput** instance from this **CaptureSession** instance. This API uses a promise to return the result. **System capability**: SystemCapability.Multimedia.Camera.Core **Parameters** -| Name | Type | Mandatory| Description | -| ------------- | ------------------------------- | ---- | ------------------------- | -| cameraOutput | [CameraOutput](#cameraoutput) | Yes | **CameraOutput** instance to add.| +| Name | Type | Mandatory| Description | +| ----------- | --------------------------- | ---- | --------------------------- | +| cameraInput | [CameraInput](#camerainput) | Yes | **CameraInput** instance to remove.| **Return value** -| Type | Description | -| -------------- | ----------------------- | -| Promise| Promise used to return the result.| +| Type | Description | +| -------------- | --------------------------- | +| Promise\ | Promise used to return the result.| **Example** ```js -captureSession.addOutput(cameraOutput).then(() => { - console.log('Promise returned with cameraOutput added.'); +captureSession.removeInput(cameraInput).then(() => { + console.log('Promise returned to indicate that the cameraInput instance is removed.'); }) ``` ### removeOutput -removeOutput\(cameraOutput: CameraOutput, callback: AsyncCallback\): void +removeOutput\(previewOutput: PreviewOutput, callback: AsyncCallback\): void -Removes a **[CameraOutput](#cameraoutput)** instance from this **CaptureSession**. This API uses an asynchronous callback to return the result. +Removes a **PreviewOutput** instance from this **CaptureSession** instance. This API uses an asynchronous callback to return the result. **System capability**: SystemCapability.Multimedia.Camera.Core **Parameters** -| Name | Type | Mandatory| Description | -| ------------- | ------------------------------- | ---- | ------------------------ | -| cameraOutput | [CameraOutput](#cameraoutput) | Yes | **CameraOutput** instance to remove.| +| Name | Type | Mandatory| Description | +| ------------- | ------------------------------- | ---- | ----------------------------- | +| previewOutput | [PreviewOutput](#previewoutput) | Yes | **PreviewOutput** instance to remove.| | callback | AsyncCallback | Yes | Callback used to return the result. | **Example** ```js -captureSession.removeOutput(cameraOutput, (err) => { +captureSession.removeOutput(previewOutput, (err) => { if (err) { - console.error(`Failed to remove the CameraOutput instance. ${err.message}`); + console.error('Failed to remove the PreviewOutput instance. ${err.message}'); return; } - console.log('Callback invoked to indicate that the CameraOutput instance is removed.'); + console.log('Callback invoked to indicate that the PreviewOutput instance is removed.'); }); ``` ### removeOutput -removeOutput(cameraOutput: CameraOutput): Promise +removeOutput(previewOutput: PreviewOutput): Promise -Removes a **[CameraOutput](#cameraoutput)** instance from this **CaptureSession**. This API uses a promise to return the result. +Removes a **PreviewOutput** instance from this **CaptureSession** instance. This API uses a promise to return the result. **System capability**: SystemCapability.Multimedia.Camera.Core **Parameters** -| Name | Type | Mandatory| Description | -| ------------- | ------------------------------- | ---- | ------------------------- | -| cameraOutput | [CameraOutput](#cameraoutput) | Yes | **CameraOutput** instance to remove.| +| Name | Type | Mandatory| Description | +| ------------- | ------------------------------- | ---- | ----------------------------- | +| previewOutput | [PreviewOutput](#previewoutput) | Yes | **PreviewOutput** instance to remove.| **Return value** -| Type | Description | -| -------------- | ------------------------ | +| Type | Description | +| -------------- | --------------------------- | | Promise| Promise used to return the result.| **Example** ```js -captureSession.removeOutput(cameraOutput).then(() => { - console.log('Promise returned to indicate that the CameraOutput instance is removed.'); +captureSession.removeOutput(previewOutput).then(() => { + console.log('Promise returned to indicate that the PreviewOutput instance is removed.'); }) ``` -### start +### removeOutput -start\(callback: AsyncCallback\): void +removeOutput(photoOutput: PhotoOutput, callback: AsyncCallback): void -Starts this **CaptureSession**. This API uses an asynchronous callback to return the result. +Removes a **PhotoOutput** instance from this **CaptureSession** instance. This API uses an asynchronous callback to return the result. **System capability**: SystemCapability.Multimedia.Camera.Core **Parameters** -| Name | Type | Mandatory| Description | -| -------- | -------------------- | ---- | -------------------- | -| callback | AsyncCallback | Yes | Callback used to return the result.| +| Name | Type | Mandatory| Description | +| ----------- | --------------------------- | ---- | --------------------------- | +| photoOutput | [PhotoOutput](#photooutput) | Yes | **PhotoOutput** instance to remove.| +| callback | AsyncCallback | Yes | Callback used to return the result. | **Example** ```js -captureSession.start((err) => { +captureSession.removeOutput(photoOutput, (err) => { if (err) { - console.error(`Failed to start the session ${err.message}`); + console.error('Failed to remove the PhotoOutput instance. ${err.message}'); return; } - console.log('Callback invoked to indicate the session start success.'); + console.log('Callback invoked to indicate that the PhotoOutput instance is removed.'); }); ``` -### start +### removeOutput -start\(\): Promise +removeOutput(photoOutput: PhotoOutput): Promise -Starts this **CaptureSession**. This API uses a promise to return the result. +Removes a **PhotoOutput** instance from this **CaptureSession** instance. This API uses a promise to return the result. **System capability**: SystemCapability.Multimedia.Camera.Core +**Parameters** + +| Name | Type | Mandatory| Description | +| ----------- | --------------------------- | ---- | --------------------------- | +| photoOutput | [PhotoOutput](#photooutput) | Yes | **PhotoOutput** instance to remove.| + + **Return value** -| Type | Description | -| -------------- | ------------------------ | +| Type | Description | +| -------------- | --------------------------- | | Promise| Promise used to return the result.| + **Example** ```js -captureSession.start().then(() => { - console.log('Promise returned to indicate the session start success.'); +captureSession.removeOutput(photoOutput).then(() => { + console.log('Promise returned to indicate that the PhotoOutput instance is removed.'); }) ``` -### stop +### removeOutput -stop\(callback: AsyncCallback\): void +removeOutput(videoOutput: VideoOutput, callback: AsyncCallback): void -Stops this **CaptureSession**. This API uses an asynchronous callback to return the result. +Removes a **VideoOutput** instance from this **CaptureSession** instance. This API uses an asynchronous callback to return the result. **System capability**: SystemCapability.Multimedia.Camera.Core **Parameters** -| Name | Type | Mandatory| Description | -| -------- | -------------------- | ---- | ------------------- | -| callback | AsyncCallback | Yes | Callback used to return the result.| +| Name | Type | Mandatory| Description | +| ----------- | --------------------------- | ---- | --------------------------- | +| videoOutput | [VideoOutput](#videooutput) | Yes | **VideoOutput** instance to remove.| +| callback | AsyncCallback | Yes | Callback used to return the result. | **Example** ```js -captureSession.stop((err) => { +captureSession.removeOutput(videoOutput, (err) => { if (err) { - console.error(`Failed to stop the session ${err.message}`); + console.error('Failed to remove the VideoOutput instance. ${err.message}'); return; } - console.log('Callback invoked to indicate the session stop success.'); + console.log('Callback invoked to indicate that the VideoOutput instance is removed.'); }); ``` -### stop +### removeOutput -stop(): Promise +removeOutput(videoOutput: VideoOutput): Promise -Stops this **CaptureSession**. This API uses a promise to return the result. +Removes a **VideoOutput** instance from this **CaptureSession** instance. This API uses a promise to return the result. **System capability**: SystemCapability.Multimedia.Camera.Core +**Parameters** + +| Name | Type | Mandatory| Description | +| ----------- | --------------------------- | ---- | --------------------------- | +| videoOutput | [VideoOutput](#videooutput) | Yes | **VideoOutput** instance to remove.| + + **Return value** -| Type | Description | -| -------------- | ----------------------- | +| Type | Description | +| -------------- | --------------------------- | | Promise| Promise used to return the result.| + **Example** ```js -captureSession.stop().then(() => { - console.log('Promise returned to indicate the session stop success.'); +captureSession.removeOutput(videoOutput).then(() => { + console.log('Promise returned to indicate that the VideoOutput instance is removed.'); }) ``` -### lockForControl +### start -lockForControl(callback: AsyncCallback): void +start\(callback: AsyncCallback\): void -Requests to exclusively control the hardware attributes **[CameraInput](#camerainput)** of the camera device. This API uses an asynchronous callback to return the result. After the exclusive control is complete, you must call **[unlockForControl](#unlockforcontrol)** to release the exclusive control. +Starts this **CaptureSession** instance. This API uses an asynchronous callback to return the result. **System capability**: SystemCapability.Multimedia.Camera.Core **Parameters** -| Name | Type | Mandatory| Description | -| -------- | -------------------- | ---- | ------------------- | +| Name | Type | Mandatory| Description | +| -------- | -------------------- | ---- | ------------------------ | | callback | AsyncCallback | Yes | Callback used to return the result.| **Example** ```js -captureSession.lockForControl((err) => { +captureSession.start((err) => { if (err) { - console.error(`Failed to lock. ${err.message}`); + console.error('Failed to start the session ${err.message}'); return; } - console.log('Locked.'); -}) + console.log('Callback invoked to indicate the session start success.'); +}); ``` -### lockForControl +### start -lockForControl(): Promise +start\(\): Promise -Requests to exclusively control the hardware attributes **[CameraInput](#camerainput)** of the camera device. This API uses a promise to return the result. After the exclusive control is complete, you must call **[unlockForControl](#unlockforcontrol)** to release the exclusive control. +Starts this **CaptureSession** instance. This API uses a promise to return the result. **System capability**: SystemCapability.Multimedia.Camera.Core **Return value** -| Type | Description | -| -------------- | ------------------------ | +| Type | Description | +| -------------- | --------------------------- | | Promise| Promise used to return the result.| **Example** ```js -captureSession.lockForControl().then(() => { - console.log('Locked.'); +captureSession.start().then(() => { + console.log('Promise returned to indicate the session start success.'); }) ``` -### unlockForControl +### stop -unlockForControl(callback: AsyncCallback): void +stop\(callback: AsyncCallback\): void -Releases the exclusive control on the device configuration. This API uses an asynchronous callback to return the result. +Stops this **CaptureSession** instance. This API uses an asynchronous callback to return the result. **System capability**: SystemCapability.Multimedia.Camera.Core **Parameters** -| Name | Type | Mandatory| Description | -| -------- | -------------------- | ---- | -------------------- | + +| Name | Type | Mandatory| Description | +| -------- | -------------------- | ---- | ------------------------ | | callback | AsyncCallback | Yes | Callback used to return the result.| **Example** ```js -captureSession.unlockForControl((err) => { +captureSession.stop((err) => { if (err) { - console.error(`Failed to unlock. ${err.message}`); + console.error('Failed to stop the session ${err.message}'); return; } - console.log('Unlocked.'); -}) + console.log('Callback invoked to indicate the session stop success.'); +}); ``` -### unlockForControl +### stop -unlockForControl(): Promise +stop(): Promise -Releases the exclusive control on the device configuration. This API uses a promise to return the result. +Stops this **CaptureSession** instance. This API uses a promise to return the result. **System capability**: SystemCapability.Multimedia.Camera.Core **Return value** -| Type | Description | -| -------------- | ------------------------ | +| Type | Description | +| -------------- | --------------------------- | | Promise| Promise used to return the result.| **Example** ```js -captureSession.unlockForControl().then(() => { - console.log('Unlocked.'); +captureSession.stop().then(() => { + console.log('Promise returned to indicate the session stop success.'); }) ``` @@ -1979,14 +1807,14 @@ captureSession.unlockForControl().then(() => { release\(callback: AsyncCallback\): void -Releases this **CaptureSession**. This API uses an asynchronous callback to return the result. +Releases this **CaptureSession** instance. This API uses an asynchronous callback to return the result. **System capability**: SystemCapability.Multimedia.Camera.Core **Parameters** -| Name | Type | Mandatory| Description | -| -------- | -------------------- | ---- | -------------------- | +| Name | Type | Mandatory| Description | +| -------- | -------------------- | ---- | ------------------------ | | callback | AsyncCallback | Yes | Callback used to return the result.| **Example** @@ -1994,7 +1822,7 @@ Releases this **CaptureSession**. This API uses an asynchronous callback to retu ```js captureSession.release((err) => { if (err) { - console.error(`Failed to release the CaptureSession instance ${err.message}`); + console.error('Failed to release the CaptureSession instance ${err.message}'); return; } console.log('Callback invoked to indicate that the CaptureSession instance is released successfully.'); @@ -2005,14 +1833,14 @@ captureSession.release((err) => { release(): Promise -Releases this **CaptureSession**. This API uses a promise to return the result. +Releases this **CaptureSession** instance. This API uses a promise to return the result. **System capability**: SystemCapability.Multimedia.Camera.Core **Return value** -| Type | Description | -| -------------- | ------------------------ | +| Type | Description | +| -------------- | --------------------------- | | Promise| Promise used to return the result.| **Example** @@ -2023,2077 +1851,433 @@ captureSession.release().then(() => { }) ``` -### hasFlash +### on('error') -hasFlash(callback: AsyncCallback): void +on(type: 'error', callback: ErrorCallback): void -Checks whether the device has flash. This API uses an asynchronous callback to return the result. +Listens for **CaptureSession** errors. This API uses a callback to return the errors. **System capability**: SystemCapability.Multimedia.Camera.Core **Parameters** -| Name | Type | Mandatory| Description | -| -------- | ----------------------- | ---- | -------------------------------- | -| callback | AsyncCallback | Yes | Callback used to return the flash support status. The value **true** means that the device has flash.| +| Name | Type | Mandatory| Description | +| :------- | :---------------------------------------------------------- | :--- | :-------------------------------------------- | +| type | string | Yes | Event type. The value is fixed at **'error'**, indicating the capture session error event.| +| callback | ErrorCallback<[CaptureSessionError](#capturesessionerror)\> | Yes | Callback used to return the error information. | **Example** ```js -cameraInput.hasFlash((err, status) => { - if (err) { - console.error(`Failed to check whether the device has flash light. ${err.message}`); - return; - } - console.log(`Callback returned with flash light support status: ${status}`); +captureSession.on('error', (captureSessionError) => { + console.log('Capture session error code: ' + captureSessionError.code); }) ``` -### hasFlash - -hasFlash(): Promise +## CaptureSessionErrorCode -Checks whether the device has flash. This API uses a promise to return the result. +Enumerates the error codes used in a **CaptureSession** instance. **System capability**: SystemCapability.Multimedia.Camera.Core -**Return value** +| Name | Value | Description | +| ------------- | ---- | ---------- | +| ERROR_UNKNOWN | -1 | Unknown error.| -| Type | Description | -| ----------------- | ----------------------------------------------- | -| Promise | Promise used to return the flash support status. The value **true** means that the device has flash.| +## CaptureSessionError -**Example** +Defines a **CaptureSession** error. -```js -cameraInput.hasFlash().then((status) => { - console.log(`Promise returned with the flash light support status: ${status}`); -}) -``` +**System capability**: SystemCapability.Multimedia.Camera.Core -### isFlashModeSupported +| Name| Type | Description | +| ---- | ------------------------------------------- | -------------------------- | +| code | [CaptureSessionError](#capturesessionerror) | **CaptureSession** error code.| -isFlashModeSupported(flashMode: FlashMode, callback: AsyncCallback): void +## camera.createPreviewOutput -Checks whether a specified flash mode is supported. This API uses an asynchronous callback to return the result. +createPreviewOutput(surfaceId: string, callback: AsyncCallback): void + +Creates a **PreviewOutput** instance. This API uses an asynchronous callback to return the result. **System capability**: SystemCapability.Multimedia.Camera.Core **Parameters** -| Name | Type | Mandatory| Description | -| --------- | ----------------------- | ---- | --------------------------------- | -| flashMode | [FlashMode](#flashmode) | Yes | Flash mode. | -| callback | AsyncCallback | Yes | Callback used to return the flash mode support status. The value **true** means that the flash mode is supported, and **false** means the opposite.| +| Name | Type | Mandatory| Description | +| --------- | ----------------------------------------------- | ---- | ------------------------------------- | +| surfaceId | string | Yes | Surface ID, which is obtained from **XComponent**. | +| callback | AsyncCallback<[PreviewOutput](#previewoutput)\> | Yes | Callback used to return the **PreviewOutput** instance.| **Example** ```js -cameraInput.isFlashModeSupported(camera.FlashMode.FLASH_MODE_AUTO, (err, status) => { +camera.createPreviewOutput(("surfaceId"), (err, previewOutput) => { if (err) { - console.error(`Failed to check whether the flash mode is supported. ${err.message}`); + console.error('Failed to create the PreviewOutput instance. ${err.message}'); return; } - console.log(`Callback returned with the flash mode support status: ${status}`); -}) + console.log('Callback returned with previewOutput instance'); +}); ``` -### isFlashModeSupported +## camera.createPreviewOutput -isFlashModeSupported(flashMode: FlashMode): Promise +createPreviewOutput(surfaceId: string): Promise\ -Checks whether a specified flash mode is supported. This API uses a promise to return the result. +Creates a **PreviewOutput** instance. This API uses a promise to return the result. **System capability**: SystemCapability.Multimedia.Camera.Core **Parameters** -| Name | Type | Mandatory| Description | -| --------- | ----------------------- | ---- | ------------- | -| flashMode | [FlashMode](#flashmode) | Yes | Flash mode.| +| Name | Type | Mandatory| Description | +| --------- | ------ | ---- | ---------------------------------- | +| surfaceId | string | Yes | Surface ID, which is obtained from **XComponent**.| **Return value** -| Type | Description | -| ----------------- | ---------------------------------------------------- | -| Promise | Promise used to return the flash mode support status. The value **true** means that the flash mode is supported, and **false** means the opposite.| +| Type | Description | +| ----------------------------------------- | --------------------------- | +| Promise<[PreviewOutput](#previewoutput)\> | Promise used to return the result.| **Example** ```js -cameraInput.isFlashModeSupported(camera.FlashMode.FLASH_MODE_AUTO).then((status) => { - console.log(`Promise returned with flash mode support status.${status}`); +camera.createPreviewOutput("surfaceId").then((previewOutput) => { + console.log('Promise returned with the PreviewOutput instance'); }) ``` -### setFlashMode +## PreviewOutput -setFlashMode(flashMode: FlashMode, callback: AsyncCallback): void +Implements preview output. -Sets the flash mode. This API uses an asynchronous callback to return the result. +### release -Before the setting, do the following checks: +release(callback: AsyncCallback): void -1. Use **[hasFlash](#hasflash)** to check whether the device has flash. -2. Use **[isFlashModeSupported](#isflashmodesupported)** to check whether the device supports the flash mode. +Releases this **PreviewOutput** instance. This API uses an asynchronous callback to return the result. **System capability**: SystemCapability.Multimedia.Camera.Core **Parameters** -| Name | Type | Mandatory| Description | -| --------- | ----------------------- | ---- | --------------------- | -| flashMode | [FlashMode](#flashmode) | Yes | Flash mode. | -| callback | AsyncCallback | Yes | Callback used to return the result.| +| Name | Type | Mandatory| Description | +| -------- | -------------------- | ---- | ------------------------ | +| callback | AsyncCallback | Yes | Callback used to return the result.| **Example** ```js -cameraInput.setFlashMode(camera.FlashMode.FLASH_MODE_AUTO, (err) => { +previewOutput.release((err) => { if (err) { - console.error(`Failed to set the flash mode ${err.message}`); + console.error('Failed to release the PreviewOutput instance ${err.message}'); return; } - console.log('Callback returned with the successful execution of setFlashMode.'); -}) + console.log('Callback invoked to indicate that the PreviewOutput instance is released successfully.'); +}); ``` -### setFlashMode - -setFlashMode(flashMode: FlashMode): Promise - -Sets a flash mode. This API uses a promise to return the result. +### release -Before the setting, do the following checks: +release(): Promise -1. Use **[hasFlash](#hasflash)** to check whether the device has flash. -2. Use **[isFlashModeSupported](#isflashmodesupported)** to check whether the device supports the flash mode. +Releases this **PreviewOutput** instance. This API uses a promise to return the result. **System capability**: SystemCapability.Multimedia.Camera.Core -**Parameters** - -| Name | Type | Mandatory| Description | -| --------- | ----------------------- | ---- | ------------- | -| flashMode | [FlashMode](#flashmode) | Yes | Flash mode.| - **Return value** -| Type | Description | -| -------------- | ------------------------ | +| Type | Description | +| -------------- | --------------------------- | | Promise| Promise used to return the result.| + **Example** ```js -cameraInput.setFlashMode(camera.FlashMode.FLASH_MODE_AUTO).then(() => { - console.log('Promise returned with the successful execution of setFlashMode.'); +previewOutput.release().then(() => { + console.log('Promise returned to indicate that the PreviewOutput instance is released successfully.'); }) ``` -### getFlashMode +### on('frameStart') -getFlashMode(callback: AsyncCallback): void +on(type: 'frameStart', callback: AsyncCallback): void -Obtains the flash mode in use. This API uses an asynchronous callback to return the result. +Listens for preview frame start events. This API uses an asynchronous callback to return the result. **System capability**: SystemCapability.Multimedia.Camera.Core **Parameters** -| Name | Type | Mandatory| Description | -| -------- | --------------------------------------- | ---- | --------------------------------- | -| callback | AsyncCallback<[FlashMode](#flashmode)\> | Yes | Callback used to return the flash mode.| +| Name | Type | Mandatory| Description | +| :------- | :------------------- | :--- | :------------------------------------------- | +| type | string | Yes | Event type. The value is fixed at **'frameStart'**, indicating the preview frame start event.| +| callback | AsyncCallback | Yes | Callback used to return the result. | **Example** ```js -cameraInput.getFlashMode((err, flashMode) => { - if (err) { - console.error(`Failed to get the flash mode ${err.message}`); - return; - } - console.log(`Callback returned with current flash mode: ${flashMode}`); +previewOutput.on('frameStart', () => { + console.log('Preview frame started'); }) ``` -### getFlashMode +### on('frameEnd') -getFlashMode(): Promise +on(type: 'frameEnd', callback: AsyncCallback): void -Obtains the flash mode in use. This API uses a promise to return the result. +Listens for preview frame end events. This API uses an asynchronous callback to return the result. **System capability**: SystemCapability.Multimedia.Camera.Core -**Return value** +**Parameters** -| Type | Description | -| --------------------------------- | --------------------------------- | -| Promise<[FlashMode](#flashmode)\> | Promise used to return the flash mode.| +| Name | Type | Mandatory| Description | +| :------- | :------------------- | :--- | :----------------------------------------- | +| type | string | Yes | Event type. The value is fixed at **'frameEnd'**, indicating the preview frame end event.| +| callback | AsyncCallback | Yes | Callback used to return the result. | **Example** ```js -cameraInput.getFlashMode().then((flashMode) => { - console.log(`Promise returned with current flash mode : ${flashMode}`); +previewOutput.on('frameEnd', () => { + console.log('Preview frame ended'); }) ``` -### isExposureModeSupported +### on('error') -isExposureModeSupported(aeMode: ExposureMode, callback: AsyncCallback): void; +on(type: 'error', callback: ErrorCallback): void -Checks whether a specified exposure mode is supported. This API uses an asynchronous callback to return the result. +Listens for **PreviewOutput** errors. This API uses a callback to return the errors. **System capability**: SystemCapability.Multimedia.Camera.Core **Parameters** -| Name | Type | Mandatory | Description | -| -------- | -------------------------------| ---- | ----------------------------- | -| aeMode | [ExposureMode](#exposuremode) | Yes | Exposure mode. | -| callback | AsyncCallback | Yes | Callback used to return the exposure mode support status. The value **true** means that the exposure mode is supported, and **false** means the opposite.| +| Name | Type | Mandatory| Description | +| :------- | :----------------------------------------------------------- | :--- | :-------------------------------------------- | +| type | string | Yes | Event type. The value is fixed at **'error'**, indicating the preview output error event.| +| callback | ErrorCallback<[PreviewOutputErrorCode](#previewoutputerrorcode)\> | Yes | Callback used to return the error information. | **Example** ```js -cameraInput.isExposureModeSupported(camera.ExposureMode.EXPOSURE_MODE_LOCKEN,(err) => { - if (err) { - console.log(`Failed to check exposure mode supported ${err.message}`); - return ; - } - console.log('Callback returned with the successful execution of isExposureModeSupported'); +previewOutput.on('error', (previewOutputError) => { + console.log('Preview output error code: ' + previewOutputError.code); }) ``` -### isExposureModeSupported - -isExposureModeSupported(aeMode: ExposureMode): Promise +## PreviewOutputErrorCode -Checks whether a specified exposure mode is supported. This API uses a promise to return the result. +Enumerates the error codes used in a **PreviewOutput** instance. **System capability**: SystemCapability.Multimedia.Camera.Core -**Parameters** - -| Name | Type | Mandatory | Description | -| -------- | -------------------------------| ---- | ----------------------------- | -| aeMode | [ExposureMode](#exposuremode) | Yes | Exposure mode. | +| Name | Value | Description | +| ------------- | ---- | ---------- | +| ERROR_UNKNOWN | -1 | Unknown error.| -**Return value** +## PreviewOutputError -| Name | Description | -| ----------------- |--------------------------------- | -| Promise | Promise used to return the exposure mode support status. The value **true** means that the exposure mode is supported, and **false** means the opposite.| +Defines a **PreviewOutput** error. -**Example** +**System capability**: SystemCapability.Multimedia.Camera.Core -```js -cameraInput.isExposureModeSupported(camera.ExposureMode.EXPOSURE_MODE_LOCKED).then((isSupported) => { - console.log(`Promise returned with exposure mode supported : ${isSupported}`); -}) -``` +| Name| Type | Description | +| ---- | ------------------------------------------------- | ---------------------- | +| code | [PreviewOutputErrorCode](#previewoutputerrorcode) | **PreviewOutput** error code.| -### getExposureMode +## camera.createPhotoOutput -getExposureMode(callback: AsyncCallback): void +createPhotoOutput(surfaceId: string, callback: AsyncCallback): void -Obtains the exposure mode in use. This API uses an asynchronous callback to return the result. +Creates a **PhotoOutput** instance. This API uses an asynchronous callback to return the result. **System capability**: SystemCapability.Multimedia.Camera.Core **Parameters** -| Name | Type | Mandatory| Description | -| -------- | -------------------------------| ---- | ---------------------------------------- | -| callback | AsyncCallback<[ExposureMode](#exposuremode)\> | Yes | Callback used to return the exposure mode.| +| Name | Type | Mandatory| Description | +| --------- | ------------------------------------------- | ---- | ----------------------------------- | +| surfaceId | string | Yes | Surface ID, which is obtained from **[ImageReceiver](js-apis-image.md#imagereceiver9)**. | +| callback | AsyncCallback<[PhotoOutput](#photooutput)\> | Yes | Callback used to return the **PhotoOutput** instance.| **Example** ```js -cameraInput.getExposureMode((err, exposureMode) => { +camera.createPhotoOutput(("surfaceId"), (err, photoOutput) => { if (err) { - console.log(`Failed to get the exposure mode ${err.message}`); - return ; + console.error('Failed to create the PhotoOutput instance. ${err.message}'); + return; } - console.log(`Callback returned with current exposure mode: ${exposureMode}`); -}) + console.log('Callback returned with the PhotoOutput instance.'); +}); ``` -### getExposureMode +## camera.createPhotoOutput -getExposureMode(): Promise +createPhotoOutput(surfaceId: string): Promise -Obtains the exposure mode in use. This API uses a promise to return the result. +Creates a **PhotoOutput** instance. This API uses a promise to return the result. **System capability**: SystemCapability.Multimedia.Camera.Core +**Parameters** + +| Name | Type | Mandatory| Description | +| --------- | ------ | ---- | --------------------------------- | +| surfaceId | string | Yes | Surface ID, which is obtained from **[ImageReceiver](js-apis-image.md#imagereceiver9)**.| + **Return value** -| Name | Description | -| --------------------------------------- |------------------------------- | -| Promise<[ExposureMode](#exposuremode)\> | Promise used to return the exposure mode.| +| Type | Description | +| ------------------------------------- | -------------------------------------- | +| Promise<[PhotoOutput](#photooutput)\> | Promise used to return the **PhotoOutput** instance.| **Example** ```js -cameraInput.getExposureMode().then((exposureMode) => { - console.log(`Promise returned with current exposure mode : ${exposureMode}`); +camera.createPhotoOutput("surfaceId").then((photoOutput) => { + console.log('Promise returned with PhotoOutput instance'); }) ``` +## ImageRotation -### setExposureMode - -setExposureMode(aeMode: ExposureMode, callback: AsyncCallback): void - -Sets an exposure mode. This API uses an asynchronous callback to return the result. - -**System capability**: SystemCapability.Multimedia.Camera.Core +Enumerates the image rotation angles. -**Parameters** - -| Name | Type | Mandatory| Description | -| -------- | -------------------------------| ---- | ----------------------- | -| aeMode | [ExposureMode](#exposuremode) | Yes | Exposure mode. | -| callback | AsyncCallback | Yes | Callback used to return the result.| - -**Example** - -```js -cameraInput.setExposureMode(camera.ExposureMode.EXPOSURE_MODE_LOCKEN,(err) => { - if (err) { - console.log(`Failed to set the exposure mode ${err.message}`); - return ; - } - console.log('Callback returned with the successful execution of setExposureMode'); -}) -``` - -### setExposureMode - -setExposureMode(aeMode: ExposureMode): Promise - -Sets an exposure mode. This API uses a promise to return the result. - -**System capability**: SystemCapability.Multimedia.Camera.Core - -**Return value** - -| Name | Description | -| ----------------- |---------------------------- | -| Promise | Promise used to return the result.| - -**Example** - -```js -cameraInput.setExposureMode(camera.ExposureMode.EXPOSURE_MODE_LOCKED).then(() => { - console.log('Promise returned with the successful execution of setExposureMode.'); -}) -``` - -### getMeteringPoint - -getMeteringPoint(callback: AsyncCallback): void - -Obtains the center of the metering area. This API uses an asynchronous callback to return the result. - -**System capability**: SystemCapability.Multimedia.Camera.Core - -**Parameters** - -| Name | Type | Mandatory| Description | -| -------- | -------------------------------| ---- | ------------------------ | -| callback | AsyncCallback<[Point](#point)\>| Yes | Callback used to return the center of the metering area.| - -**Example** - -```js -cameraInput.getMeteringPoint((err, exposurePoint) => { - if (err) { - console.log(`Failed to get the current exposure point ${err.message}`); - return ; - } - console.log(`Callback returned with current exposure point: ${exposurePoint}`); -}) -``` - -### getMeteringPoint - -getMeteringPoint(): Promise - -Obtains the center of the metering area. This API uses a promise to return the result. - -**System capability**: SystemCapability.Multimedia.Camera.Core - -**Return value** - -| Name | Description | -| ------------------------- |----------------------------- | -| Promise<[Point](#point)\> | Promise used to return the center of the metering area.| - -**Example** - -```js -cameraInput.getMeteringPoint().then((exposurePoint) => { - console.log(`Promise returned with current exposure point : ${exposurePoint}`); -}) -``` - -### setMeteringPoint - -setMeteringPoint(point: Point, callback: AsyncCallback): void - -Sets the center of the metering area. This API uses an asynchronous callback to return the result. - -**System capability**: SystemCapability.Multimedia.Camera.Core - -**Parameters** - -| Name | Type | Mandatory| Description | -| ------------- | -------------------------------| ---- | ------------------- | -| exposurePoint | [Point](#point) | Yes | Exposure point. | -| callback | AsyncCallback | Yes | Callback used to return the result.| - -**Example** - -```js -const Point1 = {x: 1, y: 1}; - -cameraInput.setMeteringPoint(Point1,(err) => { - if (err) { - console.log(`Failed to set the exposure point ${err.message}`); - return ; - } - console.log('Callback returned with the successful execution of setMeteringPoint'); -}) -``` - -### setMeteringPoint - -setMeteringPoint(point: Point): Promise - -Sets the center of the metering area. This API uses a promise to return the result. - -**System capability**: SystemCapability.Multimedia.Camera.Core - -**Parameters** - -| Name | Type | Mandatory| Description | -| ------------- | -------------------------------| ---- | ------------------- | -| exposurePoint | [Point](#point) | Yes | Exposure point. | - -**Return value** - -| Name | Description | -| ----------------- |------------------------ | -| Promise | Promise used to return the center of the metering area.| - -**Example** - -```js -const Point2 = {x: 2, y: 2}; - -cameraInput.setMeteringPoint(Point2).then(() => { - console.log('Promise returned with the successful execution of setMeteringPoint'); -}) -``` - -### getExposureBiasRange - -getExposureBiasRange(callback: AsyncCallback\>): void - -Obtains the exposure compensation values. This API uses an asynchronous callback to return the result. - -**System capability**: SystemCapability.Multimedia.Camera.Core - -**Parameters** - -| Name | Type | Mandatory| Description | -| -------- | -------------------------------| ---- | ----------------------------- | -| callback | AsyncCallback\> | Yes | Callback used to return the array of compensation values.| - -**Example** - -```js -cameraInput.getExposureBiasRange((err, biasRangeArray) => { - if (err) { - console.log(`Failed to get the array of compenstation range ${err.message}`); - return ; - } - console.log('Callback returned with the array of compenstation range: ' + JSON.stringify(biasRangeArray)); -}) -``` - -### getExposureBiasRange - -getExposureBiasRange(): Promise\> - -Obtains the exposure compensation values. This API uses a promise to return the result. - -**System capability**: SystemCapability.Multimedia.Camera.Core - -**Return value** - -| Name | Description | -| ----------------- |-------------------------------------- | -| Promise\> | Promise used to return the array of compensation values.| - -**Example** - -```js -cameraInput.isExposureModeSupported(camera.ExposureMode.EXPOSURE_MODE_LOCKED).then((isSupported) => { - console.log(`Promise returned with exposure mode supported : ${isSupported}`); -}) -``` - -### setExposureBias - -setExposureBias(exposureBias: number, callback: AsyncCallback): void - -Sets an exposure compensation value. This API uses an asynchronous callback to return the result. - -Before the setting, you are advised to use **[getExposureBiasRange](#getexposurebiasrange)** to obtain the supported values. - -**System capability**: SystemCapability.Multimedia.Camera.Core - -**Parameters** - -| Name | Type | Mandatory| Description | -| -------- | -------------------------------| ---- | ------------------- | -| exposureBias | number | Yes | Compensation value. | -| callback | AsyncCallback | Yes | Callback used to return the result.| - -**Example** - -```js -cameraInput.setExposureBias(-4,(err) => { - if (err) { - console.log(`Failed to set the exposure bias ${err.message}`); - return ; - } - console.log('Callback returned with the successful execution of setExposureBias'); -}) -``` - -### setExposureBias - -setExposureBias(exposureBias: number): Promise - -Sets an exposure compensation value. This API uses a promise to return the result. - -Before the setting, you are advised to use **[getExposureBiasRange](#getexposurebiasrange)** to obtain the supported values. - -**System capability**: SystemCapability.Multimedia.Camera.Core - -**Parameters** - -| Name | Type | Mandatory| Description | -| -------------- | --------- | ---- | --------- | -| exposureBias | number | Yes | Compensation value. | - -**Return value** - -| Name | Description | -| ----------------- |------------------------- | -| Promise | Promise used to return the result.| - -**Example** - -```js -cameraInput.setExposureBias(-4).then(() => { - console.log('Promise returned with the successful execution of setExposureBias.'); -}) -``` - -### getExposureValue - -getExposureValue(callback: AsyncCallback): void - -Obtains the exposure value in use. This API uses an asynchronous callback to return the result. - -**System capability**: SystemCapability.Multimedia.Camera.Core - -**Parameters** - -| Name | Type | Mandatory| Description | -| -------- | ------------------------| ---- | --------------------- | -| callback | AsyncCallback | Yes | Callback used to the exposure value.| - -**Example** - -```js -cameraInput.getExposureValue((err, exposureValue) => { - if (err) { - console.log(`Failed to get the exposure value ${err.message}`); - return ; - } - console.log(`Callback returned with the exposure value: ${exposureValue}`); -}) -``` - -### getExposureValue - -getExposureValue(): Promise - -Obtains the exposure value in use. This API uses a promise to return the result. - -**System capability**: SystemCapability.Multimedia.Camera.Core - -**Return value** - -| Name | Description | -| ----------------- |-------------------------- | -| Promise | Promise used to the exposure value.| - -**Example** - -```js -cameraInput.getExposureValue().then((exposureValue) => { - console.log(`Promise returned with exposure value: ${exposureValude}`); -}) -``` - -### isFocusModeSupported - -isFocusModeSupported(afMode: FocusMode, callback: AsyncCallback): void - -Checks whether a specified focus mode is supported. This API uses an asynchronous callback to return the result. - -**System capability**: SystemCapability.Multimedia.Camera.Core - -**Parameters** - -| Name | Type | Mandatory| Description | -| -------- | ----------------------- | ---- | -------------------------------- | -| afMode | [FocusMode](#focusmode) | Yes | Focus mode. | -| callback | AsyncCallback | Yes | Callback used to return the focus mode support status. The value **true** means that the focus mode is supported, and **false** means the opposite.| - -**Example** - -```js -cameraInput.isFocusModeSupported(camera.FocusMode.FOCUS_MODE_AUTO, (err, status) => { - if (err) { - console.error(`Failed to check whether the focus mode is supported. ${err.message}`); - return; - } - console.log(`Callback returned with the focus mode support status: ${status}`); -}) -``` - -### isFocusModeSupported - -isFocusModeSupported(afMode: FocusMode): Promise - -Checks whether a specified focus mode is supported. This API uses a promise to return the result. - -**System capability**: SystemCapability.Multimedia.Camera.Core - -**Parameters** - -| Name | Type | Mandatory| Description | -| ------ | ----------------------- | ---- | ------------- | -| afMode | [FocusMode](#focusmode) | Yes | Focus mode.| - -**Return value** - -| Type | Description | -| ----------------- | --------------------------------------------------- | -| Promise | Promise used to return the focus mode support status. The value **true** means that the focus mode is supported, and **false** means the opposite.| - -**Example** - -```js -cameraInput.isFocusModeSupported(camera.FocusMode.FOCUS_MODE_AUTO).then((status) => { - console.log(`Promise returned with focus mode support status ${status}.`); -}) -``` - -### setFocusMode - -setFocusMode(afMode: FocusMode, callback: AsyncCallback): void - -Sets a focus mode. This API uses an asynchronous callback to return the result. - -Before the setting, use **[isFocusModeSupported](#isfocusmodesupported)** to check whether the focus mode is supported. - -**System capability**: SystemCapability.Multimedia.Camera.Core - -**Parameters** - -| Name | Type | Mandatory| Description | -| -------- | ----------------------- | ---- | ------------------- | -| afMode | [FocusMode](#focusmode) | Yes | Focus mode. | -| callback | AsyncCallback | Yes | Callback used to return the result.| - -**Example** - -```js -cameraInput.setFocusMode(camera.FocusMode.FOCUS_MODE_AUTO, (err) => { - if (err) { - console.error(`Failed to set the focus mode ${err.message}`); - return; - } - console.log('Callback returned with the successful execution of setFocusMode.'); -}) -``` - -### setFocusMode - -setFocusMode(afMode: FocusMode): Promise - -Sets a focus mode. This API uses a promise to return the result. - -Before the setting, use **[isFocusModeSupported](#isfocusmodesupported)** to check whether the focus mode is supported. - -**System capability**: SystemCapability.Multimedia.Camera.Core - -**Parameters** - -| Name | Type | Mandatory| Description | -| ------ | ----------------------- | ---- | ------------- | -| afMode | [FocusMode](#focusmode) | Yes | Focus mode.| - -**Return value** - -| Type | Description | -| -------------- | ------------------------ | -| Promise| Promise used to return the result.| - -**Example** - -```js -cameraInput.setFocusMode(camera.FocusMode.FOCUS_MODE_AUTO).then(() => { - console.log('Promise returned with the successful execution of setFocusMode.'); -}) -``` - -### getFocusMode - -getFocusMode(callback: AsyncCallback): void - -Obtains the focus mode in use. This API uses an asynchronous callback to return the result. - -**System capability**: SystemCapability.Multimedia.Camera.Core - -**Parameters** - -| Name | Type | Mandatory| Description | -| -------- | --------------------------------------- | ---- | ------------------------------- | -| callback | AsyncCallback<[FocusMode](#focusmode)\> | Yes | Callback used to return the focus mode.| - -**Example** - -```js -cameraInput.getFocusMode((err, afMode) => { - if (err) { - console.error(`Failed to get the focus mode ${err.message}`); - return; - } - console.log(`Callback returned with current focus mode: ${afMode}`); -}) -``` - -### getFocusMode - -getFocusMode(): Promise - -Obtains the focus mode in use. This API uses a promise to return the result. - -**System capability**: SystemCapability.Multimedia.Camera.Core - -**Return value** - -| Type | Description | -| ------------------- | -------------------------------- | -| Promise | Promise used to return the focus mode.| - -**Example** - -```js -cameraInput.getFocusMode().then((afMode) => { - console.log(`Promise returned with current focus mode : ${afMode}`); -}) -``` - -### setFocusPoint - -setFocusPoint(point: Point, callback: AsyncCallback): void - -Sets a focus point. This API uses an asynchronous callback to return the result. - -**System capability**: SystemCapability.Multimedia.Camera.Core - -**Parameters** - -| Name | Type | Mandatory| Description | -| -------- | ----------------------- | ---- | ------------------- | -| point | [Point](#point) | Yes | Focus point. | -| callback | AsyncCallback | Yes | Callback used to return the result.| - -**Example** - -```js -const Point1 = {x: 1, y: 1}; - -cameraInput.setFocusPoint(Point1, (err) => { - if (err) { - console.error(`Failed to set the focus point ${err.message}`); - return; - } - console.log('Callback returned with the successful execution of setFocusPoint.'); -}) -``` - -### setFocusPoint - -setFocusPoint(point: Point): Promise - -Sets a focal point. This API uses a promise to return the result. - -**System capability**: SystemCapability.Multimedia.Camera.Core - -**Parameters** - -| Name | Type | Mandatory| Description | -| -------- | ----------------------- | ---- | ------------------- | -| point | [Point](#point) | Yes | Focal point. | - -**Return value** - -| Type | Description | -| -------------- | ----------------------- | -| Promise| Promise used to return the result.| - -**Example** - -```js -const Point2 = {x: 2, y: 2}; - -cameraInput.setFocusPoint(Point2).then(() => { - console.log('Promise returned with the successful execution of setFocusPoint.'); -}) -``` - -### getFocusPoint - -getFocusPoint(callback: AsyncCallback): void - -Obtains the focal point. This API uses an asynchronous callback to return the result. - -**System capability**: SystemCapability.Multimedia.Camera.Core - -**Parameters** - -| Name | Type | Mandatory| Description | -| -------- | ---------------------------------- | ---- | ----------------------- | -| callback | AsyncCallback<[Point](#point)\> | Yes | Callback used to return the focal point.| - -**Example** - -```js -cameraInput.getFocusPoint((err, point) => { - if (err) { - console.error(`Failed to get the current focus point ${err.message}`); - return; - } - console.log('Callback returned with the current focus point: ' + JSON.stringify(point)); -}) -``` - -### getFocusPoint - -getFocusPoint(): Promise - -Obtains the focal point. This API uses a promise to return the result. - -**System capability**: SystemCapability.Multimedia.Camera.Core - -**Return value** - -| Type | Description | -| --------------- | --------------------------- | -| Promise | Promise used to return the focal point.| - -**Example** - -```js -cameraInput.getFocusPoint().then((point) => { - console.log('Promise returned with the current focus point: ' + JSON.stringify(point)); -}) -``` - -### getFocalLength - -getFocalLength(callback: AsyncCallback): void - -Obtains the focal length. This API uses an asynchronous callback to return the result. - -**System capability**: SystemCapability.Multimedia.Camera.Core - -**Parameters** - -| Name | Type | Mandatory| Description | -| -------- | ------------------------- | ---- | ----------------------- | -| callback | AsyncCallback | Yes | Callback used to return the focal length.| - -**Example** - -```js -cameraInput.getFocalLength((err, focalLength) => { - if (err) { - console.error(`Failed to get the current focal length ${err.message}`); - return; - } - console.log(`Callback returned with the current focal length: ${focalLength}`); -}) -``` - -### getFocalLength - -getFocalLength(): Promise - -Obtains the focal length. This API uses a promise to return the result. - -**System capability**: SystemCapability.Multimedia.Camera.Core - -**Return value** - -| Type | Description | -| ---------------- | ----------------------- | -| Promise | Promise used to return the focal length.| - -**Example** - -```js -cameraInput.getFocalLength().then((focalLength) => { - console.log(`Promise returned with the current focal length: ${focalLength}`); -}) -``` - -### getZoomRatioRange - -getZoomRatioRange\(callback: AsyncCallback\>\): void - -Obtains the zoom ratio range. This API uses an asynchronous callback to return the result. - -**System capability**: SystemCapability.Multimedia.Camera.Core - -**Parameters** - -| Name | Type | Mandatory| Description | -| -------- | ------------------------------ | ---- | ------------------- | -| callback | AsyncCallback\> | Yes | Callback used to return the result.| - -**Example** - -```js -cameraInput.getZoomRatioRange((err, zoomRatioRange) => { - if (err) { - console.error(`Failed to get the zoom ratio range. ${err.message}`); - return; - } - console.log(`Callback returned with zoom ratio range: ${zoomRatioRange.length}`); -}) -``` - -### getZoomRatioRange - -getZoomRatioRange\(\): Promise\> - -Obtains the zoom ratio range. This API uses a promise to return the result. - -**System capability**: SystemCapability.Multimedia.Camera.Core - -**Return value** - -| Type | Description | -| ------------------------ | --------------------------- | -| Promise\> | Promise used to return the zoom ratio range.| - -**Example** - -```js -cameraInput.getZoomRatioRange().then((zoomRatioRange) => { - console.log(`Promise returned with zoom ratio range: ${zoomRatioRange.length}`); -}) -``` - -### setZoomRatio - -setZoomRatio(zoomRatio: number, callback: AsyncCallback): void - -Sets a zoom ratio. This API uses an asynchronous callback to return the result. - -**System capability**: SystemCapability.Multimedia.Camera.Core - -**Parameters** - -| Name | Type | Mandatory| Description | -| --------- | -------------------- | ---- | ------------------- | -| zoomRatio | number | Yes | Zoom ratio. | -| callback | AsyncCallback | Yes | Callback used to return the result.| - -**Example** - -```js -cameraInput.setZoomRatio(1, (err) => { - if (err) { - console.error(`Failed to set the zoom ratio value ${err.message}`); - return; - } - console.log('Callback returned with the successful execution of setZoomRatio.'); -}) -``` - -### setZoomRatio - -setZoomRatio(zoomRatio: number): Promise - -Sets a zoom ratio. This API uses a promise to return the result. - -**System capability**: SystemCapability.Multimedia.Camera.Core - -**Parameters** - -| Name | Type | Mandatory| Description | -| --------- | ------ | ---- | --------- | -| zoomRatio | number | Yes | Zoom ratio.| - -**Return value** - -| Type | Description | -| -------------- | ----------------------- | -| Promise| Promise used to return the result.| - -**Example** - -```js -cameraInput.setZoomRatio(1).then(() => { - console.log('Promise returned with the successful execution of setZoomRatio.'); -}) -``` - -### getZoomRatio - -getZoomRatio(callback: AsyncCallback): void - -Obtains the zoom ratio in use. This API uses an asynchronous callback to return the result. - -**System capability**: SystemCapability.Multimedia.Camera.Core - -**Parameters** - -| Name | Type | Mandatory| Description | -| -------- | ---------------------- | ---- | ------------------- | -| callback | AsyncCallback | Yes | Callback used to return the result.| - -**Example** - -```js -cameraInput.getZoomRatio((err, zoomRatio) => { - if (err) { - console.error(`Failed to get the zoom ratio ${err.message}`); - return; - } - console.log(`Callback returned with current zoom ratio: ${zoomRatio}`); -}) -``` - -### getZoomRatio - -getZoomRatio(): Promise - -Obtains the zoom ratio in use. This API uses a promise to return the result. - -**System capability**: SystemCapability.Multimedia.Camera.Core - -**Return value** - -| Type | Description | -| ---------------- | ----------------------- | -| Promise | Promise used to return the zoom ratio.| - -**Example** - -```js -cameraInput.getZoomRatio().then((zoomRatio) => { - console.log(`Promise returned with current zoom ratio : ${zoomRatio}`); -}) -``` - -### isVideoStablizationModeSupported - -isVideoStablizationModeSupported(vsMode: VideoStabilizationMode, callback: AsyncCallback): void - -Checks whether the specified video stabilization mode is supported. This API uses an asynchronous callback to return the result. - -**System capability**: SystemCapability.Multimedia.Camera.Core - -**Parameters** - -| Name | Type | Mandatory| Description | -| -------- | ------------------------------------------------- | ---- | ------------------------------ | -| vsMode | [VideoStabilizationMode](#videostabilizationmode) | Yes | Video stabilization mode. | -| callback | AsyncCallback | Yes | Callback used to return whether the video stabilization mode is supported. The value **true** means that the video stabilization mode is supported, and **false** means the opposite. | - -**Example** - -```js -captureSession.isVideoStablizationModeSupported(camera.VideoStabilizationMode.OFF, (err, isSupported) => { - if (err) { - console.error(`Failed to check whether video stabilization mode supported. ${err.message}`); - return; - } - console.log(`Callback returned with the successful execution of isVideoStabilizationModeSupported: ${status}`); -}) -``` - -### isVideoStablizationModeSupported - -isVideoStablizationModeSupported(vsMode: VideoStabilizationMode): Promise - -Checks whether the specified video stabilization mode is supported. This API uses a promise to return the result. - -**System capability**: SystemCapability.Multimedia.Camera.Core - -**Return value** - -| Type | Description | -| ----------------- | --------------------------------------------- | -| Promise | Promise used to return whether the video stabilization mode is supported. The value **true** means that the video stabilization mode is supported, and **false** means the opposite.| - -**Example** - -```js -captureSession.isVideoStablizationModeSupported(camera.VideoStabilizationMode.OFF).then((isSupported) => { - console.log(`Promise returned with video stabilization mode supported: ${isSupported}`); -}) -``` - -### getActiveVideoStabilizationMode - -getActiveVideoStabilizationMode(callback: AsyncCallback): void - -Obtains the video stabilization mode in use. This API uses an asynchronous callback to return the result. - -**System capability**: SystemCapability.Multimedia.Camera.Core - -**Parameters** - -| Name | Type | Mandatory| Description | -| -------- | ----------------------------------------- | ---- | ------------------------------ | -| callback | AsyncCallback | Yes | Callback used to return the video stabilization mode. | - -**Example** - -```js -captureSession.getActiveVideoStabilizationMode((err, vsMode) => { - if (err) { - console.error(`Failed to get active video stabilization mode ${err.message}`); - return; - } - console.log('Callback returned with the successful execution of getActiveVideoStabilizationMode.'); -}) -``` - -### getActiveVideoStabilizationMode - -getActiveVideoStabilizationMode(): Promise - -Obtains the video stabilization mode in use. This API uses a promise to return the result. - -**System capability**: SystemCapability.Multimedia.Camera.Core - -**Return value** - -| Type | Description | -| -------------------------------- | ------------------------------------------------- | -| Promise | Promise used to return the video stabilization mode. | - -**Example** - -```js -captureSession.getActiveVideoStabilizationMode().then((vsMode) => { - console.log(`Promise returned with the current video stabilization mode: ${vsMode}`); -}) -``` - -### setVideoStabilizationMode - -setVideoStabilizationMode(mode: VideoStabilizationMode, callback: AsyncCallback): void - -Sets a video stabilization mode. This API uses an asynchronous callback to return the result. - -**System capability**: SystemCapability.Multimedia.Camera.Core - -**Parameters** - -| Name | Type | Mandatory| Description | -| -------- | ------------------------------------------------- | ---- | --------------------- | -| mode | [VideoStabilizationMode](#videostabilizationmode) | Yes | Video stabilization mode. | -| callback | AsyncCallback | Yes | Callback used to return the result. | - -**Example** - -```js -captureSession.setVideoStabilizationMode(camera.VideoStabilizationMode.OFF, (err) => { - if (err) { - console.error(`Failed to set the video stabilization mode ${err.message}`); - return; - } - console.log('Callback returned with the successful execution of setVideoStabilizationMode.'); -}) -``` - -### setVideoStabilizationMode - -setVideoStabilizationMode(mode: VideoStabilizationMode): Promise - -Sets a video stabilization mode. This API uses a promise to return the result. - -**System capability**: SystemCapability.Multimedia.Camera.Core - -**Parameters** - -| Name | Type | Mandatory| Description | -| -------- | ------------------------------------------------- | ---- | --------------------- | -| mode | [VideoStabilizationMode](#videostabilizationmode) | Yes | Video stabilization mode. | - -**Return value** - -| Type | Description | -| -------------- | ------------------------------------------------- | -| Promise| Promise used to return the result. | - -**Example** - -```js -captureSession.setVideoStabilizationMode(camera.VideoStabilizationMode.OFF).then(() => { - console.log('Promise returned with the successful execution of setVideoStabilizationMode.'); -}) -``` - -### on('focusStateChange') - -on(type: 'focusStateChange', callback: AsyncCallback): void - -Listens for focus state changes. This API uses an asynchronous callback to return the result. - -**System capability**: SystemCapability.Multimedia.Camera.Core - -**Parameters** - -| Name | Type | Mandatory| Description | -| -------- | ----------------------------------------- | ---- | ------------------------ | -| type | string | Yes | Event type. The value is fixed at **'focusStateChange'**, indicating the focus state change event.| -| callback | AsyncCallback<[FocusState](#focusstate)\> | Yes | Callback used to return the focus state change. | - -**Example** - -```js -cameraInput.on('focusStateChange', (focusState) => { - console.log(`Focus state : ${focusState}`); -}) -``` - -### on('exposureStateChange') - -on(type: 'exposureStateChange', callback: AsyncCallback): void - -Listens for exposure state changes. This API uses an asynchronous callback to return the result. - -**System capability**: SystemCapability.Multimedia.Camera.Core - -**Parameters** - -| Name | Type | Mandatory| Description | -| -------- | ----------------------------------------- | ---- | ---------------------------------------------- | -| type | string | Yes | Event type. The value is fixed at **'exposureStateChange'**, indicating the exposure state change event.| -| callback | AsyncCallback<[ExposureState](#exposurestate)\> | Yes | Callback used to return the exposure state change. | - -**Example** - -```js -cameraInput.on('exposureStateChange', (exposureState) => { - console.log(`Exposuer state : ${exposureState}`); -}) -``` - -### on('error') - -on(type: 'error', callback: ErrorCallback): void - -Listens for **CaptureSession** errors. This API uses a callback to return the errors. - -**System capability**: SystemCapability.Multimedia.Camera.Core - -**Parameters** - -| Name | Type | Mandatory| Description | -| -------- | ----------------------------------------------------------- | ---- | ------------------------------ | -| type | string | Yes | Event type. The value is fixed at **'error'**, indicating the capture session error event.| -| callback | ErrorCallback<[CaptureSessionError](#capturesessionerror)\> | Yes | Callback used to return the error information. | - -**Example** - -```js -captureSession.on('error', (captureSessionError) => { - console.log(`Capture session error code: ${captureSessionError.code}`); -}) -``` - -## CaptureSessionErrorCode - -Enumerates the error codes used in a **CaptureSession**. - -**System capability**: SystemCapability.Multimedia.Camera.Core - -| Name | Value | Description | -| ----------------------------- | ---- | -------- | -| ERROR_UNKNOWN | -1 | Unknown error.| -| ERROR_INSUFFICIENT_RESOURCES | 0 | Insufficient resources.| -| ERROR_TIMEOUT | 1 | Timeout.| - -## CaptureSessionError - -Defines a **CaptureSession** error. - -**System capability**: SystemCapability.Multimedia.Camera.Core - -| Name| Type | Description | -| ---- | ------------------------------------------- | -------------------------- | -| code | [CaptureSessionError](#capturesessionerror) | **CaptureSession** error code.| - -## CameraOutput - -Implements output information used in a **[CaptureSession](#capturesession)**. It is the base class of **output**. - -### release - -release(callback: AsyncCallback): void - -Releases output resources. This API uses an asynchronous callback to return the result. - -**System capability**: SystemCapability.Multimedia.Camera.Core - -**Parameters** - -| Name | Type | Mandatory| Description | -| -------- | -------------------- | ---- | ------------------- | -| callback | AsyncCallback | Yes | Callback used to return the result.| - -**Example** - -```js -previewOutput.release((err) => { - if (err) { - console.error(`Failed to release the PreviewOutput instance ${err.message}`); - return; - } - console.log('Callback invoked to indicate that the PreviewOutput instance is released successfully.'); -}); -``` - -### release - -release(): Promise - -Releases output resources. This API uses a promise to return the result. - -**System capability**: SystemCapability.Multimedia.Camera.Core - -**Return value** - -| Type | Description | -| -------------- | ----------------------- | -| Promise| Promise used to return the result.| - -**Example** - -```js -previewOutput.release().then(() => { - console.log('Promise returned to indicate that the PreviewOutput instance is released successfully.'); -}) -``` - -## PreviewOutput - -Implements preview output. It inherits **[CameraOutput](#cameraoutput)**. - -### addDeferredSurface - -addDeferredSurface(surfaceId: string, callback: AsyncCallback): void - -Adds a surface after a **PreviewOutput** instance is created. This API uses an asynchronous callback to return the result. - -**System capability**: SystemCapability.Multimedia.Camera.Core - -**Parameters** - -| Name | Type | Mandatory| Description | -| -------- | -------------------- | ---- | -------------------------------------------------------------------- | -| surfaceId| string | Yes | Surface ID, which is obtained from **[XComponent](../arkui-ts/ts-basic-components-xcomponent.md)**.| -| callback | AsyncCallback | Yes | Callback used to return the result. | - -**Example** - -```js -previewOutput.addDeferredSurface('surfaceId', (err) => { - if (err) { - console.error(`Failed to add deferredSurface. ${err.message}`); - return; - } - console.log('Callback returned with deferredSurface added.'); -}) -``` - -### addDeferredSurface - -addDeferredSurface(surfaceId: string): Promise - -Adds a surface after a **PreviewOutput** instance is created. This API uses a promise to return the result. - -**System capability**: SystemCapability.Multimedia.Camera.Core - -**Parameters** - -| Name | Type | Mandatory| Description | -| -------- | -----------| ---- | ------------------------------------------------------------------------------ | -| surfaceId| string | Yes | Surface ID, which is obtained from **[XComponent](../arkui-ts/ts-basic-components-xcomponent.md)**.| - -**Return value** - -| Type | Description | -| -------------- | ----------------------- | -| Promise| Promise used to return the result.| - -**Example** - -```js -previewOutput.addDeferredSurface('surfaceId').then(() => { - console.log('Promise returned with deferredSurface added.'); -}) -``` - -### start - -start(callback: AsyncCallback): void - -Starts to output preview streams. This API uses an asynchronous callback to return the result. - -**System capability**: SystemCapability.Multimedia.Camera.Core - -**Parameters** - -| Name | Type | Mandatory| Description | -| -------- | -------------------- | ---- | -------------------- | -| callback | AsyncCallback | Yes | Callback used to return the result.| - -**Example** - -```js -previewOutput.start((err) => { - if (err) { - console.error(`Failed to start the previewOutput. ${err.message}`); - return; - } - console.log('Callback returned with previewOutput started.'); -}) -``` - -### start - -start(): Promise - -Starts to output preview streams. This API uses a promise to return the result. - -**System capability**: SystemCapability.Multimedia.Camera.Core - -**Return value** - -| Type | Description | -| -------------- | ----------------------- | -| Promise| Promise used to return the result.| - -**Example** - -```js -previewOutput.start().then(() => { - console.log('Promise returned with previewOutput started.'); -}) -``` - -### stop - -stop(callback: AsyncCallback): void - -Stops outputting preview streams. This API uses an asynchronous callback to return the result. - -**System capability**: SystemCapability.Multimedia.Camera.Core - -**Parameters** - -| Name | Type | Mandatory| Description | -| -------- | -------------------- | ---- | -------------------- | -| callback | AsyncCallback | Yes | Callback used to return the result.| - -**Example** - -```js -previewOutput.stop((err) => { - if (err) { - console.error(`Failed to stop the previewOutput. ${err.message}`); - return; - } - console.log('Callback returned with previewOutput stopped.'); -}) -``` - -### stop - -stop(): Promise - -Stops outputting preview streams. This API uses a promise to return the result. - -**System capability**: SystemCapability.Multimedia.Camera.Core - -**Return value** - -| Type | Description | -| -------------- | ------------------------ | -| Promise| Promise used to return the result.| - -**Example** - -```js -previewOutput.stop().then(() => { - console.log('Callback returned with previewOutput stopped.'); -}) -``` - -### on('frameStart') - -on(type: 'frameStart', callback: AsyncCallback): void - -Listens for preview frame start events. This API uses an asynchronous callback to return the result. - -**System capability**: SystemCapability.Multimedia.Camera.Core - -**Parameters** - -| Name | Type | Mandatory| Description | -| -------- | -------------------- | ---- | --------------------------------------- | -| type | string | Yes | Event type. The value is fixed at **'frameStart'**, indicating the preview frame start event.| -| callback | AsyncCallback | Yes | Callback used to return the result. | - -**Example** - -```js -previewOutput.on('frameStart', () => { - console.log('Preview frame started'); -}) -``` - -### on('frameEnd') - -on(type: 'frameEnd', callback: AsyncCallback): void - -Listens for preview frame end events. This API uses an asynchronous callback to return the result. - -**System capability**: SystemCapability.Multimedia.Camera.Core - -**Parameters** - -| Name | Type | Mandatory| Description | -| -------- | -------------------- | ---- | ------------------------------------- | -| type | string | Yes | Event type. The value is fixed at **'frameEnd'**, indicating the preview frame end event.| -| callback | AsyncCallback | Yes | Callback used to return the result. | - -**Example** - -```js -previewOutput.on('frameEnd', () => { - console.log('Preview frame ended'); -}) -``` - -### on('error') - -on(type: 'error', callback: ErrorCallback): void - -Listens for **PreviewOutput** errors. This API uses a callback to return the errors. - -**System capability**: SystemCapability.Multimedia.Camera.Core - -**Parameters** - -| Name | Type | Mandatory| Description | -| -------- | ----------------------------------------------------------------- | ---- | ------------------------ | -| type | string | Yes | Event type. The value is fixed at **'error'**, indicating the preview output error event.| -| callback | ErrorCallback<[PreviewOutputErrorCode](#previewoutputerrorcode)\> | Yes | Callback used to return the error information. | - -**Example** - -```js -previewOutput.on('error', (previewOutputError) => { - console.log(`Preview output error code: ${previewOutputError.code}`); -}) -``` - -## PreviewOutputErrorCode - -Enumerates the error codes used for preview output. - -**System capability**: SystemCapability.Multimedia.Camera.Core - -| Name | Value | Description | -| ------------- | ---- | -------- | -| ERROR_UNKNOWN | -1 | Unknown error.| - -## PreviewOutputError - -Defines the preview output error. - -**System capability**: SystemCapability.Multimedia.Camera.Core - -| Name| Type | Description | -| ---- | ------------------------------------------------- | ---------------------- | -| code | [PreviewOutputErrorCode](#previewoutputerrorcode) | **PreviewOutput** error code.| - -## ImageRotation - -Enumerates the image rotation angles. - -**System capability**: SystemCapability.Multimedia.Camera.Core - -| Name | Value | Description | -| ------------ | ---- | ------------- | -| ROTATION_0 | 0 | The image rotates 0 degrees. | -| ROTATION_90 | 90 | The image rotates 90 degrees. | -| ROTATION_180 | 180 | The image rotates 180 degrees.| -| ROTATION_270 | 270 | The image rotates 270 degrees.| - -## Location - -Defines geolocation information. - -**System capability**: SystemCapability.Multimedia.Camera.Core - -| Name | Type | Mandatory|Description | -| ------------ | ------ | --- |------------ | -| latitude | number | Yes |Latitude, in degrees. | -| longitude | number | Yes |Longitude, in degrees. | -| altitude | number | Yes |Altitude, in meters. | - -## QualityLevel - -Enumerates the image quality levels. - -**System capability**: SystemCapability.Multimedia.Camera.Core - -| Name | Value | Description | -| -------------------- | ---- | ------------ | -| QUALITY_LEVEL_HIGH | 0 | High image quality. | -| QUALITY_LEVEL_MEDIUM | 1 | Medium image quality.| -| QUALITY_LEVEL_LOW | 2 | Low image quality. | - - -## PhotoCaptureSetting - -Defines the settings for photo capture. - -**System capability**: SystemCapability.Multimedia.Camera.Core - -| Name | Type | Mandatory | Default Value | Description | -| -------- | ------------------------------- | ---- | ----------------- | -----------------| -| quality | [QualityLevel](#qualitylevel) | No | QUALITY_LEVEL_HIGH| Photo quality. | -| rotation | [ImageRotation](#imagerotation) | No | ROTATION_0 | Rotation angle of the photo. | -| location | [Location](#location) | No | (0,0,0) | Geolocation information of the photo. | -| mirror | boolean | No | false |Whether mirroring is enabled. By default, mirroring is disabled.| - -## PhotoOutput - -Implements output information used in a **CaptureSession**. - -### getDefaultCaptureSetting - -getDefaultCaptureSetting(callback: AsyncCallback): void - -Obtains the default shooting parameters. This API uses an asynchronous callback to return the result. - -**System capability**: SystemCapability.Multimedia.Camera.Core - -**Parameters** - -| Name | Type | Mandatory| Description | -| -------- | ----------------------------------------------------------- | ---- | -------------------- | -| callback | AsyncCallback<[PhotoCaptureSetting](#photocapturesetting)\> | Yes | Callback used to return the result.| - -**Example** - -```js -photoOutput.getDefaultCaptureSetting((err, photocapturesetting) => { - if (err) { - console.error(`Failed to get the defaultCaptureSetting. ${err.message}`); - return; - } - console.log('Callback returned with an array of defaultCaptureSetting.'); -}) -``` - -### getDefaultCaptureSetting - -getDefaultCaptureSetting(): Promise - -Obtains the default shooting parameters. This API uses a promise to return the result. - -**System capability**: SystemCapability.Multimedia.Camera.Core - -**Return value** - -| Type | Description | -| ----------------------------------------------------- | ----------------------- | -| Promise<[PhotoCaptureSetting](#photocapturesetting)\> | Promise used to return the result.| - -**Example** - -```js -photoOutput.getDefaultCaptureSetting().then((photocapturesetting) => { - console.log('Callback returned with an array of defaultCaptureSetting.'); -}) -``` - -### capture - -capture(callback: AsyncCallback): void - -Captures a photo with the default shooting parameters. This API uses an asynchronous callback to return the result. - -**System capability**: SystemCapability.Multimedia.Camera.Core - -**Parameters** - -| Name | Type | Mandatory| Description | -| -------- | -------------------- | ---- | ------------------- | -| callback | AsyncCallback | Yes | Callback used to return the result.| - -**Example** - -```js -photoOutput.capture((err) => { - if (err) { - console.error(`Failed to capture the photo ${err.message}`); - return; - } - console.log('Callback invoked to indicate the photo capture request success.'); -}); -``` - -### capture - -capture(setting: PhotoCaptureSetting, callback: AsyncCallback): void - -Captures a photo with the specified shooting parameters. This API uses an asynchronous callback to return the result. - -**System capability**: SystemCapability.Multimedia.Camera.Core - -**Parameters** - -| Name | Type | Mandatory| Description | -| -------- | ------------------------------------------- | ---- | -------------------- | -| setting | [PhotoCaptureSetting](#photocapturesetting) | Yes | Shooting settings. | -| callback | AsyncCallback | Yes | Callback used to return the result. | - -**Example** - -```js -let settings:PhotoCaptureSetting = { - quality = 1, - rotation = 0 -} -photoOutput.capture(settings, (err) => { - if (err) { - console.error(`Failed to capture the photo ${err.message}`); - return; - } - console.log('Callback invoked to indicate the photo capture request success.'); -}); -``` - -### capture - -capture(setting?: PhotoCaptureSetting): Promise - -Captures a photo with the specified shooting parameters. This API uses a promise to return the result. - -**System capability**: SystemCapability.Multimedia.Camera.Core - -**Parameters** - -| Name | Type | Mandatory| Description | -| ------- | ------------------------------------------- | ---- | -------- | -| setting | [PhotoCaptureSetting](#photocapturesetting) | No | Shooting settings.| - -**Return value** - -| Type | Description | -| -------------- | ------------------------ | -| Promise| Promise used to return the result.| - - -**Example** - -```js -photoOutput.capture().then(() => { - console.log('Promise returned to indicate that photo capture request success.'); -}) -``` - -### isMirrorSupported - -isMirrorSupported(callback: AsyncCallback): void - -Checks whether mirroring is supported. This API uses an asynchronous callback to return the result. - -**System capability**: SystemCapability.Multimedia.Camera.Core - -**Parameters** - -| Name | Type | Mandatory| Description | -| -------- | ------------------------------------------------- | ---- | -------------------------- | -| callback | AsyncCallback | Yes | Callback used to return the mirroring support status. The value **true** means that mirroring is supported, and **false** means the opposite. | - -**Example** - -```js -captureSession.isMirrorSupported((err, isSupported) => { - if (err) { - console.error(`Failed to check mirror is supported ${err.message}`); - return; - } - console.log('Callback returned with the successful execution of isMirrorSupported.'); -}) -``` - -### isMirrorSupported - -isMirrorSupported(): Promise - -Checks whether mirroring is supported. This API uses a promise to return the result. - -**System capability**: SystemCapability.Multimedia.Camera.Core - -**Return value** - -| Type | Description | -| ----------------- | ------------------------------------------- | -| Promise | Promise used to return the mirroring support status. The value **true** means that mirroring is supported, and **false** means the opposite. | - -**Example** - -```js -captureSession.isMirrorSupported().then((isSupported) => { - console.log(`Promise returned with mirror supported: ${isSupported}`); -}) -``` - -### on('captureStart') - -on(type: 'captureStart', callback: AsyncCallback): void - -Listens for shooting start events. This API uses an asynchronous callback to return the capture ID. - -**System capability**: SystemCapability.Multimedia.Camera.Core - -**Parameters** - -| Name | Type | Mandatory| Description | -| -------- | ---------------------- | ---- | ------------------------------------------ | -| type | string | Yes | Event type. The value is fixed at **'captureStart'**, indicating the shooting start event.| -| callback | AsyncCallback | Yes | Callback used to return the capture ID. | - -**Example** - -```js -photoOutput.on('captureStart', (err, captureId) => { - console.log(`photo capture stated, captureId : ${captureId}`); -}) -``` - -### on('frameShutter') - -on(type: 'frameShutter', callback: AsyncCallback): void - -Listens for frame shutter events. This API uses an asynchronous callback to return the event information. - -**System capability**: SystemCapability.Multimedia.Camera.Core - -**Parameters** - -| Name | Type | Mandatory| Description | -| -------- | ----------------------------------------------------- | --- | ------------------------------------ | -| type | string | Yes | Event type. The value is fixed at **'frameShutter'**, indicating the frame shutter event.| -| callback | AsyncCallback<[FrameShutterInfo](#frameshutterinfo)\> | Yes | Callback used to return the result. | - -**Example** - -```js -photoOutput.on('frameShutter', (err, frameShutterInfo) => { - console.log(`photo capture end, captureId : ${frameShutterInfo.captureId}`); - console.log(`Timestamp for frame : ${frameShutterInfo.timestamp}`); -}) -``` - -### on('captureEnd') - -on(type: 'captureEnd', callback: AsyncCallback): void - -Listens for shooting end events. This API uses an asynchronous callback to return the event information. - -**System capability**: SystemCapability.Multimedia.Camera.Core - -**Parameters** - -| Name | Type | Mandatory| Description | -| -------- | ------------------------------------------------- | ---- | ---------------------------------------- | -| type | string | Yes | Event type. The value is fixed at **'captureEnd'**, indicating the shooting end event.| -| callback | AsyncCallback<[CaptureEndInfo](#captureendinfo)\> | Yes | Callback used to return the result. | - -**Example** - -```js -photoOutput.on('captureEnd', (err, captureEndInfo) => { - console.log(`photo capture end, captureId : ${captureEndInfo.captureId}`); - console.log(`frameCount : ${captureEndInfo.frameCount}`); -}) -``` - -### on('error') - -on(type: 'error', callback: ErrorCallback): void - -Listens for **PhotoOutput** errors. This API uses a callback to return the errors. - -**System capability**: SystemCapability.Multimedia.Camera.Core - -**Parameters** - -| Name | Type | Mandatory| Description | -| -------- | ----------------------------------------------------- | ---- | ----------------------------------- | -| type | string | Yes | Event type. The value is fixed at **'error'**, indicating the photo output error event.| -| callback | ErrorCallback<[PhotoOutputError](#photooutputerror)\> | Yes | Callback used to return the error information. | - -**Example** - -```js -photoOutput.on('error', (err, photoOutputError) => { - console.log(`Photo output error code: ${photoOutputError.code}`); -}) -``` +**System capability**: SystemCapability.Multimedia.Camera.Core -## FrameShutterInfo +| Name | Value | Description | +| ------------ | ---- | --------------- | +| ROTATION_0 | 0 | The image rotates 0 degrees. | +| ROTATION_90 | 90 | The image rotates 90 degrees. | +| ROTATION_180 | 180 | The image rotates 180 degrees.| +| ROTATION_270 | 270 | The image rotates 270 degrees.| -Defines the frame shutter information. +## QualityLevel + +Enumerates the image quality levels. **System capability**: SystemCapability.Multimedia.Camera.Core -| Name | Type | Mandatory| Description | -| --------- | ------ | ---- | ---------- | -| captureId | number | Yes | ID of this capture action. | -| timestamp | number | Yes | Timestamp when the frame shutter event is triggered.| +| Name | Value | Description | +| -------------------- | ---- | -------------- | +| QUALITY_LEVEL_HIGH | 0 | High image quality. | +| QUALITY_LEVEL_MEDIUM | 1 | Medium image quality.| +| QUALITY_LEVEL_LOW | 2 | Low image quality. | -## CaptureEndInfo -Defines the capture end information. +## PhotoCaptureSetting + +Defines the settings for photo capture. **System capability**: SystemCapability.Multimedia.Camera.Core -| Name | Type | Mandatory| Description | -| ---------- | ------ | ---- | ---------| -| captureId | number | Yes | ID of this capture action.| -| frameCount | number | Yes | Number of frames captured. | +| Name | Type | Mandatory| Description | +| -------- | ------------------------------- | ---- | -------------- | +| quality | [QualityLevel](#qualitylevel) | No | Photo quality. | +| rotation | [ImageRotation](#imagerotation) | No | Rotation angle of the photo.| -## PhotoOutputErrorCode -Enumerates the error codes used for photo output. +## PhotoOutput -**System capability**: SystemCapability.Multimedia.Camera.Core +Implements photo output. -| Name | Value | Description | -| ----------------------------- | ---- | --------------- | -| ERROR_UNKNOWN | -1 | Unknown error. | -| ERROR_DRIVER_ERROR | 0 | The driver or hardware is faulty.| -| ERROR_INSUFFICIENT_RESOURCES | 1 | Insufficient resources. | -| ERROR_TIMEOUT | 2 | Timeout. | +### capture -## PhotoOutputError +capture(callback: AsyncCallback): void -Defines a photo output error. +Captures a photo with the default shooting settings. This API uses an asynchronous callback to return the result. **System capability**: SystemCapability.Multimedia.Camera.Core -| Name| Type | Description | -| ---- | ------------------------------------- | ----------------------- | -| code | [PhotoOutputError](#photooutputerror) | **PhotoOutput** error code.| +**Parameters** -## VideoOutput +| Name | Type | Mandatory| Description | +| -------- | -------------------- | ---- | ------------------------ | +| callback | AsyncCallback | Yes | Callback used to return the result.| -Implements output information used in a video recording session. +**Example** -### start +```js +photoOutput.capture((err) => { + if (err) { + console.error('Failed to capture the photo ${err.message}'); + return; + } + console.log('Callback invoked to indicate the photo capture request success.'); +}); +``` -start(callback: AsyncCallback): void +### capture -Starts video recording. This API uses an asynchronous callback to return the result. +capture(setting: PhotoCaptureSetting, callback: AsyncCallback): void + +Captures a photo with the specified shooting settings. This API uses an asynchronous callback to return the result. **System capability**: SystemCapability.Multimedia.Camera.Core **Parameters** -| Name | Type | Mandatory| Description | -| -------- | -------------------- | ---- | -------------------- | -| callback | AsyncCallback | Yes | Callback used to return the result.| +| Name | Type | Mandatory| Description | +| -------- | ------------------------------------------- | ---- | ------------------------ | +| setting | [PhotoCaptureSetting](#photocapturesetting) | Yes | Shooting settings. | +| callback | AsyncCallback | Yes | Callback used to return the result.| **Example** ```js -videoOutput.start((err) => { +let settings:PhotoCaptureSetting = { + quality = 1, + rotation = 0 +} +photoOutput.capture(settings, (err) => { if (err) { - console.error(`Failed to start the video output ${err.message}`); + console.error('Failed to capture the photo ${err.message}'); return; } - console.log('Callback invoked to indicate the video output start success.'); + console.log('Callback invoked to indicate the photo capture request success.'); }); ``` -### start +### capture -start(): Promise +capture(setting?: PhotoCaptureSetting): Promise -Starts video recording. This API uses a promise to return the result. +Captures a photo with the specified shooting settings. This API uses a promise to return the result. **System capability**: SystemCapability.Multimedia.Camera.Core +**Parameters** + +| Name | Type | Mandatory| Description | +| ------- | ------------------------------------------- | ---- | ---------- | +| setting | [PhotoCaptureSetting](#photocapturesetting) | No | Shooting settings.| + **Return value** -| Type | Description | -| -------------- | ----------------------- | +| Type | Description | +| -------------- | --------------------------- | | Promise| Promise used to return the result.| **Example** ```js -videoOutput.start().then(() => { - console.log('Promise returned to indicate that start method execution success.'); +photoOutput.capture().then(() => { + console.log('Promise returned to indicate that photo capture request success.'); }) ``` -### stop +### release -stop(callback: AsyncCallback): void +release(callback: AsyncCallback): void -Stops video recording. This API uses an asynchronous callback to return the result. +Releases this **PhotoOutput** instance. This API uses an asynchronous callback to return the result. **System capability**: SystemCapability.Multimedia.Camera.Core @@ -4106,465 +2290,465 @@ Stops video recording. This API uses an asynchronous callback to return the resu **Example** ```js -videoOutput.stop((err) => { +photoOutput.release((err) => { if (err) { - console.error(`Failed to stop the video output ${err.message}`); + console.error('Failed to release the PhotoOutput instance ${err.message}'); return; } - console.log('Callback invoked to indicate the video output stop success.'); + console.log('Callback invoked to indicate that the PhotoOutput instance is released successfully.'); }); ``` -### stop +### release -stop(): Promise +release(): Promise -Stops video recording. This API uses a promise to return the result. +Releases this **PhotoOutput** instance. This API uses a promise to return the result. **System capability**: SystemCapability.Multimedia.Camera.Core **Return value** -| Type | Description | -| -------------- | ----------------------- | +| Type | Description | +| -------------- | --------------------------- | | Promise| Promise used to return the result.| + **Example** ```js -videoOutput.stop().then(() => { - console.log('Promise returned to indicate that stop method execution success.'); +photoOutput.release().then(() => { + console.log('Promise returned to indicate that the PhotoOutput instance is released successfully.'); }) -``` +``` -### on('frameStart') +### on('captureStart') -on(type: 'frameStart', callback: AsyncCallback): void +on(type: 'captureStart', callback: AsyncCallback): void -Listens for video recording start events. This API uses an asynchronous callback to return the result. +Listens for shooting start events. This API uses an asynchronous callback to return the capture ID. **System capability**: SystemCapability.Multimedia.Camera.Core **Parameters** -| Name | Type | Mandatory| Description | -| -------- | -------------------- | ---- | ----------------------------------------- | -| type | string | Yes | Event type. The value is fixed at **frameStart**, indicating the video recording start event.| -| callback | AsyncCallback | Yes | Callback used to return the result. | +| Name | Type | Mandatory| Description | +| :------- | :--------------------- | :--- | :----------------------------------------------- | +| type | string | Yes | Event type. The value is fixed at **'captureStart'**, indicating the shooting start event.| +| callback | AsyncCallback | Yes | Callback used to return the capture ID. | **Example** ```js -videoOutput.on('frameStart', () => { - console.log('Video frame started'); +photoOutput.on('captureStart', (err, captureId) => { + console.log('photo capture stated, captureId : ' + captureId); }) ``` -### on('frameEnd') +### on('frameShutter') -on(type: 'frameEnd', callback: AsyncCallback): void +on(type: 'frameShutter', callback: AsyncCallback): void -Listens for video recording stop events. This API uses an asynchronous callback to return the result. +Listens for frame shutter events. This API uses an asynchronous callback to return the event information. **System capability**: SystemCapability.Multimedia.Camera.Core **Parameters** -| Name | Type | Mandatory| Description | -| -------- | -------------------- | ---- | ------------------------------------------ | -| type | string | Yes | Event type. The value is fixed at **'frameEnd'**, indicating the video recording stop event.| -| callback | AsyncCallback | Yes | Callback used to return the result. | +| Name | Type | Mandatory| Description | +| :------- | :---------------------------------------------------- | :--- | :--------------------------------------------- | +| type | string | Yes | Event type. The value is fixed at **'frameShutter'**, indicating the frame shutter event.| +| callback | AsyncCallback<[FrameShutterInfo](#frameshutterinfo)\> | Yes | Callback used to return the result. | **Example** ```js -videoOutput.on('frameEnd', () => { - console.log('Video frame ended'); +photoOutput.on('frameShutter', (err, frameShutterInfo) => { + console.log('photo capture end, captureId : ' + frameShutterInfo.captureId); + console.log('Timestamp for frame : ' + frameShutterInfo.timestamp); }) ``` -### on('error') +### on('captureEnd') -on(type: 'error', callback: ErrorCallback): void +on(type: 'captureEnd', callback: AsyncCallback): void -Listens for errors that occur during video recording. This API uses a callback to return the result. +Listens for shooting end events. This API uses an asynchronous callback to return the event information. **System capability**: SystemCapability.Multimedia.Camera.Core **Parameters** -| Name | Type | Mandatory| Description | -| -------- | ------------------------------------------------ | ---- | -------------------------------------- | -| type | string | Yes | Event type. The value is fixed at **'error'**, indicating the video output error event.| -| callback | Callback<[VideoOutputError](#videooutputerror)\> | Yes | Callback used to return the error information. | +| Name | Type | Mandatory| Description | +| :------- | :------------------------------------------------ | :--- | :--------------------------------------------- | +| type | string | Yes | Event type. The value is fixed at **'captureEnd'**, indicating the shooting end event.| +| callback | AsyncCallback<[CaptureEndInfo](#captureendinfo)\> | Yes | Callback used to return the result. | **Example** ```js -videoOutput.on('error', (VideoOutputError) => { - console.log(`Video output error code: ${VideoOutputError.code}`); +photoOutput.on('captureEnd', (err, captureEndInfo) => { + console.log('photo capture end, captureId : ' + captureEndInfo.captureId); + console.log('frameCount : ' + captureEndInfo.frameCount); }) ``` -## VideoOutputErrorCode +### on('error') + +on(type: 'error', callback: ErrorCallback): void -Enumerates the error codes used for video recording. +Listens for **PhotoOutput** errors. This API uses a callback to return the errors. **System capability**: SystemCapability.Multimedia.Camera.Core -| Name | Value | Description | -| --------------------- | ---- | ------------ | -| ERROR_UNKNOWN | -1 | Unknown error. | -| ERROR_DRIVER_ERROR | 0 | The driver or hardware is faulty.| +**Parameters** + +| Name | Type | Mandatory| Description | +| :------- | :---------------------------------------------------- | :--- | :---------------------------------------- | +| type | string | Yes | Event type. The value is fixed at **'error'**, indicating the photo output error event.| +| callback | ErrorCallback<[PhotoOutputError](#photooutputerror)\> | Yes | Callback used to return the error information. | + +**Example** -## VideoOutputError +```js +photoOutput.on('error', (err, photoOutputError) => { + console.log('Photo output error code: ' + photoOutputError.code); +}) +``` -Defines a video output error. +## FrameShutterInfo + +Defines the frame shutter information. **System capability**: SystemCapability.Multimedia.Camera.Core -| Name| Type | Description | -| ---- | ------------------------------------- | ----------------------- | -| code | [PhotoOutputError](#photooutputerror) | **VideoOutput** error code.| +| Name | Type | Mandatory| Description | +| --------- | ------ | ---- | ----------------------------- | +| captureId | number | Yes | ID of this capture action.| +| timestamp | number | Yes | Timestamp when the frame shutter event is triggered. | -## MetadataObjectType +## CaptureEndInfo -Enumerates metadata streams. +Defines the capture end information. **System capability**: SystemCapability.Multimedia.Camera.Core -| Name | Value | Description | -| ------------------------- | ---- | ----------------- | -| FACE_DETECTION | 0 | Metadata object type.| +| Name | Type | Mandatory| Description | +| ---------- | ------ | ---- | ----------------------------- | +| captureId | number | Yes | ID of this capture action.| +| frameCount | number | Yes | Number of frames captured. | -## Rect +## PhotoOutputErrorCode -Defines a rectangle. +Enumerates the error codes used in a **PhotoOutput** instance. **System capability**: SystemCapability.Multimedia.Camera.Core -| Name | Type | Description | -| -------- | ------ | -------------------- | -| topLeftX | number | X-axis coordinate of the upper left corner of the rectangle. | -| topLeftY | number | Y-axis coordinate of the upper left corner of the rectangle. | -| width | number | Width of the rectangle. | -| height | number | Height of the rectangle. | +| Name | Value | Description | +| ------------- | ---- | ---------- | +| ERROR_UNKNOWN | -1 | Unknown error.| + +## PhotoOutputError + +Defines a **PhotoOutput** error. -## MetadataObject +**System capability**: SystemCapability.Multimedia.Camera.Core -Implements camera metadata, which is the data source of **[CameraInput](#camerainput)**. +| Name| Type | Description | +| ---- | ------------------------------------- | ----------------------- | +| code | [PhotoOutputError](#photooutputerror) | **PhotoOutput** error code.| -### getType +## camera.createVideoOutput -getType(callback: AsyncCallback): void +createVideoOutput(surfaceId: string, callback: AsyncCallback): void -Obtains the metadata object type. This API uses an asynchronous callback to return the result. +Creates a **VideoOutput** instance. This API uses an asynchronous callback to return the result. **System capability**: SystemCapability.Multimedia.Camera.Core **Parameters** -| Name | Type | Mandatory| Description | -| -------- | --------------------------------------------------------- | --- | -------------------- | -| callback | AsyncCallback<[MetadataObjectType](#metadataobjecttype)\> | Yes | Callback used to return the result.| +| Name | Type | Mandatory| Description | +| --------- | ------------------------------------------- | ---- | ----------------------------------- | +| surfaceId | string | Yes | Surface ID, which is obtained from **VideoRecorder**. | +| callback | AsyncCallback<[VideoOutput](#videooutput)\> | Yes | Callback used to return the **VideoOutput** instance.| **Example** ```js -metadataObject.getType((err, metadataObjectType) => { +camera.createVideoOutput(("surfaceId"), (err, videoOutput) => { if (err) { - console.error(`Failed to get type. ${err.message}`); + console.error('Failed to create the VideoOutput instance. ${err.message}'); return; } - console.log('Callback returned with an array of metadataObjectType.'); -}) + console.log('Callback returned with the VideoOutput instance'); +}); ``` -### getType +## camera.createVideoOutput -getType(): Promise +createVideoOutput(surfaceId: string): Promise -Obtains the metadata object type. This API uses a promise to return the result. +Creates a **VideoOutput** instance. This API uses a promise to return the result. **System capability**: SystemCapability.Multimedia.Camera.Core +**Parameters** + +| Name | Type | Mandatory| Description | +| --------- | ------ | ---- | --------------------------------- | +| surfaceId | string | Yes | Surface ID, which is obtained from **VideoRecorder**.| + **Return value** -| Type | Description | -| --------------------------------------------------- | --------------------------- | -| Promise<[MetadataObjectType](#metadataobjecttype)\> | Promise used to return the result.| +| Type | Description | +| ------------------------------------- | -------------------------------------- | +| Promise<[VideoOutput](#videooutput)\> | Promise used to return the **VideoOutput** instance.| **Example** ```js -metadataObject.getType().then((metadataObjectType) => { - console.log('Callback returned with an array of metadataObjectType.'); +camera.createVideoOutput("surfaceId" +).then((videoOutput) => { + console.log('Promise returned with the VideoOutput instance'); }) ``` -### getTimestamp +## VideoOutput + +Implements output information used in a video recording session. + +### start -getTimestamp(callback: AsyncCallback): void +start(callback: AsyncCallback): void -Obtains the metadata timestamp. This API uses an asynchronous callback to return the result. +Starts video recording. This API uses an asynchronous callback to return the result. **System capability**: SystemCapability.Multimedia.Camera.Core **Parameters** -| Name | Type | Mandatory| Description | -| -------- | ----------------------------------------------------------- | ---- | ------------------------ | -| callback | AsyncCallback | Yes | Callback used to return the result.| +| Name | Type | Mandatory| Description | +| -------- | -------------------- | ---- | ------------------------ | +| callback | AsyncCallback | Yes | Callback used to return the result.| **Example** ```js -metadataObject.getTimestamp((err) => { +videoOutput.start((err) => { if (err) { - console.error(`Failed to get timestamp. ${err.message}`); + console.error('Failed to start the video output ${err.message}'); return; } - console.log('Callback returned with timestamp getted.'); -}) + console.log('Callback invoked to indicate the video output start success.'); +}); ``` -### getTimestamp +### start -getTimestamp(): Promise +start(): Promise -Obtains the metadata timestamp. This API uses a promise to return the result. +Starts video recording. This API uses a promise to return the result. **System capability**: SystemCapability.Multimedia.Camera.Core **Return value** -| Type | Description | -| ---------------- | --------------------------- | -| Promise | Promise used to return the result.| +| Type | Description | +| -------------- | --------------------------- | +| Promise| Promise used to return the result.| + **Example** ```js -metadataObject.getTimestamp().then(() => { - console.log('Callback returned with timestamp getted.'); +videoOutput.start().then(() => { + console.log('Promise returned to indicate that start method execution success.'); }) ``` -### getBoundingBox +### stop -getBoundingBox(callback: AsyncCallback): void +stop(callback: AsyncCallback): void -Obtains the bounding box of metadata. This API uses an asynchronous callback to return the result. +Stops video recording. This API uses an asynchronous callback to return the result. **System capability**: SystemCapability.Multimedia.Camera.Core **Parameters** -| Name | Type | Mandatory| Description | -| -------- | ----------------------------------------------------------- | ---- | ------------------------ | -| callback | AsyncCallback<[Rect](#rect)\> | Yes | Callback used to return the result.| +| Name | Type | Mandatory| Description | +| -------- | -------------------- | ---- | ------------------------ | +| callback | AsyncCallback | Yes | Callback used to return the result.| **Example** ```js -metadataObject.getBoundingBox((err, rect) => { +videoOutput.stop((err) => { if (err) { - console.error(`Failed to get boundingBox. ${err.message}`); + console.error('Failed to stop the video output ${err.message}'); return; } - console.log('Callback returned with boundingBox getted.'); -}) + console.log('Callback invoked to indicate the video output stop success.'); +}); ``` -### getBoundingBox +### stop -getBoundingBox(): Promise +stop(): Promise -Obtains the bounding box of metadata. This API uses a promise to return the result. +Stops video recording. This API uses a promise to return the result. **System capability**: SystemCapability.Multimedia.Camera.Core **Return value** -| Type | Description | -| ---------------------- | --------------------------- | -| Promise<[Rect](#rect)\> | Promise used to return the result.| +| Type | Description | +| -------------- | --------------------------- | +| Promise| Promise used to return the result.| **Example** ```js -metadataObject.getBoundingBox().then((rect) => { - console.log('Callback returned with boundingBox getted.'); +videoOutput.start().then(() => { + console.log('Promise returned to indicate that stop method execution success.'); }) ``` -## MetadataFaceObject - -Implements the face object of metadata. It inherits [MetadataObject](#metadataobject). - -## MetadataOutput - -Implements metadata streams. It inherits **[CameraOutput](#cameraoutput)**. - -### start +### release -start(callback: AsyncCallback): void +release(callback: AsyncCallback): void -Starts to output metadata. This API uses an asynchronous callback to return the result. +Releases this **VideoOutput** instance. This API uses an asynchronous callback to return the result. **System capability**: SystemCapability.Multimedia.Camera.Core **Parameters** -| Name | Type | Mandatory| Description | -| -------- | ----------------------------------------------------------- | ---- | ------------------- | -| callback | AsyncCallback | Yes | Callback used to return the result.| +| Name | Type | Mandatory| Description | +| -------- | -------------------- | ---- | ------------------------ | +| callback | AsyncCallback | Yes | Callback used to return the result.| **Example** ```js -metadataOutput.start((err) => { +videoOutput.release((err) => { if (err) { - console.error(`Failed to start metadataOutput. ${err.message}`); + console.error('Failed to release the VideoOutput instance ${err.message}'); return; } - console.log('Callback returned with metadataOutput started.'); -}) + console.log('Callback invoked to indicate that the VideoOutput instance is released successfully.'); +}); ``` -### start +### release -start(): Promise +release(): Promise -Starts to output metadata. This API uses a promise to return the result. +Releases this **VideoOutput** instance. This API uses a promise to return the result. **System capability**: SystemCapability.Multimedia.Camera.Core **Return value** -| Type | Description | -| ---------------------- | ------------------------ | -| Promise | Promise used to return the result.| - -**Example** - -```js -metadataOutput.start().then(() => { - console.log('Callback returned with metadataOutput started.'); -}) -``` - -### stop - -stop(callback: AsyncCallback): void - -Stops outputting metadata. This API uses an asynchronous callback to return the result. - -**System capability**: SystemCapability.Multimedia.Camera.Core - -**Parameters** +| Type | Description | +| -------------- | --------------------------- | +| Promise| Promise used to return the result.| -| Name | Type | Mandatory| Description | -| -------- | -------------------------- | ---- | ------------------- | -| callback | AsyncCallback | Yes | Callback used to return the result.| **Example** ```js -metadataOutput.stop((err) => { - if (err) { - console.error(`Failed to stop the metadataOutput. ${err.message}`); - return; - } - console.log('Callback returned with metadataOutput stopped.'); +videoOutput.release().then(() => { + console.log('Promise returned to indicate that the VideoOutput instance is released successfully.'); }) ``` -### stop +### on('frameStart') -stop(): Promise +on(type: 'frameStart', callback: AsyncCallback): void -Stops outputting metadata. This API uses a promise to return the result. +Listens for video recording start events. This API uses an asynchronous callback to return the result. **System capability**: SystemCapability.Multimedia.Camera.Core -**Return value** +**Parameters** -| Type | Description | -| ---------------------- | --------------------------- | -| Promise | Promise used to return the result.| +| Name | Type | Mandatory| Description | +| :------- | :------------------- | :--- | :----------------------------------------------- | +| type | string | Yes | Event type. The value is fixed at **`frameStart`**, indicating the video recording start event.| +| callback | AsyncCallback | Yes | Callback used to return the result. | **Example** ```js -metadataOutput.stop().then(() => { - console.log('Callback returned with metadataOutput stopped.'); +videoOutput.on('frameStart', () => { + console.log('Video frame started'); }) ``` -### on('metadataObjectsAvailable') +### on('frameEnd') -on(type: 'metadataObjectsAvailable', callback: AsyncCallback\>): void +on(type: 'frameEnd', callback: AsyncCallback): void -Listens for metadata objects. This API uses an asynchronous callback to return the result. +Listens for video recording end events. This API uses an asynchronous callback to return the result. **System capability**: SystemCapability.Multimedia.Camera.Core **Parameters** -| Name | Type | Mandatory| Description | -| -------- | ----------------------------------------------- - | ---- | ------------------------------------ | -| type | string | Yes | Event type. The value is fixed at **'metadataObjectsAvailable'**, that is, the metadata object.| -| callback | Callback\> | Yes | Callback used to return the error information. | +| Name | Type | Mandatory| Description | +| :------- | :------------------- | :--- | :--------------------------------------------- | +| type | string | Yes | Event type. The value is fixed at **`frameEnd`**, indicating the video frame end event.| +| callback | AsyncCallback | Yes | Callback used to return the result. | **Example** ```js -metadataOutput.on('metadataObjectsAvailable', (metadataObject) => { - console.log(`metadata output error code: ${metadataObject.code}`); +videoOutput.on('frameEnd', () => { + console.log('Video frame ended'); }) ``` ### on('error') -on(tuype: 'error', callback: ErrorCallback): void +on(type: 'error', callback: ErrorCallback): void -Listens for metadata errors. This API uses an asynchronous callback to return the result. +Listens for **VideoOutput** errors. This API uses a callback to return the result. **System capability**: SystemCapability.Multimedia.Camera.Core **Parameters** -| Name | Type | Mandatory| Description | -| -------- | ------------------------------------------------ | ---- | --------------------------------------- | -| type | string | Yes | Event type. The value is fixed at **'error'**, that is, the metadata error.| -| callback | Callback<[MetadataOutputError](#metadataoutputerror)\> | Yes | Callback used to return the error information. | +| Name | Type | Mandatory| Description | +| :------- | :----------------------------------------------- | :--- | :-------------------------------------------- | +| type | string | Yes | Event type. The value is fixed at **'error'**, indicating the video output error event.| +| callback | Callback<[VideoOutputError](#videooutputerror)\> | Yes | Callback used to return the error information. | **Example** ```js -metadataOutput.on('error', (metadataOutputError) => { - console.log(`Metadata output error code: ${metadataOutputError.code}`); +videoOutput.on('error', (VideoOutputError) => { + console.log('Video output error code: ' + VideoOutputError.code); }) ``` -## MetadataOutputErrorCode +## VideoOutputErrorCode -Enumerates the codes used for metadata output errors. +Enumerates the error codes used in a **VideoOutput** instance. **System capability**: SystemCapability.Multimedia.Camera.Core -| Name | Value | Description | -| ------------------------------- | ---- | -------- | -| ERROR_UNKNOWN | -1 | Unknown error.| -| ERROR_INSUFFICIENT_RESOURCES | 0 | Insufficient resources.| +| Name | Value | Description | +| ------------- | ---- | ---------- | +| ERROR_UNKNOWN | -1 | Unknown error.| -## MetadataOutputError +## VideoOutputError -Defines a metadata output error. +Defines a **VideoOutput** error. **System capability**: SystemCapability.Multimedia.Camera.Core | Name| Type | Description | | ---- | ------------------------------------- | ----------------------- | -| code | [MetadataOutputErrorCode](#metadataoutputerrorcode) | **MetadataOutput** error code.| +| code | [PhotoOutputError](#photooutputerror) | **VideoOutput** error code.| diff --git a/en/application-dev/reference/apis/js-apis-data-ability.md b/en/application-dev/reference/apis/js-apis-data-ability.md index 3860be1f4cd4fae2b432c7286ae5aca1c2b44868..5d393653ce602b60438df2b6f9e54f6ba9cb9fe6 100644 --- a/en/application-dev/reference/apis/js-apis-data-ability.md +++ b/en/application-dev/reference/apis/js-apis-data-ability.md @@ -13,13 +13,10 @@ import dataAbility from '@ohos.data.dataAbility'; ``` - ## dataAbility.createRdbPredicates - createRdbPredicates(name: string, dataAbilityPredicates: DataAbilityPredicates): rdb.RdbPredicates - Creates an **RdbPredicates** object from a **DataAbilityPredicates** object. **System capability**: SystemCapability.DistributedDataManager.DataShare.Core @@ -32,93 +29,93 @@ Creates an **RdbPredicates** object from a **DataAbilityPredicates** object. | dataAbilityPredicates | [DataAbilityPredicates](#dataabilitypredicates) | Yes| **DataAbilityPredicates** object. | **Return value** + | Type| Description| | -------- | -------- | | rdb.[RdbPredicates](js-apis-data-rdb.md#rdbpredicates) | **RdbPredicates** object created.| **Example** + ```js let dataAbilityPredicates = new dataAbility.DataAbilityPredicates() - dataAbilityPredicates.equalTo("NAME", "Rose").between("AGE", 16, 30) + dataAbilityPredicates.equalTo("NAME", "Rose") let predicates = dataAbility.createRdbPredicates("EMPLOYEE", dataAbilityPredicates) ``` - ## DataAbilityPredicates Provides predicates for implementing diverse query methods. - ### equalTo - equalTo(field: string, value: ValueType): DataAbilityPredicates - Sets a **DataAbilityPredicates** object to match the field with data type **ValueType** and value equal to the specified value. **System capability**: SystemCapability.DistributedDataManager.DataShare.Core **Parameters** + | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | | field | string | Yes| Column name in the table.| | value | [ValueType](#valuetype) | Yes| Value to match the **DataAbilityPredicates**.| **Return value** + | Type| Description| | -------- | -------- | | [DataAbilityPredicates](#dataabilitypredicates) | **DataAbilityPredicates** object that matches the specified field.| **Example** + ```js dataAbilityPredicates.equalTo("NAME", "lisi") ``` - ### notEqualTo - notEqualTo(field: string, value: ValueType): DataAbilityPredicates - Sets a **DataAbilityPredicates** object to match the field with data type **ValueType** and value not equal to the specified value. **System capability**: SystemCapability.DistributedDataManager.DataShare.Core **Parameters** + | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | | field | string | Yes| Column name in the table.| | value | [ValueType](#valuetype) | Yes| Value to match the **DataAbilityPredicates**.| **Return value** + | Type| Description| | -------- | -------- | | [DataAbilityPredicates](#dataabilitypredicates) | **DataAbilityPredicates** object that matches the specified field.| **Example** + ```js dataAbilityPredicates.notEqualTo("NAME", "lisi") ``` - ### beginWrap - beginWrap(): DataAbilityPredicates - Adds a left parenthesis to this **DataAbilityPredicates**. **System capability**: SystemCapability.DistributedDataManager.DataShare.Core **Return value** + | Type| Description| | -------- | -------- | | [DataAbilityPredicates](#dataabilitypredicates) | **DataAbilityPredicates** object with a left parenthesis.| **Example** + ```js dataAbilityPredicates.equalTo("NAME", "lisi") .beginWrap() @@ -128,23 +125,22 @@ Adds a left parenthesis to this **DataAbilityPredicates**. .endWrap() ``` - ### endWrap - endWrap(): DataAbilityPredicates - Adds a right parenthesis to this **DataAbilityPredicates**. **System capability**: SystemCapability.DistributedDataManager.DataShare.Core **Return value** + | Type| Description| | -------- | -------- | | [DataAbilityPredicates](#dataabilitypredicates) | **DataAbilityPredicates** object with a right parenthesis.| **Example** + ```js dataAbilityPredicates.equalTo("NAME", "lisi") .beginWrap() @@ -154,251 +150,247 @@ Adds a right parenthesis to this **DataAbilityPredicates**. .endWrap() ``` - ### or - or(): DataAbilityPredicates - Adds the OR condition to this **DataAbilityPredicates**. **System capability**: SystemCapability.DistributedDataManager.DataShare.Core **Return value** + | Type| Description| | -------- | -------- | | [DataAbilityPredicates](#dataabilitypredicates) | **DataAbilityPredicates** object with the OR condition.| **Example** + ```js dataAbilityPredicates.equalTo("NAME", "Lisa") .or() .equalTo("NAME", "Rose") ``` - ### and - and(): DataAbilityPredicates - Adds the AND condition to this **DataAbilityPredicates**. **System capability**: SystemCapability.DistributedDataManager.DataShare.Core **Return value** + | Type| Description| | -------- | -------- | | [DataAbilityPredicates](#dataabilitypredicates) | **DataAbilityPredicates** object with the AND condition.| **Example** + ```js dataAbilityPredicates.equalTo("NAME", "Lisa") .and() .equalTo("SALARY", 200.5) ``` - ### contains - contains(field: string, value: string): DataAbilityPredicates - Sets a **DataAbilityPredicates** object to match a string containing the specified value. **System capability**: SystemCapability.DistributedDataManager.DataShare.Core **Parameters** + | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | | field | string | Yes| Column name in the table.| | value | string | Yes| Value to match the **DataAbilityPredicates**.| **Return value** + | Type| Description| | -------- | -------- | | [DataAbilityPredicates](#dataabilitypredicates) | **DataAbilityPredicates** object that matches the specified field.| **Example** + ```js dataAbilityPredicates.contains("NAME", "os") ``` - ### beginsWith - beginsWith(field: string, value: string): DataAbilityPredicates - Sets a **DataAbilityPredicates** object to match a string that starts with the specified value. **System capability**: SystemCapability.DistributedDataManager.DataShare.Core **Parameters** + | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | | field | string | Yes| Column name in the table.| | value | string | Yes| Value to match the **DataAbilityPredicates**.| **Return value** + | Type| Description| | -------- | -------- | | [DataAbilityPredicates](#dataabilitypredicates) | **DataAbilityPredicates** object that matches the specified field.| **Example** + ```js dataAbilityPredicates.beginsWith("NAME", "os") ``` - ### endsWith - endsWith(field: string, value: string): DataAbilityPredicates - Sets a **DataAbilityPredicates** object to match a string that ends with the specified value. **System capability**: SystemCapability.DistributedDataManager.DataShare.Core **Parameters** + | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | | field | string | Yes| Column name in the table.| | value | string | Yes| Value to match the **DataAbilityPredicates**.| **Return value** + | Type| Description| | -------- | -------- | | [DataAbilityPredicates](#dataabilitypredicates) | **DataAbilityPredicates** object that matches the specified field.| **Example** + ``` dataAbilityPredicates.endsWith("NAME", "se") ``` - ### isNull - isNull(field: string): DataAbilityPredicates - Sets a **DataAbilityPredicates** object to match the field whose value is null. **System capability**: SystemCapability.DistributedDataManager.DataShare.Core **Parameters** + | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | | field | string | Yes| Column name in the table.| **Return value** + | Type| Description| | -------- | -------- | | [DataAbilityPredicates](#dataabilitypredicates) | **DataAbilityPredicates** object that matches the specified field.| **Example** + ```js dataAbilityPredicates.isNull("NAME") ``` - ### isNotNull - isNotNull(field: string): DataAbilityPredicates - Sets a **DataAbilityPredicates** object to match the field whose value is not null. **System capability**: SystemCapability.DistributedDataManager.DataShare.Core **Parameters** + | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | | field | string | Yes| Column name in the table.| **Return value** + | Type| Description| | -------- | -------- | | [DataAbilityPredicates](#dataabilitypredicates) | **DataAbilityPredicates** object that matches the specified field.| **Example** + ```js dataAbilityPredicates.isNotNull("NAME") ``` - ### like - like(field: string, value: string): DataAbilityPredicates - Sets a **DataAbilityPredicates** object to match a string that is similar to the specified value. **System capability**: SystemCapability.DistributedDataManager.DataShare.Core **Parameters** + | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | | field | string | Yes| Column name in the table.| | value | string | Yes| Value to match the **DataAbilityPredicates**.| **Return value** + | Type| Description| | -------- | -------- | | [DataAbilityPredicates](#dataabilitypredicates) | **DataAbilityPredicates** object that matches the specified field.| **Example** + ```js dataAbilityPredicates.like("NAME", "%os%") ``` - ### glob - glob(field: string, value: string): DataAbilityPredicates - Sets a **DataAbilityPredicates** object to match the specified string. **System capability**: SystemCapability.DistributedDataManager.DataShare.Core **Parameters** + | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | | field | string | Yes| Column name in the table.| | value | string | Yes| Value to match the **DataAbilityPredicates**.| **Return value** + | Type| Description| | -------- | -------- | | [DataAbilityPredicates](#dataabilitypredicates) | **DataAbilityPredicates** object that matches the specified field.| **Example** + ```js dataAbilityPredicates.glob("NAME", "?h*g") ``` - ### between - between(field: string, low: ValueType, high: ValueType): DataAbilityPredicates - Sets a **DataAbilityPredicates** object to match a field whose data type is **ValueType** and value is within the specified range. **System capability**: SystemCapability.DistributedDataManager.DataShare.Core **Parameters** + | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | | field | string | Yes| Column name in the table.| @@ -406,27 +398,27 @@ Sets a **DataAbilityPredicates** object to match a field whose data type is **Va | high | [ValueType](#valuetype) | Yes| Maximum value to match the **DataAbilityPredicates**.| **Return value** + | Type| Description| | -------- | -------- | | [DataAbilityPredicates](#dataabilitypredicates) | **DataAbilityPredicates** object that matches the specified field.| **Example** + ```js dataAbilityPredicates.between("AGE", 10, 50) ``` - ### notBetween - notBetween(field: string, low: ValueType, high: ValueType): DataAbilityPredicates - Sets a **DataAbilityPredicates** object to match the field with data type **ValueType** and value out of the specified range. **System capability**: SystemCapability.DistributedDataManager.DataShare.Core **Parameters** + | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | | field | string | Yes| Column name in the table.| @@ -434,244 +426,245 @@ Sets a **DataAbilityPredicates** object to match the field with data type **Valu | high | [ValueType](#valuetype) | Yes| Maximum value to match the **DataAbilityPredicates**.| **Return value** + | Type| Description| | -------- | -------- | | [DataAbilityPredicates](#dataabilitypredicates) | **DataAbilityPredicates** object that matches the specified field.| **Example** + ```js dataAbilityPredicates.notBetween("AGE", 10, 50) ``` - ### greaterThan - greaterThan(field: string, value: ValueType): DataAbilityPredicates - Sets a **DataAbilityPredicates** object to match the field with data type **ValueType** and value greater than the specified value. **System capability**: SystemCapability.DistributedDataManager.DataShare.Core **Parameters** + | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | | field | string | Yes| Column name in the table.| | value | [ValueType](#valuetype) | Yes| Value to match the **DataAbilityPredicates**.| **Return value** + | Type| Description| | -------- | -------- | | [DataAbilityPredicates](#dataabilitypredicates) | **DataAbilityPredicates** object that matches the specified field.| **Example** + ```js dataAbilityPredicates.greaterThan("AGE", 18) ``` - ### lessThan - lessThan(field: string, value: ValueType): DataAbilityPredicates - Sets a **DataAbilityPredicates** object to match the field with data type **ValueType** and value less than the specified value. **System capability**: SystemCapability.DistributedDataManager.DataShare.Core **Parameters** + | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | | field | string | Yes| Column name in the table.| | value | [ValueType](#valuetype) | Yes| Value to match the **DataAbilityPredicates**.| **Return value** + | Type| Description| | -------- | -------- | | [DataAbilityPredicates](#dataabilitypredicates) | **DataAbilityPredicates** object that matches the specified field.| **Example** + ```js dataAbilityPredicates.lessThan("AGE", 20) ``` - ### greaterThanOrEqualTo - greaterThanOrEqualTo(field: string, value: ValueType): DataAbilityPredicates - Sets a **DataAbilityPredicates** object to match the field with data type **ValueType** and value greater than or equal to the specified value. **System capability**: SystemCapability.DistributedDataManager.DataShare.Core **Parameters** + | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | | field | string | Yes| Column name in the table.| | value | [ValueType](#valuetype) | Yes| Value to match the **DataAbilityPredicates**.| **Return value** + | Type| Description| | -------- | -------- | | [DataAbilityPredicates](#dataabilitypredicates) | **DataAbilityPredicates** object that matches the specified field.| **Example** + ```js dataAbilityPredicates.greaterThanOrEqualTo("AGE", 18) ``` - ### lessThanOrEqualTo - lessThanOrEqualTo(field: string, value: ValueType): DataAbilityPredicates - Sets a **DataAbilityPredicates** object to match the field with data type **ValueType** and value less than or equal to the specified value. **System capability**: SystemCapability.DistributedDataManager.DataShare.Core **Parameters** + | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | | field | string | Yes| Column name in the table.| | value | [ValueType](#valuetype) | Yes| Value to match the **DataAbilityPredicates**.| **Return value** + | Type| Description| | -------- | -------- | | [DataAbilityPredicates](#dataabilitypredicates) | **DataAbilityPredicates** object that matches the specified field.| **Example** + ```js dataAbilityPredicates.lessThanOrEqualTo("AGE", 20) ``` - ### orderByAsc - orderByAsc(field: string): DataAbilityPredicates - Sets a **DataAbilityPredicates** object to match the column with values sorted in ascending order. **System capability**: SystemCapability.DistributedDataManager.DataShare.Core **Parameters** + | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | | field | string | Yes| Column name in the table.| **Return value** + | Type| Description| | -------- | -------- | | [DataAbilityPredicates](#dataabilitypredicates) | **DataAbilityPredicates** object that matches the specified field.| **Example** + ```js dataAbilityPredicates.orderByAsc("NAME") ``` - ### orderByDesc - orderByDesc(field: string): DataAbilityPredicates - Sets a **DataAbilityPredicates** object to match the column with values sorted in descending order. **System capability**: SystemCapability.DistributedDataManager.DataShare.Core **Parameters** + | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | | field | string | Yes| Column name in the table.| **Return value** + | Type| Description| | -------- | -------- | | [DataAbilityPredicates](#dataabilitypredicates) | **DataAbilityPredicates** object that matches the specified field.| **Example** + ```js dataAbilityPredicates.orderByDesc("AGE") ``` - ### distinct - distinct(): DataAbilityPredicates - Sets a **DataAbilityPredicates** object to filter out duplicate records. **System capability**: SystemCapability.DistributedDataManager.DataShare.Core **Return value** + | Type| Description| | -------- | -------- | | [DataAbilityPredicates](#dataabilitypredicates) | **DataAbilityPredicates** object that can filter out duplicate records.| **Example** + ```js dataAbilityPredicates.equalTo("NAME", "Rose").distinct() ``` - ### limitAs - limitAs(value: number): DataAbilityPredicates - Set a **DataAbilityPredicates** object to specify the maximum number of records. **System capability**: SystemCapability.DistributedDataManager.DataShare.Core **Parameters** + | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | | value | number | Yes| Maximum number of records.| **Return value** + | Type| Description| | -------- | -------- | | [DataAbilityPredicates](#dataabilitypredicates) | **DataAbilityPredicates** object that specifies the maximum number of records.| **Example** + ```js dataAbilityPredicates.equalTo("NAME", "Rose").limitAs(3) ``` - ### offsetAs - offsetAs(rowOffset: number): DataAbilityPredicates - Sets a **DataAbilityPredicates** object to specify the start position of the returned result. **System capability**: SystemCapability.DistributedDataManager.DataShare.Core **Parameters** + | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | | rowOffset | number | Yes| Number of rows to offset from the beginning. The value is a positive integer.| **Return value** + | Type| Description| | -------- | -------- | | [DataAbilityPredicates](#dataabilitypredicates) | **DataAbilityPredicates** object that specifies the start position of the returned result.| **Example** + ```js dataAbilityPredicates.equalTo("NAME", "Rose").offsetAs(3) ``` @@ -679,66 +672,66 @@ Sets a **DataAbilityPredicates** object to specify the start position of the ret ### groupBy - groupBy(fields: Array<string>): DataAbilityPredicates - Sets a **DataAbilityPredicates** object to group rows that have the same value into summary rows. **System capability**: SystemCapability.DistributedDataManager.DataShare.Core **Parameters** + | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | | fields | Array<string> | Yes| Names of columns to group.| **Return value** + | Type| Description| | -------- | -------- | | [DataAbilityPredicates](#dataabilitypredicates) | **DataAbilityPredicates** object that groups rows with the same value.| **Example** + ```js dataAbilityPredicates.groupBy(["AGE", "NAME"]) ``` ### indexedBy - indexedBy(field: string): DataAbilityPredicates - Sets a **DataAbilityPredicates** object to specify the index column. **System capability**: SystemCapability.DistributedDataManager.DataShare.Core **Parameters** + | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | | indexName | string | Yes| Name of the index column.| **Return value** + | Type| Description| | -------- | -------- | | [DataAbilityPredicates](#dataabilitypredicates) | **DataAbilityPredicates** object that specifies the index column.| **Example** + ```js dataAbilityPredicates.indexedBy("SALARY_INDEX") ``` - ### in - in(field: string, value: Array<ValueType>): DataAbilityPredicates - Sets a **DataAbilityPredicates** object to match the field with data type Array and value within the specified range. **System capability**: SystemCapability.DistributedDataManager.DataShare.Core **Parameters** + | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | | field | string | Yes| Column name in the table.| @@ -746,39 +739,40 @@ Sets a **DataAbilityPredicates** object to match the field with data type Array< **Return value** + | Type| Description| | -------- | -------- | | [DataAbilityPredicates](#dataabilitypredicates) | **DataAbilityPredicates** object that matches the specified field.| **Example** + ```js dataAbilityPredicates.in("AGE", [18, 20]) ``` - ### notIn - notIn(field: string, value: Array<ValueType>): DataAbilityPredicates - Sets a **DataAbilityPredicates** object to match the field with data type Array and value out of the specified range. **System capability**: SystemCapability.DistributedDataManager.DataShare.Core **Parameters** + | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | | field | string | Yes| Column name in the table.| | value | Array<[ValueType](#valuetype)> | Yes| Array of **ValueType**s to match.| - **Return value** + | Type| Description| | -------- | -------- | | [DataAbilityPredicates](#dataabilitypredicates) | **DataAbilityPredicates** object that matches the specified field.| **Example** + ```js dataAbilityPredicates.notIn("NAME", ["Lisa", "Rose"]) ``` diff --git a/en/application-dev/reference/apis/js-apis-dispatchInfo.md b/en/application-dev/reference/apis/js-apis-dispatchInfo.md index 5f476f34bd9ed8c08fc0e033243c1f4fb55ca23c..749ff83e51d077e066bc426c78a5e329510bf0c8 100644 --- a/en/application-dev/reference/apis/js-apis-dispatchInfo.md +++ b/en/application-dev/reference/apis/js-apis-dispatchInfo.md @@ -10,7 +10,9 @@ The **DispatchInfo** module provides dispatch information. **System capability**: SystemCapability.BundleManager.BundleFramework +**System API**: This is a system API and cannot be called by third-party applications. + | Name | Type | Readable| Writable| Description | | ----------- | ------ | ---- | ---- | ------------------------ | -| verison | string | Yes | No | Version of the API to dispatch.| +| version | string | Yes | No | Version of the API to dispatch.| | dispatchAPI | string | Yes | No | API to dispatch. | diff --git a/en/application-dev/reference/apis/js-apis-effectKit.md b/en/application-dev/reference/apis/js-apis-effectKit.md index c5edd6538136499bfe2deb04450cefbda2d8f146..498bc3beb398e1f7b3b6fc20657ef01fec0b8bb1 100644 --- a/en/application-dev/reference/apis/js-apis-effectKit.md +++ b/en/application-dev/reference/apis/js-apis-effectKit.md @@ -40,13 +40,14 @@ Creates a **Filter** instance based on the pixel map. **Example** ```js -import image from "@ohos.multimedia.image" +import image from "@ohos.multimedia.image"; + const color = new ArrayBuffer(96); -let opts = { editable: true, pixelFormat: 3, size: { height: 4, width: 6 } }; -image.createPixelMap(color, opts) - .then((pixelMap) => { - let headFilter = effectKit.createEffect(pixelMap) - }) +let bufferArr = new Uint8Array(color); +let opts = { editable: true, pixelFormat: 3, size: { height: 4, width: 6 } } +image.createPixelMap(color, opts).then((pixelMap) => { + let headFilter = effectKit.createEffect(pixelMap); +}) ``` ## effectKit.createColorPicker @@ -72,14 +73,15 @@ Creates a **ColorPicker** instance based on the pixel map. This API uses a promi **Example** ```js -import image from "@ohos.multimedia.image" +import image from "@ohos.multimedia.image"; + const color = new ArrayBuffer(96); -let opts = { editable: true, pixelFormat: 3, size: { height: 4, width: 6 } }; -image.createPixelMap(color, opts, (pixelMap) => { - effectKit.createColorPicker(pixelMap).then(colorPicker => { - console.info("color picker=" + colorPicker); - }) - .catch(ex => console.error(".error=" + ex.toString())) +let bufferArr = new Uint8Array(color); +let opts = { editable: true, pixelFormat: 3, size: { height: 4, width: 6 } } +image.createPixelMap(color, opts).then((pixelMap) => { + effectKit.createColorPicker(pixelMap).then(colorPicker => { + console.info("color picker=" + colorPicker); + }).catch(ex => console.error(".error=" + ex.toString())) }) ``` @@ -101,17 +103,19 @@ Creates a **ColorPicker** instance based on the pixel map. This API uses an asyn **Example** ```js -import image from "@ohos.multimedia.image" +import image from "@ohos.multimedia.image"; + const color = new ArrayBuffer(96); -let opts = { editable: true, pixelFormat: 3, size: { height: 4, width: 6 } }; -image.createPixelMap(color, opts, (pixelMap) => { - effectKit.createColorPicker(pixelMap, (error, colorPicker) => { - if(error) { - console.log('Failed to create color picker.'); - } else { - console.log('Succeeded in creating color picker.'); - } - }) +let bufferArr = new Uint8Array(color); +let opts = { editable: true, pixelFormat: 3, size: { height: 4, width: 6 } } +image.createPixelMap(color, opts).then((pixelMap) => { + effectKit.createColorPicker(pixelMap, (error, colorPicker) => { + if (error) { + console.log('Failed to create color picker.'); + } else { + console.log('Succeeded in creating color picker.'); + } + }) }) ``` @@ -150,7 +154,7 @@ Obtains the main color of the image and writes the result to a **[Color](#color) ```js colorPicker.getMainColor().then(color => { - console.log('Succeeded in getting main color.') + console.log('Succeeded in getting main color.'); console.info("color[ARGB]=" + color.alpha + "," + color.red + "," + color.green + "," + color.blue); }).catch(error => { console.log('Failed to get main color.'); @@ -205,17 +209,17 @@ Adds the blur effect to the filter linked list, and returns the head node of the **Example** ```js -import image from "@ohos.multimedia.image" +import image from "@ohos.multimedia.image"; + const color = new ArrayBuffer(96); let opts = { editable: true, pixelFormat: 3, size: { height: 4, width: 6 } }; -image.createPixelMap(color, opts) - .then((pixelMap) => { - let radius = 5; - let headFilter = effectKit.createEffect(pixelMap) - if (headFilter != null) { - headFilter.blur(radius) - } - }) +image.createPixelMap(color, opts).then((pixelMap) => { + let radius = 5; + let headFilter = effectKit.createEffect(pixelMap); + if (headFilter != null) { + headFilter.blur(radius); + } +}) ``` ### brightness @@ -241,17 +245,17 @@ Adds the brightness effect to the filter linked list, and returns the head node **Example** ```js -import image from "@ohos.multimedia.image" +import image from "@ohos.multimedia.image"; + const color = new ArrayBuffer(96); let opts = { editable: true, pixelFormat: 3, size: { height: 4, width: 6 } }; -image.createPixelMap(color, opts) - .then((pixelMap) => { - let bright = 0.5; - let headFilter = effectKit.createEffect(pixelMap) - if (headFilter != null) { - headFilter.brightness(bright) - } - }) +image.createPixelMap(color, opts).then((pixelMap) => { + let bright = 0.5; + let headFilter = effectKit.createEffect(pixelMap); + if (headFilter != null) { + headFilter.brightness(bright); + } +}) ``` ### grayscale @@ -271,16 +275,16 @@ Adds the grayscale effect to the filter linked list, and returns the head node o **Example** ```js -import image from "@ohos.multimedia.image" +import image from "@ohos.multimedia.image"; + const color = new ArrayBuffer(96); let opts = { editable: true, pixelFormat: 3, size: { height: 4, width: 6 } }; -image.createPixelMap(color, opts) - .then((pixelMap) => { - let headFilter = effectKit.createEffect(pixelMap) - if (headFilter != null) { - headFilter.grayscale() - } - }) +image.createPixelMap(color, opts).then((pixelMap) => { + let headFilter = effectKit.createEffect(pixelMap); + if (headFilter != null) { + headFilter.grayscale(); + } +}) ``` ### getPixelMap @@ -300,11 +304,11 @@ Obtains **image.PixelMap** of the source image to which the filter linked list i **Example** ```js -import image from "@ohos.multimedia.image" +import image from "@ohos.multimedia.image"; + const color = new ArrayBuffer(96); let opts = { editable: true, pixelFormat: 3, size: { height: 4, width: 6 } }; -image.createPixelMap(color, opts) - .then((pixelMap) => { - let pixel = effectKit.createEffect(pixelMap).grayscale().getPixelMap() - }) +image.createPixelMap(color, opts).then((pixelMap) => { + let pixel = effectKit.createEffect(pixelMap).grayscale().getPixelMap(); +}) ``` diff --git a/en/application-dev/reference/apis/js-apis-extensionrunninginfo.md b/en/application-dev/reference/apis/js-apis-extensionrunninginfo.md index 66b794234a41c9e57977946adbf02a9f35182b60..841f7755273489a570865b41c63c5103c3af0c9a 100644 --- a/en/application-dev/reference/apis/js-apis-extensionrunninginfo.md +++ b/en/application-dev/reference/apis/js-apis-extensionrunninginfo.md @@ -12,9 +12,9 @@ The **ExtensionRunningInfo** module provides running information and states for The Extension ability running information is obtained through an **abilityManager** instance. ```js -import abilitymanager from '@ohos.application.abilityManager'; +import abilityManager from '@ohos.application.abilityManager'; let upperLimit=1 -abilitymanager.getExtensionRunningInfos(upperLimit, (err,data) => { +abilityManager.getExtensionRunningInfos(upperLimit, (err,data) => { console.log("getExtensionRunningInfos err: " + err + " data: " + JSON.stringify(data)); }); ``` diff --git a/en/application-dev/reference/apis/js-apis-image.md b/en/application-dev/reference/apis/js-apis-image.md index 20776d6cc80e501da6ae7accd069ebb502894f86..bcbf619bf7173a405eee37f5dac86c5e87a023e9 100644 --- a/en/application-dev/reference/apis/js-apis-image.md +++ b/en/application-dev/reference/apis/js-apis-image.md @@ -170,7 +170,12 @@ Reads image pixel map data in an area. This API uses a promise to return the dat **Example** ```js -const area = new ArrayBuffer(400); +const area = { + pixels: new ArrayBuffer(8), + offset: 0, + stride: 8, + region: { size: { height: 1, width: 2 }, x: 0, y: 0 } +} pixelmap.readPixels(area).then(() => { console.log('Succeeded in reading the image data in the area.'); // Called if the condition is met. }).catch(error => { diff --git a/en/application-dev/reference/apis/js-apis-media.md b/en/application-dev/reference/apis/js-apis-media.md index ef8c4857425a7dbd611eb3cd0a9ac7bcb2be6075..96b190f1f7f9166c68ef1fda64bb9a98bf6b269d 100644 --- a/en/application-dev/reference/apis/js-apis-media.md +++ b/en/application-dev/reference/apis/js-apis-media.md @@ -277,10 +277,10 @@ For details about the audio playback demo, see [Audio Playback Development](../. | Name | Type | Readable| Writable| Description | | ------------------------------- | ----------------------------------- | ---- | ---- | ------------------------------------------------------------ | -| src | string | Yes | Yes | Audio file URI. The mainstream audio formats (M4A, AAC, MPEG-3, OGG, and WAV) are supported.
**Examples of supported URI schemes**:
1. FD: fd://xx
![](figures/en-us_image_url.png)
2. HTTP: http://xx
3. HTTPS: https://xx
4. HLS: http://xx or https://xx
**Required permissions**: ohos.permission.READ_MEDIA and ohos.permission.INTERNET (The latter is required only when online resources are used.)| -| fdSrc9+ | [AVFileDescriptor](#interruptmode9) | Yes | Yes | Description of the audio file. This attribute is required when audio resources of an application are continuously stored in a file.
**Example:**
Assume that a music file that stores continuous music resources consists of the following:
Music 1 (address offset: 0, byte length: 100)
Music 2 (address offset: 101; byte length: 50)
Music 3 (address offset: 151, byte length: 150)
1. To play music 1: AVFileDescriptor {fd = resource handle; offset = 0; length = 100; }
2. To play music 2: AVFileDescriptor {fd = resource handle; offset = 101; length = 50; }
3. To play music 3: AVFileDescriptor {fd = resource handle; offset = 151; length = 150; }
If the file is an independent music file, use **src=fd://xx**.

**Required permissions**: ohos.permission.READ_MEDIA| +| src | string | Yes | Yes | Audio file URI. The mainstream audio formats (M4A, AAC, MPEG-3, OGG, and WAV) are supported.
**Examples of supported URI schemes**:
1. FD: fd://xx
![](figures/en-us_image_url.png)
2. HTTP: http://xx
3. HTTPS: https://xx
4. HLS: http://xx or https://xx
**Required permissions**: ohos.permission.INTERNET| +| fdSrc9+ | [AVFileDescriptor](#avfiledescriptor9) | Yes | Yes | Description of the audio file. This attribute is required when audio resources of an application are continuously stored in a file.
**Example:**
Assume that a music file that stores continuous music resources consists of the following:
Music 1 (address offset: 0, byte length: 100)
Music 2 (address offset: 101; byte length: 50)
Music 3 (address offset: 151, byte length: 150)
1. To play music 1: AVFileDescriptor {fd = resource handle; offset = 0; length = 100; }
2. To play music 2: AVFileDescriptor {fd = resource handle; offset = 101; length = 50; }
3. To play music 3: AVFileDescriptor {fd = resource handle; offset = 151; length = 150; }
If the file is an independent music file, use **src=fd://xx**.
| | loop | boolean | Yes | Yes | Whether to loop audio playback. The value **true** means to loop audio playback, and **false** means the opposite. | -| audioInterruptMode9+ | [InterruptMode](#interruptmode9) | Yes | Yes | Audio interruption mode. | +| audioInterruptMode9+ | [audio.InterruptMode](js-apis-audio.md#interruptmode9) | Yes | Yes | Audio interruption mode. | | currentTime | number | Yes | No | Current audio playback position, in ms. | | duration | number | Yes | No | Audio duration, in ms. | | state | [AudioState](#audiostate) | Yes | No | Audio playback state. This state cannot be used as the condition for triggering the call of **play()**, **pause()**, or **stop()**.| @@ -442,7 +442,7 @@ function printfDescription(obj) { } } -audioPlayer.getTrackDescription((error, arrlist) => { +audioPlayer.getTrackDescription((error, ) => { if (arrlist != null) { for (let i = 0; i < arrlist.length; i++) { printfDescription(arrlist[i]); @@ -477,7 +477,7 @@ function printfDescription(obj) { console.info('audio value is ' + property); } } - +let arrayDescription = null audioPlayer.getTrackDescription().then((arrlist) => { if (arrlist != null) { arrayDescription = arrlist; @@ -535,6 +535,8 @@ Subscribes to the audio playback events. **Example** ```js +import fileio from '@ohos.fileio' + let audioPlayer = media.createAudioPlayer(); // Create an AudioPlayer instance. audioPlayer.on('dataLoad', () => { // Set the 'dataLoad' event callback, which is triggered when the src attribute is set successfully. console.info('audio set source success'); @@ -574,11 +576,11 @@ audioPlayer.on('error', (error) => { // Set the 'error' event callback }); // Set the FD (local playback) of the video file selected by the user. -let fdPath = 'fd://' +let fdPath = 'fd://'; // The stream in the path can be pushed to the device by running the "hdc file send D:\xxx\01.mp3 /data/accounts/account_0/appdata" command. let path = '/data/accounts/account_0/appdata/ohos.xxx.xxx.xxx/01.mp3'; -fileIO.open(path).then(fdNumber) => { - fdPath = fdPath + '' + fdNumber; +fileio.open(path).then((fdValue) => { + fdPath = fdPath + '' + fdValue; console.info('open fd success fd is' + fdPath); }, (err) => { console.info('open fd failed err is' + err); @@ -646,21 +648,19 @@ Enumerates the audio playback states. You can obtain the state through the **sta **System capability**: SystemCapability.Multimedia.Media.AudioPlayer -| Name | Type | Description | -| ------------------ | ------ | ---------------------------------------------- | -| idle | string | No audio playback is in progress. The audio player is in this state after the **'dataload'** or **'reset'** event is triggered.| -| playing | string | Audio playback is in progress. The audio player is in this state after the **'play'** event is triggered. | -| paused | string | Audio playback is paused. The audio player is in this state after the **'pause'** event is triggered. | -| stopped | string | Audio playback is stopped. The audio player is in this state after the **'stop'** event is triggered. | -| error8+ | string | Audio playback is in the error state. | +| Name | Type | Description | +| ------- | ------ | ---------------------------------------------- | +| idle | string | No audio playback is in progress. The audio player is in this state after the **'dataload'** or **'reset'** event is triggered.| +| playing | string | Audio playback is in progress. The audio player is in this state after the **'play'** event is triggered. | +| paused | string | Audio playback is paused. The audio player is in this state after the **'pause'** event is triggered. | +| stopped | string | Audio playback is stopped. The audio player is in this state after the **'stop'** event is triggered. | +| error | string | Audio playback is in the error state. | ## AVFileDescriptor9+ Describes audio and video file resources. It is used to specify a particular resource for playback based on its offset and length within a file. -**System capability**: SystemCapability.Multimedia.Media.AudioPlayer - -**Parameters** +**System capability**: SystemCapability.Multimedia.Media.Core | Name| Type | Mandatory| Description | | ------ | ------ | ---- | ------------------------------------------------------------ | @@ -668,17 +668,6 @@ Describes audio and video file resources. It is used to specify a particular res | offset | number | Yes | Resource offset, which needs to be entered based on the preset resource information. An invalid value causes a failure to parse audio and video resources.| | length | number | Yes | Resource length, which needs to be entered based on the preset resource information. An invalid value causes a failure to parse audio and video resources.| -## InterruptMode9+ - -Describes the audio interruption mode. - -**System capability**: SystemCapability.Multimedia.Media.AudioPlayer - -| Name | Default Value| Description | -| ---------------------------- | ------ | ---------- | -| SHARE_MODE | 0 | Shared mode.| -| INDEPENDENT_MODE| 1 | Independent mode. | - ## VideoPlayer8+ Provides APIs to manage and play video. Before calling an API of **VideoPlayer**, you must call [createVideoPlayer()](#mediacreatevideoplayer8) to create a [VideoPlayer](#videoplayer8) instance. @@ -691,11 +680,11 @@ For details about the video playback demo, see [Video Playback Development](../. | Name | Type | Readable| Writable| Description | | ------------------------ | ---------------------------------- | ---- | ---- | ------------------------------------------------------------ | -| url8+ | string | Yes | Yes | Video media URL. The mainstream video formats (MPEG-4, MPEG-TS, WebM, and MKV) are supported.
**Example of supported URIs**:
1. FD: fd://xx
![](figures/en-us_image_url.png)
2. HTTP: http://xx
3. HTTPS: https://xx
4. HLS: http://xx or https://xx
**Required permissions**: ohos.permission.READ_MEDIA and ohos.permission.INTERNET (The latter is required only when online resources are used.)| -| fdSrc9+ | [AVFileDescriptor](#interruptmode9) | Yes| Yes| Description of a video file. This attribute is required when video resources of an application are continuously stored in a file.
**Example:**
Assume that a music file that stores continuous music resources consists of the following:
Video 1 (address offset: 0, byte length: 100)
Video 2 (address offset: 101; byte length: 50)
Video 3 (address offset: 151, byte length: 150)
1. To play video 1: AVFileDescriptor {fd = resource handle; offset = 0; length = 100; }
2. To play video 2: AVFileDescriptor {fd = resource handle; offset = 101; length = 50; }
3. To play video 3: AVFileDescriptor {fd = resource handle; offset = 151; length = 150; }
To play an independent video file, use **src=fd://xx**.
**Note**:
**Required permissions**: ohos.permission.READ_MEDIA| +| url8+ | string | Yes | Yes | Video media URL. The mainstream video formats (MPEG-4, MPEG-TS, WebM, and MKV) are supported.
**Example of supported URIs**:
1. FD: fd://xx
![](figures/en-us_image_url.png)
2. HTTP: http://xx
3. HTTPS: https://xx
4. HLS: http://xx or https://xx
**Required permissions**: ohos.permission.INTERNET| +| fdSrc9+ | [AVFileDescriptor](#avfiledescriptor9) | Yes| Yes| Description of a video file. This attribute is required when video resources of an application are continuously stored in a file.
**Example:**
Assume that a music file that stores continuous music resources consists of the following:
Video 1 (address offset: 0, byte length: 100)
Video 2 (address offset: 101; byte length: 50)
Video 3 (address offset: 151, byte length: 150)
1. To play video 1: AVFileDescriptor {fd = resource handle; offset = 0; length = 100; }
2. To play video 2: AVFileDescriptor {fd = resource handle; offset = 101; length = 50; }
3. To play video 3: AVFileDescriptor {fd = resource handle; offset = 151; length = 150; }
To play an independent video file, use **src=fd://xx**.
| | loop8+ | boolean | Yes | Yes | Whether to loop video playback. The value **true** means to loop video playback, and **false** means the opposite. | | videoScaleType9+ | [VideoScaleType](#videoscaletype9) | Yes | Yes | Video scale type. | -| audioInterruptMode9+ | [InterruptMode](#interruptmode9) | Yes | Yes | Audio interruption mode. | +| audioInterruptMode9+ | [audio.InterruptMode](js-apis-audio.md#interruptmode9) | Yes | Yes | Audio interruption mode. | | currentTime8+ | number | Yes | No | Current video playback position, in ms. | | duration8+ | number | Yes | No | Video duration, in ms. The value **-1** indicates the live mode. | | state8+ | [VideoPlayState](#videoplaystate8) | Yes | No | Video playback state. | @@ -722,6 +711,7 @@ Sets **SurfaceId**. This API uses an asynchronous callback to return the result. **Example** ```js +let surfaceId = null; videoPlayer.setDisplaySurface(surfaceId, (err) => { if (err == null) { console.info('setDisplaySurface success!'); @@ -756,6 +746,7 @@ Sets **SurfaceId**. This API uses a promise to return the result. **Example** ```js +let surfaceId = null; videoPlayer.setDisplaySurface(surfaceId).then(() => { console.info('setDisplaySurface success'); }).catch((error) => { @@ -1062,8 +1053,7 @@ Seeks to the specified playback position. This API uses an asynchronous callback ```js import media from '@ohos.multimedia.media' let seekTime = 5000; -let seekMode = media.SeekMode.SEEK_NEXT_SYNC; -videoPlayer.seek(seekTime, seekMode, (err, result) => { +videoPlayer.seek(seekTime, media.SeekMode.SEEK_NEXT_SYNC, (err, result) => { if (err == null) { console.info('seek success!'); } else { @@ -1096,6 +1086,7 @@ Seeks to the specified playback position. If **mode** is not specified, the next **Example** ```js +import media from '@ohos.multimedia.media' let seekTime = 5000; videoPlayer.seek(seekTime).then((seekDoneTime) => { // seekDoneTime indicates the position after the seek operation is complete. console.info('seek success'); @@ -1103,7 +1094,7 @@ videoPlayer.seek(seekTime).then((seekDoneTime) => { // seekDoneTime indicates th console.info(`video catchCallback, error:${error}`); }); -videoPlayer.seek(seekTime, seekMode).then((seekDoneTime) => { +videoPlayer.seek(seekTime, media.SeekMode.SEEK_NEXT_SYNC).then((seekDoneTime) => { console.info('seek success'); }).catch((error) => { console.info(`video catchCallback, error:${error}`); @@ -1162,7 +1153,7 @@ Sets the volume. This API uses a promise to return the result. ```js let vol = 0.5; -videoPlayer.setVolume(vol).then() => { +videoPlayer.setVolume(vol).then(() => { console.info('setVolume success'); }).catch((error) => { console.info(`video catchCallback, error:${error}`); @@ -1212,7 +1203,7 @@ Releases the video playback resource. This API uses a promise to return the resu **Example** ```js -videoPlayer.release().then() => { +videoPlayer.release().then(() => { console.info('release success'); }).catch((error) => { console.info(`video catchCallback, error:${error}`); @@ -1245,7 +1236,7 @@ function printfDescription(obj) { } videoPlayer.getTrackDescription((error, arrlist) => { - if (arrlist) != null) { + if ((arrlist) != null) { for (let i = 0; i < arrlist.length; i++) { printfDescription(arrlist[i]); } @@ -1351,7 +1342,7 @@ Sets the video playback speed. This API uses a promise to return the result. import media from '@ohos.multimedia.media' let speed = media.PlaybackSpeed.SPEED_FORWARD_2_00_X; -videoPlayer.setSpeed(speed).then() => { +videoPlayer.setSpeed(speed).then(() => { console.info('setSpeed success'); }).catch((error) => { console.info(`video catchCallback, error:${error}`); @@ -1410,7 +1401,7 @@ Selects a bit rate from available ones, which can be obtained by calling [availa ```js let bitrate = 1024000; -videoPlayer.selectBitrate(bitrate).then() => { +videoPlayer.selectBitrate(bitrate).then(() => { console.info('selectBitrate success'); }).catch((error) => { console.info(`video catchCallback, error:${error}`); @@ -1613,30 +1604,24 @@ Enumerates the video scale modes. ## MediaDescription8+ -### [key : string] : Object - Defines media information in key-value mode. **System capability**: SystemCapability.Multimedia.Media.Core -| Name | Type | Description | -| ----- | ------ | ------------------------------------------------------------ | -| key | string | Key of the media information. For details about the keys, see [MediaDescriptionKey](#mediadescriptionkey8).| -| value | any | Value of the key. For details about the values, see [MediaDescriptionKey](#mediadescriptionkey8).| - **Example** ```js +import media from '@ohos.multimedia.media' function printfItemDescription(obj, key) { let property = obj[key]; - console.info('audio key is ' + key); - console.info('audio value is ' + property); + console.info('audio key is ' + key); // Specify a key. For details about the keys, see [MediaDescriptionKey]. + console.info('audio value is ' + property); // Obtain the value of the key. The value can be any type. For details about the types, see [MediaDescriptionKey]. } - +let audioPlayer = media.createAudioPlayer(); audioPlayer.getTrackDescription((error, arrlist) => { if (arrlist != null) { for (let i = 0; i < arrlist.length; i++) { - printfItemDescription(arrlist[i], MD_KEY_TRACK_TYPE); // Print the MD_KEY_TRACK_TYPE value of each track. + printfItemDescription(arrlist[i], media.MediaDescriptionKey.MD_KEY_TRACK_TYPE); // Print the MD_KEY_TRACK_TYPE value of each track. } } else { console.log(`audio getTrackDescription fail, error:${error}`); @@ -1808,7 +1793,7 @@ Subscribes to the audio recording events. **Example** ```js -let audiorecorder = media.createAudioRecorder(); // Create an AudioRecorder instance. +let audioRecorder = media.createAudioRecorder(); // Create an AudioRecorder instance. let audioRecorderConfig = { audioEncoder : media.AudioEncoder.AAC_LC, , audioEncodeBitRate : 22050, @@ -1864,10 +1849,19 @@ Subscribes to audio recording error events. After an error event is reported, yo **Example** ```js +let audioRecorderConfig = { + audioEncoder : media.AudioEncoder.AAC_LC, , + audioEncodeBitRate : 22050, + audioSampleRate : 22050, + numberOfChannels : 2, + format : media.AudioOutputFormat.AAC_ADTS, + uri : 'fd://xx', // The file must be created by the caller and granted with proper permissions. + location : { latitude : 30, longitude : 130}, +} audioRecorder.on('error', (error) => { // Set the 'error' event callback. console.info(`audio error called, error: ${error}`); }); -audioRecorder.prepare(); // Do no set any parameter in prepare and trigger the 'error' event callback. +audioRecorder.prepare(audioRecorderConfig); // Do no set any parameter in prepare and trigger the 'error' event callback. ``` ## AudioRecorderConfig @@ -2058,18 +2052,17 @@ media.createVideoRecorder().then((recorder) => { if (recorder != null) { videoRecorder = recorder; console.info('createVideoRecorder success'); + videoRecorder.prepare(videoConfig).then(() => { + console.info('prepare success'); + }).catch((err) => { + console.info('prepare failed and catch error is ' + err.message); + }); } else { console.info('createVideoRecorder failed'); } }).catch((err) => { console.info('catch err error message is ' + err.message); }); - -videoRecorder.prepare(videoConfig).then(() => { - console.info('prepare success'); -}).catch((err) => { - console.info('prepare failed and catch error is ' + err.message); -}); ``` ### getInputSurface9+ @@ -2484,7 +2477,9 @@ Subscribes to video recording error events. After an error event is reported, yo ```js videoRecorder.on('error', (error) => { // Set the 'error' event callback. console.info(`audio error called, error: ${error}`); +} // This event is reported when an error occurs during the retrieval of videoRecordState. +}); ``` ## VideoRecordState9+ @@ -2515,7 +2510,7 @@ Describes the video recording parameters. | profile | [VideoRecorderProfile](#videorecorderprofile9) | Yes | Video recording profile. | | rotation | number | No | Rotation angle of the recorded video. | | location | [Location](#location) | No | Geographical location of the recorded video. | -| url | string | Yes | Video output URL. Supported: fd://xx (fd number)
![](figures/en-us_image_url.png)
**Required permissions**: ohos.permission.READ_MEDIA| +| url | string | Yes | Video output URL. Supported: fd://xx (fd number)
![](figures/en-us_image_url.png) | ## AudioSourceType9+ diff --git a/en/application-dev/reference/apis/js-apis-process.md b/en/application-dev/reference/apis/js-apis-process.md index 8420e6055aadb9d2e7d45567d25b5fee9c21b795..a05b509b3c5072c28129c1d58a6d2974a4d2a01b 100755 --- a/en/application-dev/reference/apis/js-apis-process.md +++ b/en/application-dev/reference/apis/js-apis-process.md @@ -64,8 +64,8 @@ This is a system API and cannot be called by third-party applications. **Example** ```js -var child = process.runCmd('ls'); -var result = child.wait(); +let child = process.runCmd('ls'); +let result = child.wait(); result.then(val=>{ console.log("result = " + val); }) @@ -91,8 +91,8 @@ This is a system API and cannot be called by third-party applications. **Example** ```js -var child = process.runCmd('ls'); -var result = child.wait(); +let child = process.runCmd('ls'); +let result = child.wait(); child.getOutput().then(val=>{ console.log("child.getOutput = " + val); }) @@ -118,8 +118,8 @@ This is a system API and cannot be called by third-party applications. **Example** ```js -var child = process.runCmd('madir test.text'); -var result = child.wait(); +let child = process.runCmd('madir test.text'); +let result = child.wait(); child.getErrorOutput().then(val=>{ console.log("child.getErrorOutput= " + val); }) @@ -139,7 +139,7 @@ This is a system API and cannot be called by third-party applications. **Example** ```js -var child = process.runCmd('sleep 5; ls'); +let child = process.runCmd('sleep 5; ls'); child.close(); ``` @@ -163,7 +163,7 @@ This is a system API and cannot be called by third-party applications. **Example** ```js -var child = process.runCmd('sleep 5; ls'); +let child = process.runCmd('sleep 5; ls'); child.kill(9); ``` @@ -185,7 +185,7 @@ Checks whether this process is isolated. **Example** ```js -var result = process.isIsolatedProcess(); +let result = process.isIsolatedProcess(); ``` @@ -212,7 +212,7 @@ Checks whether a UID belongs to this app. **Example** ```js -var result = process.isAppUid(688); +let result = process.isAppUid(688); ``` @@ -233,7 +233,7 @@ Checks whether this process is running in a 64-bit environment. **Example** ```js -var result = process.is64Bit(); +let result = process.is64Bit(); ``` @@ -260,7 +260,7 @@ Obtains the process UID based on the process name. **Example** ```js -var pres = process.getUidForName("tool") +let pres = process.getUidForName("tool") ``` @@ -287,8 +287,8 @@ Obtains the thread priority based on the specified TID. **Example** ```js -var tid = process.tid; -var pres = process.getThreadPriority(tid); +let tid = process.tid; +let pres = process.getThreadPriority(tid); ``` @@ -309,7 +309,7 @@ Obtains the duration, in milliseconds, from the time the system starts to the ti **Example** ```js -var realtime = process.getStartRealtime(); +let realtime = process.getStartRealtime(); ``` ## process.getPastCpuTime8+ @@ -329,7 +329,7 @@ Obtains the CPU time (in milliseconds) from the time the process starts to the c **Example** ```js -var result = process.getPastCpuTime() ; +let result = process.getPastCpuTime() ; ``` @@ -356,8 +356,8 @@ Obtains the system configuration. **Example** ```js -var _SC_ARG_MAX = 0 -var pres = process.getSystemConfig(_SC_ARG_MAX) +let _SC_ARG_MAX = 0 +let pres = process.getSystemConfig(_SC_ARG_MAX) ``` @@ -384,7 +384,7 @@ Obtains the value of an environment variable. **Example** ```js -var pres = process.getEnvironmentVar("PATH") +let pres = process.getEnvironmentVar("PATH") ``` @@ -422,8 +422,8 @@ This is a system API and cannot be called by third-party applications. **Example** ```js -var child = process.runCmd('ls', { maxBuffer : 2 }); -var result = child.wait(); +let child = process.runCmd('ls', { maxBuffer : 2 }); +let result = child.wait(); child.getOutput.then(val=>{ console.log("child.getOutput = " + val); }) @@ -505,7 +505,7 @@ This is a system API and cannot be called by third-party applications. process.on("data", (e)=>{ console.log("data callback"); }) -var result = process.off("data"); +let result = process.off("data"); ``` @@ -545,7 +545,7 @@ This is a system API and cannot be called by third-party applications. **Example** ```js -var path = process.cwd(); +let path = process.cwd(); ``` @@ -589,7 +589,7 @@ Obtains the running time of this process. **Example** ```js -var time = process.uptime(); +let time = process.uptime(); ``` @@ -617,6 +617,6 @@ Sends a signal to the specified process to terminate it. **Example** ```js -var pres = process.pid -var result = process.kill(28, pres) +let pres = process.pid +let result = process.kill(28, pres) ``` diff --git a/en/application-dev/reference/apis/js-apis-prompt.md b/en/application-dev/reference/apis/js-apis-prompt.md index 11ec375e987ab2312a93b5233bd4ecdd049bb79d..e88c899e36745869e6009616b1c8581c3fa37b49 100644 --- a/en/application-dev/reference/apis/js-apis-prompt.md +++ b/en/application-dev/reference/apis/js-apis-prompt.md @@ -43,7 +43,7 @@ Describes the options for showing the toast. | Name | Type | Mandatory | Description | | -------- | ---------------------------------------- | ---- | ---------------------------------------- | -| message | string\| [Resource](.../ui/ts-types.md#resource-type)9+| Yes | Text to display. | +| message | string\| [Resource](../../ui/ts-types.md#resource-type)9+| Yes | Text to display. | | duration | number | No | Duration that the toast will remain on the screen. The default value is 1500 ms. The value range is 1500 ms to 10000 ms. If a value less than 1500 ms is set, the default value is used. If the value greater than 10000 ms is set, the upper limit 10000 ms is used.| | bottom | string\| number | No | Distance between the toast border and the bottom of the screen. | @@ -140,8 +140,8 @@ Describes the options for showing the dialog box. | Name | Type | Mandatory | Description | | ------- | ---------------------------------------- | ---- | ---------------------------------------- | -| title | string\| [Resource](.../ui/ts-types.md#resource-type)9+| No | Title of the dialog box. | -| message | string\| [Resource](.../ui/ts-types.md#resource-type)9+| No | Text body. | +| title | string\| [Resource](../../ui/ts-types.md#resource-type)9+| No | Title of the dialog box. | +| message | string\| [Resource](../../ui/ts-types.md#resource-type)9+| No | Text body. | | buttons | Array | No | Array of buttons in the dialog box. The array structure is **{text:'button', color: '\#666666'}**. Up to three buttons are supported. The first button is of the **positiveButton** type, the second is of the **negativeButton** type, and the third is of the **neutralButton** type.| ## ShowDialogSuccessResponse @@ -246,7 +246,7 @@ Describes the options for showing the action menu. | Name | Type | Mandatory | Description | | ------- | ---------------------------------------- | ---- | ---------------------------------------- | -| title | string\| [Resource](.../ui/ts-types.md#resource-type)9+| No | Title of the text to display. | +| title | string\| [Resource](../../ui/ts-types.md#resource-type)9+| No | Title of the text to display. | | buttons | Array<[Button](#button)> | Yes | Array of menu item buttons. The array structure is **{text:'button', color: '\#666666'}**. Up to six buttons are supported. If there are more than six buttons, extra buttons will not be displayed.| ## ActionMenuSuccessResponse @@ -267,5 +267,5 @@ Describes the menu item button in the action menu. | Name | Type | Mandatory | Description | | ----- | ---------------------------------------- | ---- | ------- | -| text | string\| [Resource](.../ui/ts-types.md#resource-type)9+| Yes | Button text.| -| color | string\| [Resource](.../ui/ts-types.md#resource-type)9+| Yes | Text color of the button.| +| text | string\| [Resource](../../ui/ts-types.md#resource-type)9+| Yes | Button text.| +| color | string\| [Resource](../../ui/ts-types.md#resource-type)9+| Yes | Text color of the button.| diff --git a/en/application-dev/reference/apis/js-apis-uri.md b/en/application-dev/reference/apis/js-apis-uri.md index 60fd45f98209c718374e4a2633b074a531aa719c..faeb4f766d6c1417728f540fcab71551ee688abf 100644 --- a/en/application-dev/reference/apis/js-apis-uri.md +++ b/en/application-dev/reference/apis/js-apis-uri.md @@ -47,7 +47,7 @@ A constructor used to create a URI instance. **Example** ```js -var mm = 'http://username:password@host:8080/directory/file?foo=1&bar=2#fragment'; +let mm = 'http://username:password@host:8080/directory/file?foo=1&bar=2#fragment'; new uri.URI(mm); // Output 'http://username:password@host:8080/directory/file?foo=1&bar=2#fragment'; ``` ```js diff --git a/en/application-dev/reference/apis/js-apis-url.md b/en/application-dev/reference/apis/js-apis-url.md index 55694ec1cb024a25affa93feca40b2a73ef38234..679dc182e6c06d96248a084e313cc3d1baaea7f9 100755 --- a/en/application-dev/reference/apis/js-apis-url.md +++ b/en/application-dev/reference/apis/js-apis-url.md @@ -26,16 +26,16 @@ Creates a **URLSearchParams** instance. | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | -| init | string[][] \| Record<string, string> \| string \| URLSearchParams | No| Input parameter objects, which include the following:
- **string[][]**: two-dimensional string array
- **Record<string, string>**: list of objects
- **string**: string
- **URLSearchParams**: object| +| init | string[][] \| Record<string, string> \| string \| URLSearchParams | No| Input parameter objects, which include the following:
- **string[][]**: two-dimensional string array
- **Record<string, string>**: list of objects
- **string**: string
- **URLSearchParams**: object| **Example** ```js -var objectParams = new Url.URLSearchParams([ ['user1', 'abc1'], ['query2', 'first2'], ['query3', 'second3'] ]); -var objectParams1 = new Url.URLSearchParams({"fod" : '1' , "bard" : '2'}); -var objectParams2 = new Url.URLSearchParams('?fod=1&bard=2'); -var urlObject = new Url.URL('https://developer.mozilla.org/?fod=1&bard=2'); -var params = new Url.URLSearchParams(urlObject.search); +let objectParams = new Url.URLSearchParams([ ['user1', 'abc1'], ['query2', 'first2'], ['query3', 'second3'] ]); +let objectParams1 = new Url.URLSearchParams({"fod" : '1' , "bard" : '2'}); +let objectParams2 = new Url.URLSearchParams('?fod=1&bard=2'); +let urlObject = new Url.URL('https://developer.mozilla.org/?fod=1&bard=2'); +let params = new Url.URLSearchParams(urlObject.search); ``` @@ -133,7 +133,7 @@ Obtains an ES6 iterator. Each item of the iterator is a JavaScript array, and th **Example** ```js -var searchParamsObject = new Url.URLSearchParams("keyName1=valueName1&keyName2=valueName2"); +let searchParamsObject = new Url.URLSearchParams("keyName1=valueName1&keyName2=valueName2"); for (var pair of searchParamsObject .entries()) { // Show keyName/valueName pairs console.log(pair[0]+ ', '+ pair[1]); } @@ -197,9 +197,9 @@ Obtains the value of the first key-value pair based on the specified key. **Example** ```js -var paramsOject = new Url.URLSearchParams('name=Jonathan&age=18'); -var name = paramsOject.get("name"); // is the string "Jonathan" -var age = parseInt(paramsOject.get("age"), 10); // is the number 18 +let paramsOject = new Url.URLSearchParams('name=Jonathan&age=18'); +let name = paramsOject.get("name"); // is the string "Jonathan" +let age = parseInt(paramsOject.get("age"), 10); // is the number 18 ``` @@ -267,7 +267,7 @@ Sorts all key-value pairs contained in this object based on the Unicode code poi **Example** ```js -var searchParamsObject = new Url.URLSearchParams("c=3&a=9&b=4&d=2"); // Create a test URLSearchParams object +let searchParamsObject = new Url.URLSearchParams("c=3&a=9&b=4&d=2"); // Create a test URLSearchParams object searchParamsObject.sort(); // Sort the key/value pairs console.log(searchParamsObject.toString()); // Display the sorted query string // Output a=9&b=2&c=3&d=4 ``` @@ -290,7 +290,7 @@ Obtains an ES6 iterator that contains the keys of all the key-value pairs. **Example** ```js -var searchParamsObject = new Url.URLSearchParams("key1=value1&key2=value2"); // Create a URLSearchParamsObject object for testing +let searchParamsObject = new Url.URLSearchParams("key1=value1&key2=value2"); // Create a URLSearchParamsObject object for testing for (var key of searchParamsObject .keys()) { // Output key-value pairs console.log(key); } @@ -314,8 +314,8 @@ Obtains an ES6 iterator that contains the values of all the key-value pairs. **Example** ```js -var searchParams = new Url.URLSearchParams("key1=value1&key2=value2"); // Create a URLSearchParamsObject object for testing -for (var value of searchParams.values()) { +let searchParams = new Url.URLSearchParams("key1=value1&key2=value2"); // Create a URLSearchParamsObject object for testing +for (var value of searchParams.values()) { console.log(value); } ``` @@ -339,7 +339,7 @@ Obtains an ES6 iterator. Each item of the iterator is a JavaScript array, and th ```js const paramsObject = new Url.URLSearchParams('fod=bay&edg=bap'); -for (const [name, value] of paramsObject) { +for (const [name, value] of paramsObject) { console.log(name, value); } ``` @@ -409,11 +409,11 @@ Creates a URL. **Example** ```js -var mm = 'http://username:password@host:8080'; -var a = new Url.URL("/", mm); // Output 'http://username:password@host:8080/'; -var b = new Url.URL(mm); // Output 'http://username:password@host:8080/'; +let mm = 'http://username:password@host:8080'; +let a = new Url.URL("/", mm); // Output 'http://username:password@host:8080/'; +let b = new Url.URL(mm); // Output 'http://username:password@host:8080/'; new Url.URL('path/path1', b); // Output 'http://username:password@host:8080/path/path1'; -var c = new Url.URL('/path/path1', b); // Output 'http://username:password@host:8080/path/path1'; +let c = new Url.URL('/path/path1', b); // Output 'http://username:password@host:8080/path/path1'; new Url.URL('/path/path1', c); // Output 'http://username:password@host:8080/path/path1'; new Url.URL('/path/path1', a); // Output 'http://username:password@host:8080/path/path1'; new Url.URL('/path/path1', "https://www.exampleUrl/fr-FR/toto"); // Output https://www.exampleUrl/path/path1 diff --git a/en/application-dev/reference/apis/js-apis-util.md b/en/application-dev/reference/apis/js-apis-util.md index d1ffe6f45c4a792bdfda7ad81743a3fe1b8aac51..f9820758decfac7eaef530c4ff3c65aa81544150 100755 --- a/en/application-dev/reference/apis/js-apis-util.md +++ b/en/application-dev/reference/apis/js-apis-util.md @@ -24,19 +24,21 @@ Prints the input content in a formatted string. **System capability**: SystemCapability.Utils.Lang **Parameters** + | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | | format | string | Yes| Format of the string to print.| | ...args | Object[] | No| Data to format.| **Return value** + | Type| Description| | -------- | -------- | | string | String in the specified format.| **Example** ```js - var res = util.printf("%s", "hello world!"); + let res = util.printf("%s", "hello world!"); console.log(res); ``` @@ -50,19 +52,21 @@ Obtains detailed information about a system error code. **System capability**: SystemCapability.Utils.Lang **Parameters** + | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | | errno | number | Yes| Error code generated.| **Return value** + | Type| Description| | -------- | -------- | | string | Detailed information about the error code.| **Example** ```js - var errnum = 10; // 10 is a system error code. - var result = util.getErrorString(errnum); + let errnum = 10; // 10 is a system error code. + let result = util.getErrorString(errnum); console.log("result = " + result); ``` @@ -82,6 +86,7 @@ Calls back an asynchronous function. In the callback, the first parameter indica | original | Function | Yes| Asynchronous function.| **Return value** + | Type| Description| | -------- | -------- | | Function | Callback, in which the first parameter indicates the cause of the rejection (the value is **null** if the promise has been resolved) and the second parameter indicates the resolved value.| @@ -91,8 +96,8 @@ Calls back an asynchronous function. In the callback, the first parameter indica async function promiseFn() { return Promise.reject('value'); } - var err = "type err"; - var cb = util.callbackWrapper(promiseFn); + let err = "type err"; + let cb = util.callbackWrapper(promiseFn); cb((err, ret) => { console.log(err); console.log(ret); @@ -105,7 +110,6 @@ Calls back an asynchronous function. In the callback, the first parameter indica promiseWrapper(original: (err: Object, value: Object) => void): Object > **NOTE** -> > This API is deprecated since API version 9. You are advised to use **[util.promisify9+](#utilpromisify9)** instead. Processes an asynchronous function and returns a promise version. @@ -119,9 +123,10 @@ Processes an asynchronous function and returns a promise version. | original | Function | Yes| Asynchronous function.| **Return value** + | Type| Description| | -------- | -------- | -| Function | Function in the error-first style (that is, **(err, value) =>...** is called as the last parameter) and the promise version.| +| Function | Function in the error-first style (that is, **(err, value) =>...** is called as the last parameter) and the promise.| ## util.promisify9+ @@ -132,11 +137,13 @@ Processes an asynchronous function and returns a promise. **System capability**: SystemCapability.Utils.Lang **Parameters** + | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | | original | Function | Yes| Asynchronous function.| **Return value** + | Type| Description| | -------- | -------- | | Function | Function in the error-first style (that is, **(err, value) =>...** is called as the last parameter) and the promise.| @@ -156,6 +163,90 @@ Processes an asynchronous function and returns a promise. }) ``` +## util.randomUUID9+ + +randomUUID(entropyCache?: boolean): string + +Uses a secure random number generator to generate a random universally unique identifier (UUID) of RFC 4122 version 4. + +**System capability**: SystemCapability.Utils.Lang + +**Parameters** + +| Name| Type| Mandatory| Description| +| -------- | -------- | -------- | -------- | +| entropyCache | boolean | No| Whether a cached UUID can be used. The default value is **true**.| + +**Return value** + +| Type| Description| +| -------- | -------- | +| string | A string representing the UUID generated.| + +**Example** + ```js + let uuid = util.randomUUID(true); + console.log("RFC 4122 Version 4 UUID:" + uuid); + // Output: + // RFC 4122 Version 4 UUID:88368f2a-d5db-47d8-a05f-534fab0a0045 + ``` + +## util.randomBinaryUUID9+ + +randomBinaryUUID(entropyCache?: boolean): Uint8Array + +Uses a secure random number generator to generate a random binary UUID of RFC 4122 version 4. + +**System capability**: SystemCapability.Utils.Lang + +**Parameters** + +| Name| Type| Mandatory| Description| +| -------- | -------- | -------- | -------- | +| entropyCache | boolean | No| Whether a cached UUID can be used. The default value is **true**.| + +**Return value** + +| Type| Description| +| -------- | -------- | +| Uint8Array | A Uint8Array value representing the UUID generated.| + +**Example** + ```js + let uuid = util.randomBinaryUUID(true); + console.log(JSON.stringify(uuid)); + // Output: + // 138,188,43,243,62,254,70,119,130,20,235,222,199,164,140,150 + ``` + +## util.parseUUID9+ + +parseUUID(uuid: string): Uint8Array + +Parses a UUID from a string, as described in RFC 4122 version 4. + +**System capability**: SystemCapability.Utils.Lang + +**Parameters** + +| Name| Type| Mandatory| Description| +| -------- | -------- | -------- | -------- | +| uuid | string | Yes| A string representing the UUID.| + +**Return value** + +| Type| Description| +| -------- | -------- | +| Uint8Array | A Uint8Array value representing the UUID parsed. If the parsing fails, **SyntaxError** is thrown.| + +**Example** + ```js + let uuid = util.parseUUID("84bdf796-66cc-4655-9b89-d6218d100f9c"); + console.log(JSON.stringify(uuid)); + // Output: + // 132,189,247,150,102,204,70,85,155,137,214,33,141,16,15,156 + ``` + ## TextDecoder ### Attributes @@ -178,6 +269,7 @@ A constructor used to create a **TextDecoder** object. **System capability**: SystemCapability.Utils.Lang **Parameters** + | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | | encoding | string | No| Encoding format.| @@ -192,7 +284,7 @@ A constructor used to create a **TextDecoder** object. **Example** ```js - var textDecoder = new util.TextDecoder("utf-8",{ignoreBOM: true}); + let textDecoder = new util.TextDecoder("utf-8",{ignoreBOM: true}); ``` @@ -205,6 +297,7 @@ Decodes the input content. **System capability**: SystemCapability.Utils.Lang **Parameters** + | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | | input | Uint8Array | Yes| Uint8Array to decode.| @@ -217,14 +310,15 @@ Decodes the input content. | stream | boolean | No| Whether to allow data blocks in subsequent **decode()**. If data is processed in blocks, set this parameter to **true**. If this is the last data block to process or data is not divided into blocks, set this parameter to **false**. The default value is **false**.| **Return value** + | Type| Description| | -------- | -------- | | string | Data decoded.| **Example** ```js - var textDecoder = new util.TextDecoder("utf-8",{ignoreBOM: true}); - var result = new Uint8Array(6); + let textDecoder = new util.TextDecoder("utf-8",{ignoreBOM: true}); + let result = new Uint8Array(6); result[0] = 0xEF; result[1] = 0xBB; result[2] = 0xBF; @@ -232,7 +326,50 @@ Decodes the input content. result[4] = 0x62; result[5] = 0x63; console.log("input num:"); - var retStr = textDecoder.decode( result , {stream: false}); + let retStr = textDecoder.decode( result , {stream: false}); + console.log("retStr = " + retStr); + ``` + + +### decodeWithStream9+ + +decodeWithStream(input: Uint8Array, options?: { stream?: boolean }): string + +Decodes the input content. + +**System capability**: SystemCapability.Utils.Lang + +**Parameters** + +| Name| Type| Mandatory| Description| +| -------- | -------- | -------- | -------- | +| input | Uint8Array | Yes| Uint8Array to decode.| +| options | Object | No| Options related to decoding.| + + **Table 2** options + +| Name| Type| Mandatory| Description| +| -------- | -------- | -------- | -------- | +| stream | boolean | No| Whether to allow data blocks in subsequent **decodeWithStream()**. If data is processed in blocks, set this parameter to **true**. If this is the last data block to process or data is not divided into blocks, set this parameter to **false**. The default value is **false**.| + +**Return value** + +| Type| Description| +| -------- | -------- | +| string | Data decoded.| + +**Example** + ```js + let textDecoder = new util.TextDecoder("utf-8",{ignoreBOM: true}); + let result = new Uint8Array(6); + result[0] = 0xEF; + result[1] = 0xBB; + result[2] = 0xBF; + result[3] = 0x61; + result[4] = 0x62; + result[5] = 0x63; + console.log("input num:"); + let retStr = textDecoder.decodeWithStream( result , {stream: false}); console.log("retStr = " + retStr); ``` @@ -258,7 +395,7 @@ A constructor used to create a **TextEncoder** object. **Example** ```js - var textEncoder = new util.TextEncoder(); + let textEncoder = new util.TextEncoder(); ``` @@ -271,20 +408,22 @@ Encodes the input content. **System capability**: SystemCapability.Utils.Lang **Parameters** + | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | | input | string | Yes| String to encode.| **Return value** + | Type| Description| | -------- | -------- | | Uint8Array | Encoded text.| **Example** ```js - var textEncoder = new util.TextEncoder(); - var buffer = new ArrayBuffer(20); - var result = new Uint8Array(buffer); + let textEncoder = new util.TextEncoder(); + let buffer = new ArrayBuffer(20); + let result = new Uint8Array(buffer); result = textEncoder.encode("\uD800¥¥"); ``` @@ -298,22 +437,24 @@ Stores the UTF-8 encoded text. **System capability**: SystemCapability.Utils.Lang **Parameters** + | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | | input | string | Yes| String to encode.| | dest | Uint8Array | Yes| **Uint8Array** instance used to store the UTF-8 encoded text.| **Return value** + | Type| Description| | -------- | -------- | | Uint8Array | Encoded text.| **Example** ```js - var that = new util.TextEncoder() - var buffer = new ArrayBuffer(4) - var dest = new Uint8Array(buffer) - var result = new Object() + let that = new util.TextEncoder() + let buffer = new ArrayBuffer(4) + let dest = new Uint8Array(buffer) + let result = new Object() result = that.encodeInto('abcd', dest) ``` @@ -329,6 +470,7 @@ A constructor used to create a **RationalNumber** object. **System capability**: SystemCapability.Utils.Lang **Parameters** + | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | | numerator | number | Yes| Numerator, which is an integer.| @@ -336,7 +478,7 @@ A constructor used to create a **RationalNumber** object. **Example** ```js - var rationalNumber = new util.RationalNumber(1,2); + let rationalNumber = new util.RationalNumber(1,2); ``` @@ -349,19 +491,21 @@ Creates a **RationalNumber** object based on the given string. **System capability**: SystemCapability.Utils.Lang **Parameters** + | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | | rationalString | string | Yes| String used to create the **RationalNumber** object.| **Return value** + | Type| Description| | -------- | -------- | | object | **RationalNumber** object created.| **Example** ```js - var rationalNumber = new util.RationalNumber(1,2); - var rational = util.RationalNumber.createRationalFromString("3/4"); + let rationalNumber = new util.RationalNumber(1,2); + let rational = util.RationalNumber.createRationalFromString("3/4"); ``` @@ -374,20 +518,22 @@ Compares this **RationalNumber** object with a given object. **System capability**: SystemCapability.Utils.Lang **Parameters** + | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | | another | RationalNumber | Yes| Object used to compare with this **RationalNumber** object.| **Return value** + | Type| Description| | -------- | -------- | | number | Returns **0** if the two objects are equal; returns **1** if the given object is less than this object; return **-1** if the given object is greater than this object.| **Example** ```js - var rationalNumber = new util.RationalNumber(1,2); - var rational = util.RationalNumber.createRationalFromString("3/4"); - var result = rationalNumber.compareTo(rational); + let rationalNumber = new util.RationalNumber(1,2); + let rational = util.RationalNumber.createRationalFromString("3/4"); + let result = rationalNumber.compareTo(rational); ``` @@ -400,14 +546,15 @@ Obtains the value of this **RationalNumber** object as an integer or a floating- **System capability**: SystemCapability.Utils.Lang **Return value** + | Type| Description| | -------- | -------- | | number | An integer or a floating-point number.| **Example** ```js - var rationalNumber = new util.RationalNumber(1,2); - var result = rationalNumber.valueOf(); + let rationalNumber = new util.RationalNumber(1,2); + let result = rationalNumber.valueOf(); ``` @@ -420,20 +567,22 @@ Checks whether this **RationalNumber** object equals the given object. **System capability**: SystemCapability.Utils.Lang **Parameters** + | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | | object | Object | Yes| Object used to compare with this **RationalNumber** object.| **Return value** + | Type| Description| | -------- | -------- | | boolean | Returns **true** if the two objects are equal; returns **false** otherwise.| **Example** ```js - var rationalNumber = new util.RationalNumber(1,2); - var rational = util.RationalNumber.createRationalFromString("3/4"); - var result = rationalNumber.equals(rational); + let rationalNumber = new util.RationalNumber(1,2); + let rational = util.RationalNumber.createRationalFromString("3/4"); + let result = rationalNumber.equals(rational); ``` @@ -446,20 +595,22 @@ Obtains the greatest common divisor of two specified integers. **System capability**: SystemCapability.Utils.Lang **Parameters** + | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | | number1 | number | Yes| The first integer used to get the greatest common divisor.| | number2 | number | Yes| The second integer used to get the greatest common divisor.| **Return value** + | Type| Description| | -------- | -------- | | number | Greatest common divisor obtained.| **Example** ```js - var rationalNumber = new util.RationalNumber(1,2); - var result = util.RationalNumber.getCommonDivisor(4,6); + let rationalNumber = new util.RationalNumber(1,2); + let result = util.RationalNumber.getCommonDivisor(4,6); ``` @@ -479,8 +630,8 @@ Obtains the numerator of this **RationalNumber** object. **Example** ```js - var rationalNumber = new util.RationalNumber(1,2); - var result = rationalNumber.getNumerator(); + let rationalNumber = new util.RationalNumber(1,2); + let result = rationalNumber.getNumerator(); ``` @@ -493,14 +644,15 @@ Obtains the denominator of this **RationalNumber** object. **System capability**: SystemCapability.Utils.Lang **Return value** + | Type| Description| | -------- | -------- | | number | Denominator of this **RationalNumber** object.| **Example** ```js - var rationalNumber = new util.RationalNumber(1,2); - var result = rationalNumber.getDenominator(); + let rationalNumber = new util.RationalNumber(1,2); + let result = rationalNumber.getDenominator(); ``` @@ -513,14 +665,15 @@ Checks whether this **RationalNumber** object is **0**. **System capability**: SystemCapability.Utils.Lang **Return value** + | Type| Description| | -------- | -------- | | boolean | Returns **true** if the value of this **RationalNumber** object is **0**; returns **false** otherwise.| **Example** ```js - var rationalNumber = new util.RationalNumber(1,2); - var result = rationalNumber.isZero(); + let rationalNumber = new util.RationalNumber(1,2); + let result = rationalNumber.isZero(); ``` @@ -533,14 +686,15 @@ Checks whether this **RationalNumber** object is a Not a Number (NaN). **System capability**: SystemCapability.Utils.Lang **Return value** + | Type| Description| | -------- | -------- | | boolean | Returns **true** if this **RationalNumber** object is a NaN (the denominator and numerator are both **0**); returns **false** otherwise.| **Example** ```js - var rationalNumber = new util.RationalNumber(1,2); - var result = rationalNumber.isNaN(); + let rationalNumber = new util.RationalNumber(1,2); + let result = rationalNumber.isNaN(); ``` @@ -553,14 +707,15 @@ Checks whether this **RationalNumber** object represents a finite value. **System capability**: SystemCapability.Utils.Lang **Return value** + | Type| Description| | -------- | -------- | | boolean | Returns **true** if this **RationalNumber** object represents a finite value (the denominator is not **0**); returns **false** otherwise.| **Example** ```js - var rationalNumber = new util.RationalNumber(1,2); - var result = rationalNumber.isFinite(); + let rationalNumber = new util.RationalNumber(1,2); + let result = rationalNumber.isFinite(); ``` @@ -573,14 +728,15 @@ Obtains the string representation of this **RationalNumber** object. **System capability**: SystemCapability.Utils.Lang **Return value** + | Type| Description| | -------- | -------- | | string | Returns **NaN** if the numerator and denominator of this object are both **0**; returns a string in Numerator/Denominator format otherwise, for example, **3/5**.| **Example** ```js - var rationalNumber = new util.RationalNumber(1,2); - var result = rationalNumber.toString(); + let rationalNumber = new util.RationalNumber(1,2); + let result = rationalNumber.toString(); ``` ## LruBuffer8+ @@ -595,10 +751,10 @@ Obtains the string representation of this **RationalNumber** object. **Example** ```js - var pro = new util.LruBuffer(); + let pro = new util.LruBuffer(); pro.put(2,10); pro.put(1,8); - var result = pro.length; + let result = pro.length; ``` @@ -611,13 +767,14 @@ A constructor used to create an **LruBuffer** instance. The default capacity of **System capability**: SystemCapability.Utils.Lang **Parameters** + | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | | capacity | number | No| Capacity of the **LruBuffer** to create.| **Example** ```js - var lrubuffer= new util.LruBuffer(); + let lrubuffer= new util.LruBuffer(); ``` @@ -630,14 +787,15 @@ Changes the **LruBuffer** capacity. If the new capacity is less than or equal to **System capability**: SystemCapability.Utils.Lang **Parameters** + | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | | newCapacity | number | Yes| New capacity of the **LruBuffer**.| **Example** ```js - var pro = new util.LruBuffer(); - var result = pro.updateCapacity(100); + let pro = new util.LruBuffer(); + let result = pro.updateCapacity(100); ``` @@ -650,17 +808,18 @@ Obtains the string representation of this **LruBuffer** object. **System capability**: SystemCapability.Utils.Lang **Return value** + | Type| Description| | -------- | -------- | | string | String representation of this **LruBuffer** object.| **Example** ```js - var pro = new util.LruBuffer(); + let pro = new util.LruBuffer(); pro.put(2,10); pro.get(2); pro.remove(20); - var result = pro.toString(); + let result = pro.toString(); ``` @@ -673,14 +832,15 @@ Obtains the capacity of this buffer. **System capability**: SystemCapability.Utils.Lang **Return value** + | Type| Description| | -------- | -------- | | number | Capacity of this buffer.| **Example** ```js - var pro = new util.LruBuffer(); - var result = pro.getCapacity(); + let pro = new util.LruBuffer(); + let result = pro.getCapacity(); ``` @@ -694,9 +854,9 @@ Clears key-value pairs from this buffer. The **afterRemoval()** method will be c **Example** ```js - var pro = new util.LruBuffer(); + let pro = new util.LruBuffer(); pro.put(2,10); - var result = pro.length; + let result = pro.length; pro.clear(); ``` @@ -710,15 +870,16 @@ Obtains the number of return values for **createDefault()**. **System capability**: SystemCapability.Utils.Lang **Return value** + | Type| Description| | -------- | -------- | | number | Number of return values for **createDefault()**.| **Example** ```js - var pro = new util.LruBuffer(); + let pro = new util.LruBuffer(); pro.put(1,8); - var result = pro.getCreateCount(); + let result = pro.getCreateCount(); ``` @@ -731,16 +892,17 @@ Obtains the number of times that the queried values are mismatched. **System capability**: SystemCapability.Utils.Lang **Return value** + | Type| Description| | -------- | -------- | | number | Number of times that the queried values are mismatched.| **Example** ```js - var pro = new util.LruBuffer(); + let pro = new util.LruBuffer(); pro.put(2,10); pro.get(2); - var result = pro.getMissCount(); + let result = pro.getMissCount(); ``` @@ -753,17 +915,18 @@ Obtains the number of removals from this buffer. **System capability**: SystemCapability.Utils.Lang **Return value** + | Type| Description| | -------- | -------- | | number | Number of removals from the buffer.| **Example** ```js - var pro = new util.LruBuffer(); + let pro = new util.LruBuffer(); pro.put(2,10); pro.updateCapacity(2); pro.put(50,22); - var result = pro.getRemovalCount(); + let result = pro.getRemovalCount(); ``` @@ -776,16 +939,17 @@ Obtains the number of times that the queried values are matched. **System capability**: SystemCapability.Utils.Lang **Return value** + | Type| Description| | -------- | -------- | | number | Number of times that the queried values are matched.| **Example** ```js - var pro = new util.LruBuffer(); + let pro = new util.LruBuffer(); pro.put(2,10); pro.get(2); - var result = pro.getMatchCount(); + let result = pro.getMatchCount(); ``` @@ -798,15 +962,16 @@ Obtains the number of additions to this buffer. **System capability**: SystemCapability.Utils.Lang **Return value** + | Type| Description| | -------- | -------- | | number | Number of additions to the buffer.| **Example** ```js - var pro = new util.LruBuffer(); + let pro = new util.LruBuffer(); pro.put(2,10); - var result = pro.getPutCount(); + let result = pro.getPutCount(); ``` @@ -819,15 +984,16 @@ Checks whether this buffer is empty. **System capability**: SystemCapability.Utils.Lang **Return value** + | Type| Description| | -------- | -------- | | boolean | Returns **true** if the buffer does not contain any value.| **Example** ```js - var pro = new util.LruBuffer(); + let pro = new util.LruBuffer(); pro.put(2,10); - var result = pro.isEmpty(); + let result = pro.isEmpty(); ``` @@ -840,20 +1006,22 @@ Obtains the value of the specified key. **System capability**: SystemCapability.Utils.Lang **Parameters** + | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | | key | K | Yes| Key based on which the value is queried.| **Return value** + | Type| Description| | -------- | -------- | | V \| undefind | Returns the value of the key if a match is found in the buffer; returns **undefined** otherwise.| **Example** ```js - var pro = new util.LruBuffer(); + let pro = new util.LruBuffer(); pro.put(2,10); - var result = pro.get(2); + let result = pro.get(2); ``` @@ -866,23 +1034,24 @@ Adds a key-value pair to this buffer. **System capability**: SystemCapability.Utils.Lang **Parameters** + | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | | key | K | Yes| Key of the key-value pair to add.| | value | V | Yes| Value of the key-value pair to add.| **Return value** + | Type| Description| | -------- | -------- | | V | Returns the existing value if the key already exists; returns the value added otherwise. If the key or value is null, an exception will be thrown. | **Example** ```js - var pro = new util.LruBuffer(); - var result = pro.put(2,10); + let pro = new util.LruBuffer(); + let result = pro.put(2,10); ``` - ### values8+ values(): V[] @@ -892,17 +1061,18 @@ Obtains all values in this buffer, listed from the most to the least recently ac **System capability**: SystemCapability.Utils.Lang **Return value** + | Type| Description| | -------- | -------- | | V [] | All values in the buffer, listed from the most to the least recently accessed.| **Example** ```js - var pro = new util.LruBuffer(); + let pro = new util.LruBuffer(); pro.put(2,10); pro.put(2,"anhu"); pro.put("afaf","grfb"); - var result = pro.values(); + let result = pro.values(); ``` @@ -915,15 +1085,16 @@ Obtains all keys in this buffer, listed from the most to the least recently acce **System capability**: SystemCapability.Utils.Lang **Return value** + | Type| Description| | -------- | -------- | | K [] | All keys in the buffer, listed from the most to the least recently accessed.| **Example** ```js - var pro = new util.LruBuffer(); + let pro = new util.LruBuffer(); pro.put(2,10); - var result = pro.keys(); + let result = pro.keys(); ``` @@ -936,20 +1107,22 @@ Removes the specified key and its value from this buffer. **System capability**: SystemCapability.Utils.Lang **Parameters** + | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | | key | K | Yes| Key to remove.| **Return value** + | Type| Description| | -------- | -------- | | V \| undefind | Returns an **Optional** object containing the removed key-value pair if the key exists in the buffer; returns an empty **Optional** object otherwise. If the key is null, an exception will be thrown.| **Example** ```js - var pro = new util.LruBuffer(); + let pro = new util.LruBuffer(); pro.put(2,10); - var result = pro.remove(20); + let result = pro.remove(20); ``` @@ -962,6 +1135,7 @@ Performs subsequent operations after a value is removed. **System capability**: SystemCapability.Utils.Lang **Parameters** + | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | | isEvict | boolean | No| Whether the buffer capacity is insufficient. If the value is **true**, this method is called due to insufficient capacity.| @@ -971,8 +1145,8 @@ Performs subsequent operations after a value is removed. **Example** ```js - var arr = []; - class ChildLruBuffer extends util.LruBuffer + let arr = []; + class ChildLruBuffer extends util.LruBuffer { constructor() { @@ -986,7 +1160,7 @@ Performs subsequent operations after a value is removed. } } } - var lru = new ChildLruBuffer(); + let lru = new ChildLruBuffer(); lru.afterRemoval(false,10,30,null); ``` @@ -1000,20 +1174,22 @@ Checks whether this buffer contains the specified key. **System capability**: SystemCapability.Utils.Lang **Parameters** + | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | | key | K | Yes| Key to check.| **Return value** + | Type| Description| | -------- | -------- | | boolean | Returns **true** if the buffer contains the specified key; returns **false** otherwise.| **Example** ```js - var pro = new util.LruBuffer(); + let pro = new util.LruBuffer(); pro.put(2,10); - var result = pro.contains(20); + let result = pro.contains(20); ``` @@ -1026,19 +1202,21 @@ Creates a value if the value of the specified key is not available. **System capability**: SystemCapability.Utils.Lang **Parameters** + | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | | key | K | Yes| Key of which the value is missing.| **Return value** + | Type| Description| | -------- | -------- | | V | Value of the key.| **Example** ```js - var pro = new util.LruBuffer(); - var result = pro.createDefault(50); + let pro = new util.LruBuffer(); + let result = pro.createDefault(50); ``` @@ -1051,15 +1229,16 @@ Obtains a new iterator object that contains all key-value pairs in this object. **System capability**: SystemCapability.Utils.Lang **Return value** + | Type| Description| | -------- | -------- | | [K, V] | Iterable array.| **Example** ```js - var pro = new util.LruBuffer(); + let pro = new util.LruBuffer(); pro.put(2,10); - var result = pro.entries(); + let result = pro.entries(); ``` @@ -1072,15 +1251,16 @@ Obtains a two-dimensional array in key-value pairs. **System capability**: SystemCapability.Utils.Lang **Return value** + | Type| Description| | -------- | -------- | | [K, V] | Two-dimensional array in key-value pairs.| **Example** ```js - var pro = new util.LruBuffer(); + let pro = new util.LruBuffer(); pro.put(2,10); - var result = pro[Symbol.iterator](); + let result = pro[Symbol.iterator](); ``` @@ -1133,6 +1313,7 @@ A constructor used to create a **Scope** object with the specified upper and low **System capability**: SystemCapability.Utils.Lang **Parameters** + | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | | lowerObj | [ScopeType](#scopetype8) | Yes| Lower limit of the **Scope** object.| @@ -1140,9 +1321,9 @@ A constructor used to create a **Scope** object with the specified upper and low **Example** ```js - var tempLower = new Temperature(30); - var tempUpper = new Temperature(40); - var range = new util.Scope(tempLower, tempUpper); + let tempLower = new Temperature(30); + let tempUpper = new Temperature(40); + let range = new util.Scope(tempLower, tempUpper); ``` @@ -1155,16 +1336,17 @@ Obtains a string representation that contains this **Scope**. **System capability**: SystemCapability.Utils.Lang **Return value** + | Type| Description| | -------- | -------- | | string | String representation containing the **Scope**.| **Example** ```js - var tempLower = new Temperature(30); - var tempUpper = new Temperature(40); - var range = new util.Scope(tempLower, tempUpper); - var result = range.toString(); + let tempLower = new Temperature(30); + let tempUpper = new Temperature(40); + let range = new util.Scope(tempLower, tempUpper); + let result = range.toString(); ``` @@ -1177,23 +1359,25 @@ Obtains the intersection of this **Scope** and the given **Scope**. **System capability**: SystemCapability.Utils.Lang **Parameters** + | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | | range | [Scope](#scope8) | Yes| **Scope** specified.| **Return value** + | Type| Description| | -------- | -------- | | [Scope](#scope8) | Intersection of this **Scope** and the given **Scope**.| **Example** ```js - var tempLower = new Temperature(30); - var tempUpper = new Temperature(40); - var range = new util.Scope(tempLower, tempUpper); - var tempMiDF = new Temperature(35); - var tempMidS = new Temperature(39); - var rangeFir = new util.Scope(tempMiDF, tempMidS); + let tempLower = new Temperature(30); + let tempUpper = new Temperature(40); + let range = new util.Scope(tempLower, tempUpper); + let tempMiDF = new Temperature(35); + let tempMidS = new Temperature(39); + let rangeFir = new util.Scope(tempMiDF, tempMidS); range.intersect(rangeFir ); ``` @@ -1207,24 +1391,26 @@ Obtains the intersection of this **Scope** and the given lower and upper limits. **System capability**: SystemCapability.Utils.Lang **Parameters** + | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | | lowerObj | [ScopeType](#scopetype8) | Yes| Lower limit.| | upperObj | [ScopeType](#scopetype8) | Yes| Upper limit.| **Return value** + | Type| Description| | -------- | -------- | | [Scope](#scope8) | Intersection of this **Scope** and the given lower and upper limits.| **Example** ```js - var tempLower = new Temperature(30); - var tempUpper = new Temperature(40); - var tempMiDF = new Temperature(35); - var tempMidS = new Temperature(39); - var range = new util.Scope(tempLower, tempUpper); - var result = range.intersect(tempMiDF, tempMidS); + let tempLower = new Temperature(30); + let tempUpper = new Temperature(40); + let tempMiDF = new Temperature(35); + let tempMidS = new Temperature(39); + let range = new util.Scope(tempLower, tempUpper); + let result = range.intersect(tempMiDF, tempMidS); ``` @@ -1244,10 +1430,10 @@ Obtains the upper limit of this **Scope**. **Example** ```js - var tempLower = new Temperature(30); - var tempUpper = new Temperature(40); - var range = new util.Scope(tempLower, tempUpper); - var result = range.getUpper(); + let tempLower = new Temperature(30); + let tempUpper = new Temperature(40); + let range = new util.Scope(tempLower, tempUpper); + let result = range.getUpper(); ``` @@ -1260,16 +1446,17 @@ Obtains the lower limit of this **Scope**. **System capability**: SystemCapability.Utils.Lang **Return value** + | Type| Description| | -------- | -------- | | [ScopeType](#scopetype8) | Lower limit of this **Scope**.| **Example** ```js - var tempLower = new Temperature(30); - var tempUpper = new Temperature(40); - var range = new util.Scope(tempLower, tempUpper); - var result = range.getLower(); + let tempLower = new Temperature(30); + let tempUpper = new Temperature(40); + let range = new util.Scope(tempLower, tempUpper); + let result = range.getLower(); ``` @@ -1282,12 +1469,14 @@ Obtains the union set of this **Scope** and the given lower and upper limits. **System capability**: SystemCapability.Utils.Lang **Parameters** + | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | | lowerObj | [ScopeType](#scopetype8) | Yes| Lower limit.| | upperObj | [ScopeType](#scopetype8) | Yes| Upper limit.| **Return value** + | Type| Description| | -------- | -------- | | [Scope](#scope8) | Union set of this **Scope** and the given lower and upper limits.| @@ -1295,12 +1484,12 @@ Obtains the union set of this **Scope** and the given lower and upper limits. **Example** ```js - var tempLower = new Temperature(30); - var tempUpper = new Temperature(40); - var tempMiDF = new Temperature(35); - var tempMidS = new Temperature(39); - var range = new util.Scope(tempLower, tempUpper); - var result = range.expand(tempMiDF, tempMidS); + let tempLower = new Temperature(30); + let tempUpper = new Temperature(40); + let tempMiDF = new Temperature(35); + let tempMidS = new Temperature(39); + let range = new util.Scope(tempLower, tempUpper); + let result = range.expand(tempMiDF, tempMidS); ``` @@ -1313,24 +1502,26 @@ Obtains the union set of this **Scope** and the given **Scope**. **System capability**: SystemCapability.Utils.Lang **Parameters** + | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | | range | [Scope](#scope8) | Yes| **Scope** specified.| **Return value** + | Type| Description| | -------- | -------- | | [Scope](#scope8) | Union set of this **Scope** and the given **Scope**.| **Example** ```js - var tempLower = new Temperature(30); - var tempUpper = new Temperature(40); - var tempMiDF = new Temperature(35); - var tempMidS = new Temperature(39); - var range = new util.Scope(tempLower, tempUpper); - var rangeFir = new util.Scope(tempMiDF, tempMidS); - var result = range.expand(rangeFir); + let tempLower = new Temperature(30); + let tempUpper = new Temperature(40); + let tempMiDF = new Temperature(35); + let tempMidS = new Temperature(39); + let range = new util.Scope(tempLower, tempUpper); + let rangeFir = new util.Scope(tempMiDF, tempMidS); + let result = range.expand(rangeFir); ``` @@ -1343,22 +1534,24 @@ Obtains the union set of this **Scope** and the given value. **System capability**: SystemCapability.Utils.Lang **Parameters** + | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | | value | [ScopeType](#scopetype8) | Yes| Value specified.| **Return value** + | Type| Description| | -------- | -------- | | [Scope](#scope8) | Union set of this **Scope** and the given value.| **Example** ```js - var tempLower = new Temperature(30); - var tempUpper = new Temperature(40); - var tempMiDF = new Temperature(35); - var range = new util.Scope(tempLower, tempUpper); - var result = range.expand(tempMiDF); + let tempLower = new Temperature(30); + let tempUpper = new Temperature(40); + let tempMiDF = new Temperature(35); + let range = new util.Scope(tempLower, tempUpper); + let result = range.expand(tempMiDF); ``` @@ -1371,21 +1564,23 @@ Checks whether a value is within this **Scope**. **System capability**: SystemCapability.Utils.Lang **Parameters** + | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | | value | [ScopeType](#scopetype8) | Yes| Value specified.| **Return value** + | Type| Description| | -------- | -------- | | boolean | Returns **true** if the value is within this **Scope**; returns **false** otherwise.| **Example** ```js - var tempLower = new Temperature(30); - var tempUpper = new Temperature(40); - var tempMiDF = new Temperature(35); - var range = new util.Scope(tempLower, tempUpper); + let tempLower = new Temperature(30); + let tempUpper = new Temperature(40); + let tempMiDF = new Temperature(35); + let range = new util.Scope(tempLower, tempUpper); range.contains(tempMiDF); ``` @@ -1399,24 +1594,26 @@ Checks whether a range is within this **Scope**. **System capability**: SystemCapability.Utils.Lang **Parameters** + | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | | range | [Scope](#scope8) | Yes| **Scope** specified.| **Return value** + | Type| Description| | -------- | -------- | | boolean | Returns **true** if the range is within this **Scope**; returns **false** otherwise.| **Example** ```js - var tempLower = new Temperature(30); - var tempUpper = new Temperature(40); - var range = new util.Scope(tempLower, tempUpper); - var tempLess = new Temperature(20); - var tempMore = new Temperature(45); - var rangeSec = new util.Scope(tempLess, tempMore); - var result = range.contains(rangeSec); + let tempLower = new Temperature(30); + let tempUpper = new Temperature(40); + let range = new util.Scope(tempLower, tempUpper); + let tempLess = new Temperature(20); + let tempMore = new Temperature(45); + let rangeSec = new util.Scope(tempLess, tempMore); + let result = range.contains(rangeSec); ``` @@ -1429,22 +1626,24 @@ Limits a value to this **Scope**. **System capability**: SystemCapability.Utils.Lang **Parameters** + | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | | value | [ScopeType](#scopetype8) | Yes| Value specified.| **Return value** + | Type| Description| | -------- | -------- | | [ScopeType](#scopetype8) | Returns **lowerObj** if the specified value is less than the lower limit; returns **upperObj** if the specified value is greater than the upper limit; returns the specified value if it is within this **Scope**.| **Example** ```js - var tempLower = new Temperature(30); - var tempUpper = new Temperature(40); - var tempMiDF = new Temperature(35); - var range = new util.Scope(tempLower, tempUpper); - var result = range.clamp(tempMiDF); + let tempLower = new Temperature(30); + let tempUpper = new Temperature(40); + let tempMiDF = new Temperature(35); + let range = new util.Scope(tempLower, tempUpper); + let result = range.clamp(tempMiDF); ``` @@ -1461,7 +1660,7 @@ A constructor used to create a **Base64** object. **Example** ```js - var base64 = new util.Base64(); + let base64 = new util.Base64(); ``` @@ -1474,20 +1673,22 @@ Encodes the input content. **System capability**: SystemCapability.Utils.Lang **Parameters** + | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | | src | Uint8Array | Yes| Uint8Array to encode.| **Return value** + | Type| Description| | -------- | -------- | | Uint8Array | Uint8Array encoded.| **Example** ```js - var that = new util.Base64(); - var array = new Uint8Array([115,49,51]); - var result = that.encodeSync(array); + let that = new util.Base64(); + let array = new Uint8Array([115,49,51]); + let result = that.encodeSync(array); ``` @@ -1500,20 +1701,22 @@ Encodes the input content. **System capability**: SystemCapability.Utils.Lang **Parameters** + | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | | src | Uint8Array | Yes| Uint8Array to encode.| **Return value** + | Type| Description| | -------- | -------- | | string | String encoded from the Uint8Array.| **Example** ```js - var that = new util.Base64(); - var array = new Uint8Array([115,49,51]); - var result = that.encodeToStringSync(array); + let that = new util.Base64(); + let array = new Uint8Array([115,49,51]); + let result = that.encodeToStringSync(array); ``` @@ -1526,20 +1729,22 @@ Decodes the input content. **System capability**: SystemCapability.Utils.Lang **Parameters** + | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | | src | Uint8Array \| string | Yes| Uint8Array or string to decode.| **Return value** + | Type| Description| | -------- | -------- | | Uint8Array | Uint8Array decoded.| **Example** ```js - var that = new util.Base64(); - var buff = 'czEz'; - var result = that.decodeSync(buff); + let that = new util.Base64(); + let buff = 'czEz'; + let result = that.decodeSync(buff); ``` @@ -1552,20 +1757,22 @@ Encodes the input content asynchronously. **System capability**: SystemCapability.Utils.Lang **Parameters** + | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | | src | Uint8Array | Yes| Uint8Array to encode asynchronously.| **Return value** + | Type| Description| | -------- | -------- | | Promise<Uint8Array> | Uint8Array obtained after asynchronous encoding.| **Example** ```js - var that = new util.Base64(); - var array = new Uint8Array([115,49,51]); - var rarray = new Uint8Array([99,122,69,122]); + let that = new util.Base64(); + let array = new Uint8Array([115,49,51]); + let rarray = new Uint8Array([99,122,69,122]); that.encode(array).then(val=>{ for (var i = 0; i < rarray.length; i++) { console.log(val[i].toString()) @@ -1583,19 +1790,21 @@ Encodes the input content asynchronously. **System capability**: SystemCapability.Utils.Lang **Parameters** + | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | | src | Uint8Array | Yes| Uint8Array to encode asynchronously.| **Return value** + | Type| Description| | -------- | -------- | | Promise<string> | String obtained after asynchronous encoding.| **Example** ```js - var that = new util.Base64(); - var array = new Uint8Array([115,49,51]); + let that = new util.Base64(); + let array = new Uint8Array([115,49,51]); that.encodeToString(array).then(val=>{ console.log(val) }) @@ -1611,20 +1820,22 @@ Decodes the input content asynchronously. **System capability**: SystemCapability.Utils.Lang **Parameters** + | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | | src | Uint8Array \| string | Yes| Uint8Array or string to decode asynchronously.| **Return value** + | Type| Description| | -------- | -------- | | Promise<Uint8Array> | Uint8Array obtained after asynchronous decoding.| **Example** ```js - var that = new util.Base64(); - var array = new Uint8Array([99,122,69,122]); - var rarray = new Uint8Array([115,49,51]); + let that = new util.Base64(); + let array = new Uint8Array([99,122,69,122]); + let rarray = new Uint8Array([115,49,51]); that.decode(array).then(val=>{ for (var i = 0; i < rarray.length; i++) { console.log(val[i].toString()) @@ -1646,7 +1857,7 @@ A constructor used to create a **Types** object. **Example** ```js - var type = new util.types(); + let type = new util.types(); ``` @@ -1659,19 +1870,21 @@ Checks whether the input value is of the **ArrayBuffer** type. **System capability**: SystemCapability.Utils.Lang **Parameters** + | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | | value | Object | Yes| Object to check.| **Return value** + | Type| Description| | -------- | -------- | | boolean | Returns **true** if the input value is of the **ArrayBuffer** type; returns **false** otherwise.| **Example** ```js - var that = new util.types(); - var result = that.isAnyArrayBuffer(new ArrayBuffer(0)); + let that = new util.types(); + let result = that.isAnyArrayBuffer(new ArrayBuffer(0)); ``` @@ -1686,19 +1899,21 @@ Checks whether the input value is of the **ArrayBufferView** type. **System capability**: SystemCapability.Utils.Lang **Parameters** + | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | | value | Object | Yes| Object to check.| **Return value** + | Type| Description| | -------- | -------- | | boolean | Returns **true** if the input value is of the **ArrayBufferView** type; returns **false** otherwise.| **Example** ```js - var that = new util.types(); - var result = that.isArrayBufferView(new Int8Array([])); + let that = new util.types(); + let result = that.isArrayBufferView(new Int8Array([])); ``` @@ -1711,22 +1926,24 @@ Checks whether the input value is of the **arguments** type. **System capability**: SystemCapability.Utils.Lang **Parameters** + | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | | value | Object | Yes| Object to check.| **Return value** + | Type| Description| | -------- | -------- | | boolean | Returns **true** if the input value is of the **arguments** type; returns **false** otherwise.| **Example** ```js - var that = new util.types(); + let that = new util.types(); function foo() { var result = that.isArgumentsObject(arguments); } - var f = foo(); + let f = foo(); ``` @@ -1739,19 +1956,21 @@ Checks whether the input value is of the **ArrayBuffer** type. **System capability**: SystemCapability.Utils.Lang **Parameters** + | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | | value | Object | Yes| Object to check.| **Return value** + | Type| Description| | -------- | -------- | | boolean | Returns **true** if the input value is of the **ArrayBuffer** type; returns **false** otherwise.| **Example** ```js - var that = new util.types(); - var result = that.isArrayBuffer(new ArrayBuffer(0)); + let that = new util.types(); + let result = that.isArrayBuffer(new ArrayBuffer(0)); ``` @@ -1764,19 +1983,21 @@ Checks whether the input value is an asynchronous function. **System capability**: SystemCapability.Utils.Lang **Parameters** + | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | | value | Object | Yes| Object to check.| **Return value** + | Type| Description| | -------- | -------- | | boolean | Returns **true** if the input value is an asynchronous function; returns **false** otherwise.| **Example** ```js - var that = new util.types(); - var result = that.isAsyncFunction(async function foo() {}); + let that = new util.types(); + let result = that.isAsyncFunction(async function foo() {}); ``` @@ -1789,19 +2010,21 @@ Checks whether the input value is of the **Boolean** type. **System capability**: SystemCapability.Utils.Lang **Parameters** + | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | | value | Object | Yes| Object to check.| **Return value** + | Type| Description| | -------- | -------- | | boolean | Returns **true** if the input value is of the **Boolean** type; returns **false** otherwise.| **Example** ```js - var that = new util.types(); - var result = that.isBooleanObject(new Boolean(true)); + let that = new util.types(); + let result = that.isBooleanObject(new Boolean(true)); ``` @@ -1814,19 +2037,21 @@ Checks whether the input value is of the **Boolean**, **Number**, **String**, or **System capability**: SystemCapability.Utils.Lang **Parameters** + | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | | value | Object | Yes| Object to check.| **Return value** + | Type| Description| | -------- | -------- | | boolean | Returns **true** if the input value is of the **Boolean**, **Number**, **String**, or **Symbol** type; returns **false** otherwise.| **Example** ```js - var that = new util.types(); - var result = that.isBoxedPrimitive(new Boolean(false)); + let that = new util.types(); + let result = that.isBoxedPrimitive(new Boolean(false)); ``` @@ -1839,20 +2064,22 @@ Checks whether the input value is of the **DataView** type. **System capability**: SystemCapability.Utils.Lang **Parameters** + | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | | value | Object | Yes| Object to check.| **Return value** + | Type| Description| | -------- | -------- | | boolean | Returns **true** if the input value is of the **DataView** type; returns **false** otherwise.| **Example** ```js - var that = new util.types(); + let that = new util.types(); const ab = new ArrayBuffer(20); - var result = that.isDataView(new DataView(ab)); + let result = that.isDataView(new DataView(ab)); ``` @@ -1865,19 +2092,21 @@ Checks whether the input value is of the **Date** type. **System capability**: SystemCapability.Utils.Lang **Parameters** + | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | | value | Object | Yes| Object to check.| **Return value** + | Type| Description| | -------- | -------- | | boolean | Returns **true** if the input value is of the **Date** type; returns **false** otherwise.| **Example** ```js - var that = new util.types(); - var result = that.isDate(new Date()); + let that = new util.types(); + let result = that.isDate(new Date()); ``` @@ -1890,19 +2119,21 @@ Checks whether the input value is of the **native external** type. **System capability**: SystemCapability.Utils.Lang **Parameters** + | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | | value | Object | Yes| Object to check.| **Return value** + | Type| Description| | -------- | -------- | | boolean | Returns **true** if the input value is of the **native external** type; returns **false** otherwise.| **Example** ```js - var that = new util.types(); - var result = that.isExternal(true); + let that = new util.types(); + let result = that.isExternal(true); ``` @@ -1915,19 +2146,21 @@ Checks whether the input value is of the **Float32Array** type. **System capability**: SystemCapability.Utils.Lang **Parameters** + | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | | value | Object | Yes| Object to check.| **Return value** + | Type| Description| | -------- | -------- | | boolean | Returns **true** if the input value is of the **Float32Array** type; returns **false** otherwise.| **Example** ```js - var that = new util.types(); - var result = that.isFloat32Array(new Float32Array()); + let that = new util.types(); + let result = that.isFloat32Array(new Float32Array()); ``` @@ -1940,19 +2173,21 @@ Checks whether the input value is of the **Float64Array** type. **System capability**: SystemCapability.Utils.Lang **Parameters** + | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | | value | Object | Yes| Object to check.| **Return value** + | Type| Description| | -------- | -------- | | boolean | Returns **true** if the input value is of the **Float64Array** type; returns **false** otherwise.| **Example** ```js - var that = new util.types(); - var result = that.isFloat64Array(new Float64Array()); + let that = new util.types(); + let result = that.isFloat64Array(new Float64Array()); ``` @@ -1965,19 +2200,21 @@ Checks whether the input value is a generator function. **System capability**: SystemCapability.Utils.Lang **Parameters** + | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | | value | Object | Yes| Object to check.| **Return value** + | Type| Description| | -------- | -------- | | boolean | Returns **true** if the input value is a generator function; returns **false** otherwise.| **Example** ```js - var that = new util.types(); - var result = that.isGeneratorFunction(function* foo() {}); + let that = new util.types(); + let result = that.isGeneratorFunction(function* foo() {}); ``` @@ -1990,21 +2227,23 @@ Checks whether the input value is a generator object. **System capability**: SystemCapability.Utils.Lang **Parameters** + | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | | value | Object | Yes| Object to check.| **Return value** + | Type| Description| | -------- | -------- | | boolean | Returns **true** if the input value is a generator object; returns **false** otherwise.| **Example** ```js - var that = new util.types(); + let that = new util.types(); function* foo() {} const generator = foo(); - var result = that.isGeneratorObject(generator); + let result = that.isGeneratorObject(generator); ``` @@ -2017,19 +2256,21 @@ Checks whether the input value is of the **Int8Array** type. **System capability**: SystemCapability.Utils.Lang **Parameters** + | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | | value | Object | Yes| Object to check.| **Return value** + | Type| Description| | -------- | -------- | | boolean | Returns **true** if the input value is of the **Int8Array** type; returns **false** otherwise.| **Example** ```js - var that = new util.types(); - var result = that.isInt8Array(new Int8Array([])); + let that = new util.types(); + let result = that.isInt8Array(new Int8Array([])); ``` @@ -2042,19 +2283,21 @@ Checks whether the input value is of the **Int16Array** type. **System capability**: SystemCapability.Utils.Lang **Parameters** + | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | | value | Object | Yes| Object to check.| **Return value** + | Type| Description| | -------- | -------- | | boolean | Returns **true** if the input value is of the **Int16Array** type; returns **false** otherwise.| **Example** ```js - var that = new util.types(); - var result = that.isInt16Array(new Int16Array([])); + let that = new util.types(); + let result = that.isInt16Array(new Int16Array([])); ``` @@ -2067,19 +2310,21 @@ Checks whether the input value is of the **Int32Array** type. **System capability**: SystemCapability.Utils.Lang **Parameters** + | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | | value | Object | Yes| Object to check.| **Return value** + | Type| Description| | -------- | -------- | | boolean | Returns **true** if the input value is of the **Int32Array** type; returns **false** otherwise.| **Example** ```js - var that = new util.types(); - var result = that.isInt32Array(new Int32Array([])); + let that = new util.types(); + let result = that.isInt32Array(new Int32Array([])); ``` @@ -2092,19 +2337,21 @@ Checks whether the input value is of the **Map** type. **System capability**: SystemCapability.Utils.Lang **Parameters** + | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | | value | Object | Yes| Object to check.| **Return value** + | Type| Description| | -------- | -------- | | boolean | Returns **true** if the input value is of the **Map** type; returns **false** otherwise.| **Example** ```js - var that = new util.types(); - var result = that.isMap(new Map()); + let that = new util.types(); + let result = that.isMap(new Map()); ``` @@ -2117,20 +2364,22 @@ Checks whether the input value is of the **MapIterator** type. **System capability**: SystemCapability.Utils.Lang **Parameters** + | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | | value | Object | Yes| Object to check.| **Return value** + | Type| Description| | -------- | -------- | | boolean | Returns **true** if the input value is of the **MapIterator** type; returns **false** otherwise.| **Example** ```js - var that = new util.types(); + let that = new util.types(); const map = new Map(); - var result = that.isMapIterator(map.keys()); + let result = that.isMapIterator(map.keys()); ``` @@ -2143,19 +2392,21 @@ Checks whether the input value is of the **Error** type. **System capability**: SystemCapability.Utils.Lang **Parameters** + | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | | value | Object | Yes| Object to check.| **Return value** + | Type| Description| | -------- | -------- | | boolean | Returns **true** if the input value is of the **Error** type; returns **false** otherwise.| **Example** ```js - var that = new util.types(); - var result = that.isNativeError(new TypeError()); + let that = new util.types(); + let result = that.isNativeError(new TypeError()); ``` @@ -2168,19 +2419,21 @@ Checks whether the input value is a number object. **System capability**: SystemCapability.Utils.Lang **Parameters** + | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | | value | Object | Yes| Object to check.| **Return value** + | Type| Description| | -------- | -------- | | boolean | Returns **true** if the input value is a number object; returns **false** otherwise.| **Example** ```js - var that = new util.types(); - var result = that.isNumberObject(new Number(0)); + let that = new util.types(); + let result = that.isNumberObject(new Number(0)); ``` @@ -2193,19 +2446,21 @@ Checks whether the input value is a promise. **System capability**: SystemCapability.Utils.Lang **Parameters** + | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | | value | Object | Yes| Object to check.| **Return value** + | Type| Description| | -------- | -------- | | boolean | Returns **true** if the input value is a promise; returns **false** otherwise.| **Example** ```js - var that = new util.types(); - var result = that.isPromise(Promise.resolve(1)); + let that = new util.types(); + let result = that.isPromise(Promise.resolve(1)); ``` @@ -2218,21 +2473,23 @@ Checks whether the input value is a proxy. **System capability**: SystemCapability.Utils.Lang **Parameters** + | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | | value | Object | Yes| Object to check.| **Return value** + | Type| Description| | -------- | -------- | | boolean | Returns **true** if the input value is a proxy; returns **false** otherwise.| **Example** ```js - var that = new util.types(); + let that = new util.types(); const target = {}; const proxy = new Proxy(target, {}); - var result = that.isProxy(proxy); + let result = that.isProxy(proxy); ``` @@ -2245,19 +2502,21 @@ Checks whether the input value is of the **RegExp** type. **System capability**: SystemCapability.Utils.Lang **Parameters** + | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | | value | Object | Yes| Object to check.| **Return value** + | Type| Description| | -------- | -------- | | boolean | Returns **true** if the input value is of the **RegExp** type; returns **false** otherwise.| **Example** ```js - var that = new util.types(); - var result = that.isRegExp(new RegExp('abc')); + let that = new util.types(); + let result = that.isRegExp(new RegExp('abc')); ``` @@ -2270,19 +2529,21 @@ Checks whether the input value is of the **Set** type. **System capability**: SystemCapability.Utils.Lang **Parameters** + | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | | value | Object | Yes| Object to check.| **Return value** + | Type| Description| | -------- | -------- | | boolean | Returns **true** if the input value is of the **Set** type; returns **false** otherwise.| **Example** ```js - var that = new util.types(); - var result = that.isSet(new Set()); + let that = new util.types(); + let result = that.isSet(new Set()); ``` @@ -2295,20 +2556,22 @@ Checks whether the input value is of the **SetIterator** type. **System capability**: SystemCapability.Utils.Lang **Parameters** + | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | | value | Object | Yes| Object to check.| **Return value** + | Type| Description| | -------- | -------- | | boolean | Returns **true** if the input value is of the **SetIterator** type; returns **false** otherwise.| **Example** ```js - var that = new util.types(); + let that = new util.types(); const set = new Set(); - var result = that.isSetIterator(set.keys()); + let result = that.isSetIterator(set.keys()); ``` @@ -2321,19 +2584,21 @@ Checks whether the input value is a string object. **System capability**: SystemCapability.Utils.Lang **Parameters** + | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | | value | Object | Yes| Object to check.| **Return value** + | Type| Description| | -------- | -------- | | boolean | Returns **true** if the input value is a string object; returns **false** otherwise.| **Example** ```js - var that = new util.types(); - var result = that.isStringObject(new String('foo')); + let that = new util.types(); + let result = that.isStringObject(new String('foo')); ``` @@ -2346,20 +2611,22 @@ Checks whether the input value is a symbol object. **System capability**: SystemCapability.Utils.Lang **Parameters** + | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | | value | Object | Yes| Object to check.| **Return value** + | Type| Description| | -------- | -------- | | boolean | Returns **true** if the input value is a symbol object; returns **false** otherwise.| **Example** ```js - var that = new util.types(); + let that = new util.types(); const symbols = Symbol('foo'); - var result = that.isSymbolObject(Object(symbols)); + let result = that.isSymbolObject(Object(symbols)); ``` @@ -2374,19 +2641,21 @@ Checks whether the input value is of the **TypedArray** type. **System capability**: SystemCapability.Utils.Lang **Parameters** + | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | | value | Object | Yes| Object to check.| **Return value** + | Type| Description| | -------- | -------- | | boolean | Returns **true** if the input value is of the **TypedArray** type; returns **false** otherwise.| **Example** ```js - var that = new util.types(); - var result = that.isTypedArray(new Float64Array([])); + let that = new util.types(); + let result = that.isTypedArray(new Float64Array([])); ``` @@ -2399,19 +2668,21 @@ Checks whether the input value is of the **Uint8Array** type. **System capability**: SystemCapability.Utils.Lang **Parameters** + | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | | value | Object | Yes| Object to check.| **Return value** + | Type| Description| | -------- | -------- | | boolean | Returns **true** if the input value is of the **Uint8Array** type; returns **false** otherwise.| **Example** ```js - var that = new util.types(); - var result = that.isUint8Array(new Uint8Array([])); + let that = new util.types(); + let result = that.isUint8Array(new Uint8Array([])); ``` @@ -2424,19 +2695,21 @@ Checks whether the input value is of the **Uint8ClampedArray** type. **System capability**: SystemCapability.Utils.Lang **Parameters** + | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | | value | Object | Yes| Object to check.| **Return value** + | Type| Description| | -------- | -------- | | boolean | Returns **true** if the input value is of the **Uint8ClampedArray** type; returns **false** otherwise.| **Example** ```js - var that = new util.types(); - var result = that.isUint8ClampedArray(new Uint8ClampedArray([])); + let that = new util.types(); + let result = that.isUint8ClampedArray(new Uint8ClampedArray([])); ``` @@ -2449,19 +2722,21 @@ Checks whether the input value is of the **Uint16Array** type. **System capability**: SystemCapability.Utils.Lang **Parameters** + | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | | value | Object | Yes| Object to check.| **Return value** + | Type| Description| | -------- | -------- | | boolean | Returns **true** if the input value is of the **Uint16Array** type; returns **false** otherwise.| **Example** ```js - var that = new util.types(); - var result = that.isUint16Array(new Uint16Array([])); + let that = new util.types(); + let result = that.isUint16Array(new Uint16Array([])); ``` @@ -2474,19 +2749,21 @@ Checks whether the input value is of the **Uint32Array** type. **System capability**: SystemCapability.Utils.Lang **Parameters** + | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | | value | Object | Yes| Object to check.| **Return value** + | Type| Description| | -------- | -------- | | boolean | Returns **true** if the input value is of the **Uint32Array** type; returns **false** otherwise.| **Example** ```js - var that = new util.types(); - var result = that.isUint32Array(new Uint32Array([])); + let that = new util.types(); + let result = that.isUint32Array(new Uint32Array([])); ``` @@ -2499,19 +2776,21 @@ Checks whether the input value is of the **WeakMap** type. **System capability**: SystemCapability.Utils.Lang **Parameters** + | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | | value | Object | Yes| Object to check.| **Return value** + | Type| Description| | -------- | -------- | | boolean | Returns **true** if the input value is of the **WeakMap** type; returns **false** otherwise.| **Example** ```js - var that = new util.types(); - var result = that.isWeakMap(new WeakMap()); + let that = new util.types(); + let result = that.isWeakMap(new WeakMap()); ``` @@ -2524,17 +2803,128 @@ Checks whether the input value is of the **WeakSet** type. **System capability**: SystemCapability.Utils.Lang **Parameters** + | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | | value | Object | Yes| Object to check.| **Return value** + | Type| Description| | -------- | -------- | | boolean | Returns **true** if the input value is of the **WeakSet** type; returns **false** otherwise.| **Example** ```js - var that = new util.types(); - var result = that.isWeakSet(new WeakSet()); + let that = new util.types(); + let result = that.isWeakSet(new WeakSet()); + ``` + + +### isBigInt64Array8+ + +isBigInt64Array(value: Object): boolean + +Checks whether the input value is of the **BigInt64Array** type. + +**System capability**: SystemCapability.Utils.Lang + +**Parameters** + +| Name| Type| Mandatory| Description| +| -------- | -------- | -------- | -------- | +| value | Object | Yes| Object to check.| + +**Return value** + +| Type| Description| +| -------- | -------- | +| boolean | Returns **true** if the input value is of the **BigInt64Array** type; returns **false** otherwise.| + +**Example** + ```js + let that = new util.types(); + let result = that.isBigInt64Array(new BigInt64Array([])); + ``` + + +### isBigUint64Array8+ + +isBigUint64Array(value: Object): boolean + +Checks whether the input value is of the **BigUint64Array** type. + +**System capability**: SystemCapability.Utils.Lang + +**Parameters** + +| Name| Type| Mandatory| Description| +| -------- | -------- | -------- | -------- | +| value | Object | Yes| Object to check.| + +**Return value** + +| Type| Description| +| -------- | -------- | +| boolean | Returns **true** if the input value is of the **BigUint64Array** type; returns **false** otherwise.| + +**Example** + ```js + let that = new util.types(); + let result = that.isBigUint64Array(new BigUint64Array([])); + ``` + + +### isModuleNamespaceObject8+ + +isModuleNamespaceObject(value: Object): boolean + +Checks whether the input value is a module namespace object. + +**System capability**: SystemCapability.Utils.Lang + +**Parameters** + +| Name| Type| Mandatory| Description| +| -------- | -------- | -------- | -------- | +| value | Object | Yes| Object to check.| + +**Return value** + +| Type| Description| +| -------- | -------- | +| boolean | Returns **true** if the input value is a module namespace object; returns **false** otherwise.| + +**Example** + ```js + import url from '@ohos.url' + let that = new util.types(); + let result = that.isModuleNamespaceObject(url); + ``` + + +### isSharedArrayBuffer8+ + +isSharedArrayBuffer(value: Object): boolean + +Checks whether the input value is of the **SharedArrayBuffer** type. + +**System capability**: SystemCapability.Utils.Lang + +**Parameters** + +| Name| Type| Mandatory| Description| +| -------- | -------- | -------- | -------- | +| value | Object | Yes| Object to check.| + +**Return value** + +| Type| Description| +| -------- | -------- | +| boolean | Returns **true** if the input value is of the **SharedArrayBuffer** type; returns **false** otherwise.| + +**Example** + ```js + let that = new util.types(); + let result = that.isSharedArrayBuffer(new SharedArrayBuffer(0)); ``` diff --git a/en/application-dev/reference/apis/js-apis-wifi.md b/en/application-dev/reference/apis/js-apis-wifi.md index eccade788a2d19a81b1512ae206dbdfba449b95d..ae5ab4c9b924e6b72457a9bbadec1cfd26ef5e6b 100644 --- a/en/application-dev/reference/apis/js-apis-wifi.md +++ b/en/application-dev/reference/apis/js-apis-wifi.md @@ -16,13 +16,15 @@ import wifi from '@ohos.wifi'; enableWifi(): boolean Enables WLAN. -This is a system API. + +**System API**: This is a system API. **Required permissions**: ohos.permission.SET_WIFI_INFO and ohos.permission.MANAGE_WIFI_CONNECTION (available only to system applications) **System capability**: SystemCapability.Communication.WiFi.STA **Return value** + | **Type**| **Description**| | -------- | -------- | | boolean | Returns **true** if the operation is successful; returns **false** otherwise.| @@ -33,13 +35,15 @@ This is a system API. disableWifi(): boolean Disables WLAN. -This is a system API. + +**System API**: This is a system API. **Required permissions**: ohos.permission.SET_WIFI_INFO and ohos.permission.MANAGE_WIFI_CONNECTION (available only to system applications) **System capability**: SystemCapability.Communication.WiFi.STA **Return value** + | **Type**| **Description**| | -------- | -------- | | boolean | Returns **true** if the operation is successful; returns **false** otherwise.| @@ -56,6 +60,7 @@ Checks whether WLAN is enabled. **System capability**: SystemCapability.Communication.WiFi.STA **Return value** + | **Type**| **Description**| | -------- | -------- | | boolean | Returns **true** if WLAN is enabled; returns **false** otherwise.| @@ -72,6 +77,7 @@ Starts a scan for WLAN. **System capability**: SystemCapability.Communication.WiFi.STA **Return value** + | **Type**| **Description**| | -------- | -------- | | boolean | Returns **true** if the operation is successful; returns **false** otherwise.| @@ -88,6 +94,7 @@ Obtains the scan result. This API uses a promise to return the result. **System capability**: SystemCapability.Communication.WiFi.STA **Return value** + | **Type**| **Description**| | -------- | -------- | | Promise< Array<[WifiScanInfo](#wifiscaninfo)> > | Promise used to return the detected hotspots.| @@ -104,6 +111,7 @@ Obtains the scan result. This API uses an asynchronous callback to return the re **System capability**: SystemCapability.Communication.WiFi.STA **Parameters** + | **Name**| **Type**| **Mandatory**| **Description**| | -------- | -------- | -------- | -------- | | callback | AsyncCallback< Array<[WifiScanInfo](#wifiscaninfo)>> | Yes| Callback invoked to return the result. If the operation is successful, **err** is **0** and **data** is the detected hotspots. Otherwise, **err** is a non-zero value and **data** is empty.| @@ -157,6 +165,7 @@ Represents WLAN hotspot information. **System capability**: SystemCapability.Communication.WiFi.STA + | **Name**| **Type**| **Readable/Writable**| **Description**| | -------- | -------- | -------- | -------- | | ssid | string | Read only| Service set identifier (SSID) of the hotspot, in UTF-8 format.| @@ -167,8 +176,8 @@ Represents WLAN hotspot information. | band | number | Read only| Frequency band of the WLAN access point (AP).| | frequency | number | Read only| Frequency of the WLAN AP.| | channelWidth | number | Read only| Channel width of the WLAN AP.| -| centerFrequency09+ | number | Read only| Center frequency.| -| centerFrequency19+ | number | Read only| Center frequency.| +| centerFrequency09+ | number | Read only| Center frequency of the hotspot.| +| centerFrequency19+ | number | Read only| Center frequency of the hotspot. If the hotspot uses two non-overlapping WLAN channels, two center frequencies, namely **centerFrequency0** and **centerFrequency1**, are returned.| | infoElems9+ | Array<[WifiInfoElem](#wifiinfoelem9)> | Read only| Information elements.| | timestamp | number | Read only| Timestamp.| @@ -179,6 +188,7 @@ Enumerates the WLAN security types. **System capability**: SystemCapability.Communication.WiFi.Core + | **Name**| **Default Value**| **Description**| | -------- | -------- | -------- | | WIFI_SEC_TYPE_INVALID | 0 | Invalid security type.| @@ -197,8 +207,11 @@ Enumerates the WLAN security types. Represents a WLAN information element. +**System API**: This is a system API. + **System capability**: SystemCapability.Communication.WiFi.STA + | **Name**| **Type**| **Readable/Writable**| **Description**| | -------- | -------- | -------- | -------- | | eid | number | Read only| ID of the information element.| @@ -211,6 +224,7 @@ Enumerates the WLAN channel widths. **System capability**: SystemCapability.Communication.WiFi.STA + | **Name**| **Default Value**| **Description**| | -------- | -------- | -------- | | WIDTH_20MHZ | 0 | 20 MHz.| @@ -232,6 +246,7 @@ Obtains the scan result. This API returns the result synchronously. **System capability**: SystemCapability.Communication.WiFi.STA **Return value** + | **Type**| **Description**| | -------- | -------- | |  Array<[WifiScanInfo](#wifiscaninfo)> | Scan result obtained.| @@ -242,18 +257,21 @@ Obtains the scan result. This API returns the result synchronously. addDeviceConfig(config: WifiDeviceConfig): Promise<number> Adds network configuration. This API uses a promise to return the result. -This is a system API. + +**System API**: This is a system API. **Required permissions**: ohos.permission.SET_WIFI_INFO and ohos.permission.SET_WIFI_CONFIG **System capability**: SystemCapability.Communication.WiFi.STA **Parameters** + | **Name**| **Type**| **Mandatory**| **Description**| | -------- | -------- | -------- | -------- | | config | [WifiDeviceConfig](#wifideviceconfig) | Yes| WLAN configuration to add.| **Return value** + | **Type**| **Description**| | -------- | -------- | | Promise<number> | Promise used to return the WLAN configuration ID. If **-1** is returned, the operation has failed.| @@ -264,6 +282,7 @@ Represents the WLAN configuration. **System capability**: SystemCapability.Communication.WiFi.STA + | **Name**| **Type**| **Readable/Writable**| **Description**| | -------- | -------- | -------- | -------- | | ssid | string | Read only| SSID of the hotspot, in UTF-8 format.| @@ -271,22 +290,25 @@ Represents the WLAN configuration. | preSharedKey | string | Read only| PSK of the hotspot.| | isHiddenSsid | boolean | Read only| Whether the network is hidden.| | securityType | [WifiSecurityType](#wifisecuritytype) | Read only| Security type.| -| creatorUid | number | Read only| User ID, which is available only to system applications.| -| disableReason | number | Read only| Reason for disabling WLAN. This parameter is available only to system applications.| -| netId | number | Read only| Allocated network ID, which is available only to system applications.| -| randomMacType | number | Read only| Random MAC type, which is available only to system applications.| -| randomMacAddr | string | Read only| Random MAC address, which is available only for system applications.| -| ipType | [IpType](#iptype7) | Read only| IP address type, which is available only to system applications.| -| staticIp | [IpConfig](#ipconfig7) | Read only| Static IP address configuration, which is available only to system applications.| -| eapConfig9+ | [WifiEapConfig](#wifieapconfig9) | Read only| EAP configuration, which is available only to system applications.| +| creatorUid | number | Read only| ID of the creator.
**System API**: This is a system API.| +| disableReason | number | Read only| Reason for disabling WLAN.
**System API**: This is a system API.| +| netId | number | Read only| Network ID.
**System API**: This is a system API.| +| randomMacType | number | Read only| Random MAC type.
**System API**: This is a system API.| +| randomMacAddr | string | Read only| Random MAC address.
**System API**: This is a system API.| +| ipType | [IpType](#iptype7) | Read only| IP address type.
**System API**: This is a system API.| +| staticIp | [IpConfig](#ipconfig7) | Read only| Static IP address configuration.
**System API**: This is a system API.| +| eapConfig9+ | [WifiEapConfig](#wifieapconfig9) | Read only| EAP configuration.
**System API**: This is a system API.| ## IpType7+ Enumerate the IP address types. +**System API**: This is a system API. + **System capability**: SystemCapability.Communication.WiFi.STA + | Name| Default Value| Description| | -------- | -------- | -------- | | STATIC | 0 | Static IP address.| @@ -298,6 +320,8 @@ Enumerate the IP address types. Represents IP configuration information. +**System API**: This is a system API. + **System capability**: SystemCapability.Communication.WiFi.STA | **Name**| **Type**| **Readable/Writable**| **Description**| @@ -312,6 +336,8 @@ Represents IP configuration information. Represents EAP configuration information. +**System API**: This is a system API. + **System capability**: SystemCapability.Communication.WiFi.STA | **Name**| **Type**| **Readable/Writable**| **Description**| @@ -335,6 +361,8 @@ Represents EAP configuration information. Enumerates the EAP authentication methods. +**System API**: This is a system API. + **System capability**: SystemCapability.Communication.WiFi.STA | Name| Default Value| Description| @@ -354,6 +382,8 @@ Enumerates the EAP authentication methods. Enumerates the Phase 2 authentication methods. +**System API**: This is a system API. + **System capability**: SystemCapability.Communication.WiFi.STA | Name| Default Value| Description| @@ -373,13 +403,15 @@ Enumerates the Phase 2 authentication methods. addDeviceConfig(config: WifiDeviceConfig, callback: AsyncCallback<number>): void Adds network configuration. This API uses an asynchronous callback to return the result. -This is a system API. + +**System API**: This is a system API. **Required permissions**: ohos.permission.SET_WIFI_INFO and ohos.permission.SET_WIFI_CONFIG **System capability**: SystemCapability.Communication.WiFi.STA **Parameters** + | **Name**| **Type**| **Mandatory**| **Description**| | -------- | -------- | -------- | -------- | | config | [WifiDeviceConfig](#wifideviceconfig) | Yes| WLAN configuration to add.| @@ -397,11 +429,13 @@ Adds the configuration of an untrusted network. This API uses a promise to retur **System capability**: SystemCapability.Communication.WiFi.STA **Parameters** + | **Name**| **Type**| **Mandatory**| **Description**| | -------- | -------- | -------- | -------- | | config | [WifiDeviceConfig](#wifideviceconfig) | Yes| WLAN configuration to add.| **Return value** + | **Type**| **Description**| | -------- | -------- | | Promise<boolean> | Promise used to return the result. If the operation is successful, **true** is returned; otherwise, **false** is returned.| @@ -418,6 +452,7 @@ Adds the configuration of an untrusted network. This API uses an asynchronous ca **System capability**: SystemCapability.Communication.WiFi.STA **Parameters** + | **Name**| **Type**| **Mandatory**| **Description**| | -------- | -------- | -------- | -------- | | config | [WifiDeviceConfig](#wifideviceconfig) | Yes| WLAN configuration to add.| @@ -435,11 +470,13 @@ Removes the configuration of an untrusted network. This API uses a promise to re **System capability**: SystemCapability.Communication.WiFi.STA **Parameters** + | **Name**| **Type**| **Mandatory**| **Description**| | -------- | -------- | -------- | -------- | | config | [WifiDeviceConfig](#wifideviceconfig) | Yes| WLAN configuration to remove.| **Return value** + | **Type**| **Description**| | -------- | -------- | | Promise<boolean> | Promise used to return the result. If the operation is successful, **true** is returned; otherwise, **false** is returned.| @@ -456,6 +493,7 @@ Removes the configuration of an untrusted network. This API uses an asynchronous **System capability**: SystemCapability.Communication.WiFi.STA **Parameters** + | **Name**| **Type**| **Mandatory**| **Description**| | -------- | -------- | -------- | -------- | | config | [WifiDeviceConfig](#wifideviceconfig) | Yes| WLAN configuration to remove.| @@ -473,11 +511,13 @@ Adds the configuration of a candidate network. This API uses a promise to return **System capability**: SystemCapability.Communication.WiFi.STA **Parameters** + | **Name**| **Type**| **Mandatory**| **Description**| | -------- | -------- | -------- | -------- | | config | [WifiDeviceConfig](#wifideviceconfig) | Yes| WLAN configuration to add.| **Return value** + | **Type**| **Description**| | -------- | -------- | | Promise<number> | Promise used to return the network configuration ID.| @@ -494,6 +534,7 @@ Adds the configuration of a candidate network. This API uses an asynchronous cal **System capability**: SystemCapability.Communication.WiFi.STA **Parameters** + | **Name**| **Type**| **Mandatory**| **Description**| | -------- | -------- | -------- | -------- | | config | [WifiDeviceConfig](#wifideviceconfig) | Yes| WLAN configuration to add.| @@ -511,11 +552,13 @@ Removes the configuration of a candidate network. This API uses a promise to ret **System capability**: SystemCapability.Communication.WiFi.STA **Parameters** + | **Name**| **Type**| **Mandatory**| **Description**| | -------- | -------- | -------- | -------- | | networkId | number | Yes| ID of the network configuration to remove.| **Return value** + | **Type**| **Description**| | -------- | -------- | | Promise<void> | Promise used to return the result.| @@ -532,6 +575,7 @@ Removes the configuration of a candidate network. This API uses an asynchronous **System capability**: SystemCapability.Communication.WiFi.STA **Parameters** + | **Name**| **Type**| **Mandatory**| **Description**| | -------- | -------- | -------- | -------- | | networkId | number | Yes| ID of the network configuration to remove.| @@ -549,6 +593,7 @@ Obtains candidate network configuration. **System capability**: SystemCapability.Communication.WiFi.STA **Return value** + | **Type**| **Description**| | -------- | -------- | |  Array<[WifiDeviceConfig](#wifideviceconfig)> | Candidate network configuration obtained.| @@ -556,7 +601,7 @@ Obtains candidate network configuration. ## wifi.connectToCandidateConfig9+ -connectToCandidateConfig(networkId: number): boolean +connectToCandidateConfig(networkId: number): void Connects to a candidate network. @@ -565,33 +610,32 @@ Connects to a candidate network. **System capability**: SystemCapability.Communication.WiFi.STA **Parameters** + | **Name**| **Type**| **Mandatory**| **Description**| | -------- | -------- | -------- | -------- | | networkId | number | Yes| ID of the candidate network configuration.| -**Return value** - | **Type**| **Description**| - | -------- | -------- | - | boolean | Returns **true** if the operation is successful; returns **false** otherwise.| - ## wifi.connectToNetwork connectToNetwork(networkId: number): boolean Connects to the specified network. -This is a system API. + +**System API**: This is a system API. **Required permissions**: ohos.permission.MANAGE_WIFI_CONNECTION (available only to system applications) **System capability**: SystemCapability.Communication.WiFi.STA **Parameters** + | **Name**| **Type**| **Mandatory**| **Description**| | -------- | -------- | -------- | -------- | | networkId | number | Yes| Network configuration ID.| **Return value** + | **Type**| **Description**| | -------- | -------- | | boolean | Returns **true** if the operation is successful; returns **false** otherwise.| @@ -602,20 +646,22 @@ This is a system API. connectToDevice(config: WifiDeviceConfig): boolean Connects to the specified network. -This is a system API. -**Required permissions**: - ohos.permission.SET_WIFI_INFO, ohos.permission.SET_WIFI_CONFIG, and ohos.permissio.MANAGE_WIFI_CONNECTION (available only to system applications) +**System API**: This is a system API. + +**Required permissions**: ohos.permission.SET_WIFI_INFO, ohos.permission.SET_WIFI_CONFIG, and ohos.permissio.MANAGE_WIFI_CONNECTION (available only to system applications) **System capability**: SystemCapability.Communication.WiFi.STA **Parameters** + | **Name**| **Type**| **Mandatory**| **Description**| | -------- | -------- | -------- | -------- | | config | [WifiDeviceConfig](#wifideviceconfig) | Yes| WLAN configuration.| **Return value** + | **Type**| **Description**| | -------- | -------- | | boolean | Returns **true** if the operation is successful; returns **false** otherwise.| @@ -625,16 +671,17 @@ This is a system API. disconnect(): boolean -Disconnects from the specified network. -This is a system API. +Disconnects the network. -**Required permissions**: - ohos.permission.SET_WIFI_INFO and ohos.permission.MANAGE_WIFI_CONNECTION (available only to system applications) +**System API**: This is a system API. + +**Required permissions**: ohos.permission.SET_WIFI_INFO and ohos.permission.MANAGE_WIFI_CONNECTION (available only to system applications) **System capability**: SystemCapability.Communication.WiFi.STA **Return value** + | **Type**| **Description**| | -------- | -------- | | boolean | Returns **true** if the operation is successful; returns **false** otherwise.| @@ -651,12 +698,14 @@ Obtains the WLAN signal level. **System capability**: SystemCapability.Communication.WiFi.STA **Parameters** + | **Name**| **Type**| **Mandatory**| **Description**| | -------- | -------- | -------- | -------- | | rssi | number | Yes| RSSI of the hotspot, in dBm.| | band | number | Yes| Frequency band of the WLAN AP.| **Return value** + | **Type**| **Description**| | -------- | -------- | | number | Signal level obtained. The value range is [0, 4].| @@ -673,6 +722,7 @@ Obtains WLAN connection information. This API uses a promise to return the resul **System capability**: SystemCapability.Communication.WiFi.STA **Return value** + | Type| Description| | -------- | -------- | | Promise<[WifiLinkedInfo](#wifilinkedinfo)> | Promise used to return the WLAN connection information obtained.| @@ -689,6 +739,7 @@ Obtains WLAN connection information. This API uses an asynchronous callback to r **System capability**: SystemCapability.Communication.WiFi.STA **Parameters** + | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | | callback | AsyncCallback<[WifiLinkedInfo](#wifilinkedinfo)> | Yes| Callback invoked to return the result. If the operation is successful, **err** is **0** and **data** is the WLAN connection information obtained. If **err** is not **0**, an error has occurred.| @@ -723,19 +774,19 @@ Represents the WLAN connection information. | -------- | -------- | -------- | -------- | | ssid | string | Read only| SSID of the hotspot, in UTF-8 format.| | bssid | string | Read only| BSSID of the hotspot.| -| networkId | number | Read only| Network configuration ID, which is available only to system applications.| +| networkId | number | Read only| Network configuration ID.
**System API**: This is a system API.| | rssi | number | Read only| RSSI of the hotspot, in dBm.| | band | number | Read only| Frequency band of the WLAN AP.| | linkSpeed | number | Read only| Speed of the WLAN AP.| | frequency | number | Read only| Frequency of the WLAN AP.| | isHidden | boolean | Read only| Whether to hide the WLAN AP.| | isRestricted | boolean | Read only| Whether to restrict data volume at the WLAN AP.| -| chload | number | Read only| Channel load. A larger value indicates a higher load. This parameter is only available to system applications.| -| snr | number | Read only| Signal-to-noise ratio (SNR), which is available only to system applications.| +| chload | number | Read only| Channel load. A larger value indicates a higher load.
**System API**: This is a system API.| +| snr | number | Read only| Signal-to-noise ratio (SNR).
**System API**: This is a system API.| | macType9+ | number | Read only| MAC address type.| | macAddress | string | Read only| MAC address of the device.| | ipAddress | number | Read only| IP address of the device that sets up the WLAN connection.| -| suppState | [SuppState](#suppstate) | Read only| Supplicant state, which is available only to system applications.| +| suppState | [SuppState](#suppstate) | Read only| Supplicant state.
**System API**: This is a system API.| | connState | [ConnState](#connstate) | Read only| WLAN connection state.| @@ -761,6 +812,8 @@ Enumerates the WLAN connection states. Enumerates the supplicant states. +**System API**: This is a system API. + **System capability**: SystemCapability.Communication.WiFi.STA | Name| Default Value| Description| @@ -790,6 +843,7 @@ Checks whether the WLAN is connected. **System capability**: SystemCapability.Communication.WiFi.STA **Return value** + | **Type**| **Description**| | -------- | -------- | | boolean | Returns **true** if the WLAN is connected; returns **false** otherwise.| @@ -800,13 +854,15 @@ Checks whether the WLAN is connected. getSupportedFeatures(): number Obtains the features supported by this device. -This is a system API. + +**System API**: This is a system API. **Required permissions**: ohos.permission.GET_WIFI_INFO **System capability**: SystemCapability.Communication.WiFi.Core **Return value** + | **Type**| **Description**| | -------- | -------- | | number | Feature value. | @@ -839,11 +895,13 @@ Checks whether the device supports the specified WLAN feature. **Parameters** + | **Name**| **Type**| Mandatory| **Description**| | -------- | -------- | -------- | -------- | | featureId | number | Yes| Feature ID.| **Return value** + | **Type**| **Description**| | -------- | -------- | | boolean | Returns **true** if the feature is supported; returns **false** otherwise.| @@ -854,13 +912,15 @@ Checks whether the device supports the specified WLAN feature. getDeviceMacAddress(): string[] Obtains the device MAC address. -This is a system API. + +**System API**: This is a system API. **Required permissions**: ohos.permission.GET_WIFI_LOCAL_MAC and ohos.permission.GET_WIFI_INFO (available only to system applications) **System capability**: SystemCapability.Communication.WiFi.STA **Return value** + | **Type**| **Description**| | -------- | -------- | | string[] | MAC address obtained.| @@ -877,6 +937,7 @@ Obtains IP information. **System capability**: SystemCapability.Communication.WiFi.STA **Return value** + | **Type**| **Description**| | -------- | -------- | | [IpInfo](#ipinfo7) | IP information obtained.| @@ -910,6 +971,7 @@ Obtains the country code. **System capability**: SystemCapability.Communication.WiFi.Core **Return value** + | **Type**| **Description**| | -------- | -------- | | string | Country code obtained.| @@ -920,13 +982,15 @@ Obtains the country code. reassociate(): boolean Re-associates with the network. -This is a system API. + +**System API**: This is a system API. **Required permissions**: ohos.permission.SET_WIFI_INFO and ohos.permission.MANAGE_WIFI_CONNECTION (available only to system applications) **System capability**: SystemCapability.Communication.WiFi.STA **Return value** + | **Type**| **Description**| | -------- | -------- | | boolean | Returns **true** if the operation is successful; returns **false** otherwise.| @@ -937,13 +1001,15 @@ This is a system API. reconnect(): boolean Reconnects to the network. -This is a system API. + +**System API**: This is a system API. **Required permissions**: ohos.permission.SET_WIFI_INFO and ohos.permission.MANAGE_WIFI_CONNECTION (available only to system applications) **System capability**: SystemCapability.Communication.WiFi.STA **Return value** + | **Type**| **Description**| | -------- | -------- | | boolean | Returns **true** if the operation is successful; returns **false** otherwise.| @@ -954,13 +1020,15 @@ This is a system API. getDeviceConfigs():  Array<[WifiDeviceConfig](#wifideviceconfig)> Obtains network configuration. -This is a system API. + +**System API**: This is a system API. **Required permissions**: ohos.permission.GET_WIFI_INFO, ohos.permission.LOCATION, and ohos.permission.GET_WIFI_CONFIG **System capability**: SystemCapability.Communication.WiFi.STA **Return value** + | **Type**| **Description**| | -------- | -------- | |  Array<[WifiDeviceConfig](#wifideviceconfig)> | Array of network configuration obtained.| @@ -968,24 +1036,27 @@ This is a system API. ## wifi.updateNetwork7+ -updateNetwork(config: WifiDeviceConfig): boolean +updateNetwork(config: WifiDeviceConfig): number Updates network configuration. -This is a system API. + +**System API**: This is a system API. **Required permissions**: ohos.permission.SET_WIFI_INFO and ohos.permission.SET_WIFI_CONFIG **System capability**: SystemCapability.Communication.WiFi.STA **Parameters** + | **Name**| **Type**| **Mandatory**| **Description**| | -------- | -------- | -------- | -------- | | config | [WifiDeviceConfig](#wifideviceconfig) | Yes| New WLAN configuration.| **Return value** + | **Type**| **Description**| | -------- | -------- | - | boolean | Returns **true** if the operation is successful; returns **false** otherwise.| + | number | ID of the updated network configuration. The value **-1** indicates that the operation has failed.| ## wifi.disableNetwork7+ @@ -993,18 +1064,21 @@ This is a system API. disableNetwork(netId: number): boolean Disables network configuration. -This is a system API. + +**System API**: This is a system API. **Required permissions**: ohos.permission.SET_WIFI_INFO and ohos.permission.MANAGE_WIFI_CONNECTION (available only to system applications) **System capability**: SystemCapability.Communication.WiFi.STA **Parameters** + | **Name**| **Type**| **Mandatory**| **Description**| | -------- | -------- | -------- | -------- | | netId | number | Yes| ID of the network configuration to disable.| **Return value** + | **Type**| **Description**| | -------- | -------- | | boolean | Returns **true** if the operation is successful; returns **false** otherwise.| @@ -1015,13 +1089,15 @@ This is a system API. removeAllNetwork(): boolean Removes the configuration of all networks. -This is a system API. + +**System API**: This is a system API. **Required permissions**: ohos.permission.SET_WIFI_INFO and ohos.permission.MANAGE_WIFI_CONNECTION (available only to system applications) **System capability**: SystemCapability.Communication.WiFi.STA **Return value** + | **Type**| **Description**| | -------- | -------- | | boolean | Returns **true** if the operation is successful; returns **false** otherwise.| @@ -1032,18 +1108,21 @@ This is a system API. removeDevice(id: number): boolean Removes the specified network configuration. -This is a system API. + +**System API**: This is a system API. **Required permissions**: ohos.permission.SET_WIFI_INFO and ohos.permission.MANAGE_WIFI_CONNECTION (available only to system applications) **System capability**: SystemCapability.Communication.WiFi.STA **Parameters** + | **Name**| **Type**| **Mandatory**| **Description**| | -------- | -------- | -------- | -------- | | id | number | Yes| ID of the network configuration to remove.| **Return value** + | **Type**| **Description**| | -------- | -------- | | boolean | Returns **true** if the operation is successful; returns **false** otherwise.| @@ -1054,13 +1133,15 @@ This is a system API. enableHotspot(): boolean Enables this hotspot. -This is a system API. + +**System API**: This is a system API. **Required permissions**: ohos.permission.MANAGE_WIFI_HOTSPOT (available only to system applications) **System capability**: SystemCapability.Communication.WiFi.AP.Core **Return value** + | **Type**| **Description**| | -------- | -------- | | boolean | Returns **true** if the operation is successful; returns **false** otherwise.| @@ -1071,13 +1152,15 @@ This is a system API. disableHotspot(): boolean Disables this hotspot. -This is a system API. + +**System API**: This is a system API. **Required permissions**: ohos.permission.MANAGE_WIFI_HOTSPOT (available only to system applications) **System capability**: SystemCapability.Communication.WiFi.AP.Core **Return value** + | **Type**| **Description**| | -------- | -------- | | boolean | Returns **true** if the operation is successful; returns **false** otherwise.| @@ -1088,13 +1171,15 @@ This is a system API. isHotspotDualBandSupported(): boolean Checks whether the hotspot supports dual band. -This is a system API. + +**System API**: This is a system API. **Required permissions**: ohos.permission.GET_WIFI_INFO and ohos.permission.MANAGE_WIFI_HOTSPOT (available only to system applications) **System capability**: SystemCapability.Communication.WiFi.AP.Core **Return value** + | **Type**| **Description**| | -------- | -------- | | boolean | Returns **true** if the feature is supported; returns **false** otherwise.| @@ -1105,13 +1190,15 @@ This is a system API. isHotspotActive(): boolean Checks whether this hotspot is active. -This is a system API. + +**System API**: This is a system API. **Required permissions**: ohos.permission.GET_WIFI_INFO **System capability**: SystemCapability.Communication.WiFi.AP.Core **Return value** + | **Type**| **Description**| | -------- | -------- | | boolean | Returns **true** if the hotspot is active; returns **false** otherwise.| @@ -1122,18 +1209,21 @@ This is a system API. setHotspotConfig(config: HotspotConfig): boolean Sets hotspot configuration. -This is a system API. + +**System API**: This is a system API. **Required permissions**: ohos.permission.SET_WIFI_INFO and ohos.permission.GET_WIFI_CONFIG **System capability**: SystemCapability.Communication.WiFi.AP.Core **Parameters** + | **Name**| **Type**| **Mandatory**| **Description**| | -------- | -------- | -------- | -------- | | config | [HotspotConfig](#hotspotconfig7) | Yes| Hotspot configuration to set.| **Return value** + | **Type**| **Description**| | -------- | -------- | | boolean | Returns **true** if the operation is successful; returns **false** otherwise.| @@ -1143,6 +1233,8 @@ This is a system API. Represents the hotspot configuration. +**System API**: This is a system API. + **System capability**: SystemCapability.Communication.WiFi.AP.Core | **Name**| **Type**| **Readable/Writable**| **Description**| @@ -1159,13 +1251,15 @@ Represents the hotspot configuration. getHotspotConfig(): HotspotConfig obtains hotspot configuration. -This is a system API. + +**System API**: This is a system API. **Required permissions**: ohos.permission.GET_WIFI_INFO and ohos.permission.GET_WIFI_CONFIG **System capability**: SystemCapability.Communication.WiFi.AP.Core **Return value** + | **Type**| **Description**| | -------- | -------- | | [HotspotConfig](#hotspotconfig7) | Hotspot configuration obtained.| @@ -1176,13 +1270,15 @@ This is a system API. getStations():  Array<[StationInfo](#stationinfo7)> Obtains information about the connected stations. -This is a system API. + +**System API**: This is a system API. **Required permissions**: ohos.permission.GET_WIFI_INFO, ohos.permission.LOCATION, and ohos.permission.MANAGE_WIFI_HOTSPOT (available only to system applications) **System capability**: SystemCapability.Communication.WiFi.AP.Core **Return value** + | **Type**| **Description**| | -------- | -------- | |  Array<[StationInfo](#stationinfo7)> | Connected stations obtained.| @@ -1192,6 +1288,8 @@ This is a system API. Represents the station information. +**System API**: This is a system API. + **System capability**: SystemCapability.Communication.WiFi.AP.Core | **Name**| **Type**| **Readable/Writable**| **Description**| @@ -1212,6 +1310,7 @@ Obtains P2P link information. This API uses a promise to return the result. **System capability**: SystemCapability.Communication.WiFi.P2P **Return value** + | Type| Description| | -------- | -------- | | Promise<[WifiP2pLinkedInfo](#wifip2plinkedinfo8)> | Promise used to return the P2P link information obtained.| @@ -1254,6 +1353,7 @@ Obtains P2P link information. This API uses an asynchronous callback to return t **System capability**: SystemCapability.Communication.WiFi.P2P **Parameters** + | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | | callback | AsyncCallback<[WifiP2pLinkedInfo](#wifip2plinkedinfo8)> | Yes| Callback invoked to return the result. If the operation is successful, **err** is **0** and **data** is the P2P link information. If **err** is not **0**, an error has occurred.| @@ -1270,6 +1370,7 @@ Obtains the current P2P group information. This API uses a promise to return the **System capability**: SystemCapability.Communication.WiFi.P2P **Return value** + | Type| Description| | -------- | -------- | | Promise<[WifiP2pGroupInfo](#wifip2pgroupinfo8)> | Promise used to return the group information obtained.| @@ -1286,6 +1387,7 @@ Obtains the current P2P group information. This API uses an asynchronous callbac **System capability**: SystemCapability.Communication.WiFi.P2P **Parameters** + | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | | callback | AsyncCallback<[WifiP2pGroupInfo](#wifip2pgroupinfo8)> | Yes| Callback invoked to return the result. If the operation is successful, **err** is **0** and **data** is the group information obtained. If **err** is not **0**, an error has occurred.| @@ -1302,6 +1404,7 @@ Obtains the peer device list in the P2P connection. This API uses a promise to r **System capability**: SystemCapability.Communication.WiFi.P2P **Return value** + | Type| Description| | -------- | -------- | | Promise<[WifiP2pDevice[]](#wifip2pdevice8)> | Promise used to return the peer device list.| @@ -1318,6 +1421,7 @@ Obtains the peer device list in the P2P connection. This API uses an asynchronou **System capability**: SystemCapability.Communication.WiFi.P2P **Parameters** + | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | | callback | AsyncCallback<[WifiP2pDevice[]](#wifip2pdevice8)> | Yes| Callback invoked to return the result. If the operation is successful, **err** is **0** and **data** is the peer device list obtained. If **err** is not **0**, an error has occurred.| @@ -1364,6 +1468,7 @@ Obtains the local device information in the P2P connection. This API uses a prom **System capability**: SystemCapability.Communication.WiFi.P2P **Return value** + | Type| Description| | -------- | -------- | | Promise<[WifiP2pDevice](#wifip2pdevice8)> | Promise used to return the local device information obtained.| @@ -1380,6 +1485,7 @@ Obtains the local device information in the P2P connection. This API uses an asy **System capability**: SystemCapability.Communication.WiFi.P2P **Parameters** + | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | | callback | AsyncCallback<[WifiP2pDevice](#wifip2pdevice8)> | Yes| Callback invoked to return the result. If the operation is successful, **err** is **0** and **data** is the local device information obtained. If **err** is not **0**, an error has occurred.| @@ -1402,6 +1508,7 @@ Creates a P2P group. | config | [WifiP2PConfig](#wifip2pconfig8) | Yes| Group configuration.| **Return value** + | Type| Description| | -------- | -------- | | boolean | Returns **true** if the operation is successful; returns **false** otherwise.| @@ -1446,6 +1553,7 @@ Removes this P2P group. **System capability**: SystemCapability.Communication.WiFi.P2P **Return value** + | Type| Description| | -------- | -------- | | boolean | Returns **true** if the operation is successful; returns **false** otherwise.| @@ -1463,11 +1571,13 @@ Sets up a P2P connection. **Parameters** + | **Name**| **Type**| Mandatory| **Description**| | -------- | -------- | -------- | -------- | | config | [WifiP2PConfig](#wifip2pconfig8) | Yes| P2P group configuration.| **Return value** + | Type| Description| | -------- | -------- | | boolean | Returns **true** if the operation is successful; returns **false** otherwise.| @@ -1551,6 +1661,7 @@ Cancels this P2P connection. **System capability**: SystemCapability.Communication.WiFi.P2P **Return value** + | Type| Description| | -------- | -------- | | boolean | Returns **true** if the operation is successful; returns **false** otherwise.| @@ -1567,6 +1678,7 @@ Starts to discover devices. **System capability**: SystemCapability.Communication.WiFi.P2P **Return value** + | Type| Description| | -------- | -------- | | boolean | Returns **true** if the operation is successful; returns **false** otherwise.| @@ -1583,6 +1695,7 @@ Stops discovering devices. **System capability**: SystemCapability.Communication.WiFi.P2P **Return value** + | Type| Description| | -------- | -------- | | boolean | Returns **true** if the operation is successful; returns **false** otherwise.| @@ -1594,17 +1707,21 @@ deletePersistentGroup(netId: number): boolean Deletes a persistent group. -**Required permissions**: ohos.permission.GET_WIFI_INFO +**System API**: This is a system API. + +**Required permissions**: ohos.permission.SET_WIFI_INFO and ohos.permission.MANAGE_WIFI_CONNECTION **System capability**: SystemCapability.Communication.WiFi.P2P **Parameters** + | **Name**| **Type**| Mandatory| **Description**| | -------- | -------- | -------- | -------- | | netId | number | Yes| ID of the group to delete.| **Return value** + | Type| Description| | -------- | -------- | | boolean | Returns **true** if the operation is successful; returns **false** otherwise.| @@ -1615,13 +1732,15 @@ Deletes a persistent group. getP2pGroups(): Promise<Array<WifiP2pGroupInfo>> Obtains information about all P2P groups. This API uses a promise to return the result. -This is a system API. + +**System API**: This is a system API. **Required permissions**: ohos.permission.GET_WIFI_INFO and ohos.permission.LOCATION **System capability**: SystemCapability.Communication.WiFi.P2P **Return value** + | Type| Description| | -------- | -------- | | Promise< Array<[WifiP2pGroupInfo](#wifip2pgroupinfo8)> > | Promise used to return the group information obtained.| @@ -1652,11 +1771,14 @@ getP2pGroups(callback: AsyncCallback<Array<WifiP2pGroupInfo>>): void Obtains information about all P2P groups. This API uses an asynchronous callback to return the result. +**System API**: This is a system API. + **Required permissions**: ohos.permission.GET_WIFI_INFO and ohos.permission.LOCATION **System capability**: SystemCapability.Communication.WiFi.P2P **Parameters** + | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | | callback | AsyncCallback< Array<[WifiP2pGroupInfo](#wifip2pgroupinfo8)>> | Yes| Callback invoked to return the result. If the operation is successful, **err** is **0** and **data** is the group information obtained. If **err** is not **0**, an error has occurred.| @@ -1667,19 +1789,21 @@ Obtains information about all P2P groups. This API uses an asynchronous callback setDeviceName(devName: string): boolean Sets the device name. -This is a system API. -**Required permissions**: - ohos.permission.SET_WIFI_INFO and ohos.permission.MANAGE_WIFI_CONNECTION (available only to system applications) +**System API**: This is a system API. + +**Required permissions**: ohos.permission.SET_WIFI_INFO and ohos.permission.MANAGE_WIFI_CONNECTION (available only to system applications) **System capability**: SystemCapability.Communication.WiFi.P2P **Parameters** + | **Name**| **Type**| **Mandatory**| **Description**| | -------- | -------- | -------- | -------- | | devName | string | Yes| Device name to set.| **Return value** + | **Type**| **Description**| | -------- | -------- | | boolean | Returns **true** if the operation is successful; returns **false** otherwise.| @@ -1696,6 +1820,7 @@ Registers the WLAN state change events. **System capability**: SystemCapability.Communication.WiFi.STA **Parameters** + | **Name**| **Type**| **Mandatory**| **Description**| | -------- | -------- | -------- | -------- | | type | string | Yes| Event type. The value is **wifiStateChange**.| @@ -1722,6 +1847,7 @@ Unregisters the WLAN state change events. **System capability**: SystemCapability.Communication.WiFi.STA **Parameters** + | **Name**| **Type**| **Mandatory**| **Description**| | -------- | -------- | -------- | -------- | | type | string | Yes| Event type. The value is **wifiStateChange**.| @@ -1755,6 +1881,7 @@ Registers the WLAN connection state change events. **System capability**: SystemCapability.Communication.WiFi.STA **Parameters** + | **Name**| **Type**| **Mandatory**| **Description**| | -------- | -------- | -------- | -------- | | type | string | Yes| Event type. The value is **wifiConnectionChange**.| @@ -1779,6 +1906,7 @@ Unregisters the WLAN connection state change events. **System capability**: SystemCapability.Communication.WiFi.STA **Parameters** + | **Name**| **Type**| **Mandatory**| **Description**| | -------- | -------- | -------- | -------- | | type | string | Yes| Event type. The value is **wifiConnectionChange**.| @@ -1796,6 +1924,7 @@ Registers the WLAN scan state change events. **System capability**: SystemCapability.Communication.WiFi.STA **Parameters** + | **Name**| **Type**| **Mandatory**| **Description**| | -------- | -------- | -------- | -------- | | type | string | Yes| Event type. The value is **wifiScanStateChange**.| @@ -1838,6 +1967,7 @@ Registers the RSSI change events. **System capability**: SystemCapability.Communication.WiFi.STA **Parameters** + | **Name**| **Type**| **Mandatory**| **Description**| | -------- | -------- | -------- | -------- | | type | string | Yes| Event type. The value is **wifiRssiChange**.| @@ -1855,6 +1985,7 @@ Unregisters the RSSI change events. **System capability**: SystemCapability.Communication.WiFi.STA **Parameters** + | **Name**| **Type**| **Mandatory**| **Description**| | -------- | -------- | -------- | -------- | | type | string | Yes| Event type. The value is **wifiRssiChange**.| @@ -1872,6 +2003,7 @@ Registers the hotspot state change events. **System capability**: SystemCapability.Communication.WiFi.AP.Core **Parameters** + | **Name**| **Type**| **Mandatory**| **Description**| | -------- | -------- | -------- | -------- | | type | string | Yes| Event type. The value is **hotspotStateChange**.| @@ -1898,6 +2030,7 @@ Unregisters the hotspot state change events. **System capability**: SystemCapability.Communication.WiFi.AP.Core **Parameters** + | **Name**| **Type**| **Mandatory**| **Description**| | -------- | -------- | -------- | -------- | | type | string | Yes| Event type. The value is **hotspotStateChange**.| @@ -1915,6 +2048,7 @@ Registers the P2P state change events. **System capability**: SystemCapability.Communication.WiFi.P2P **Parameters** + | **Name**| **Type**| **Mandatory**| **Description**| | -------- | -------- | -------- | -------- | | type | string | Yes| Event type. The value is **p2pStateChange**.| @@ -1941,6 +2075,7 @@ Unregisters the P2P state change events. **System capability**: SystemCapability.Communication.WiFi.P2P **Parameters** + | **Name**| **Type**| **Mandatory**| **Description**| | -------- | -------- | -------- | -------- | | type | string | Yes| Event type. The value is **p2pStateChange**.| @@ -1958,6 +2093,7 @@ Registers the P2P connection state change events. **System capability**: SystemCapability.Communication.WiFi.P2P **Parameters** + | **Name**| **Type**| **Mandatory**| **Description**| | -------- | -------- | -------- | -------- | | type | string | Yes| Event type. The value is **p2pConnectionChange**.| @@ -1975,6 +2111,7 @@ Unregisters the P2P connection state change events. **System capability**: SystemCapability.Communication.WiFi.P2P **Parameters** + | **Name**| **Type**| **Mandatory**| **Description**| | -------- | -------- | -------- | -------- | | type | string | Yes| Event type. The value is **p2pConnectionChange**.| @@ -1992,6 +2129,7 @@ Registers the P2P device state change events. **System capability**: SystemCapability.Communication.WiFi.P2P **Parameters** + | **Name**| **Type**| **Mandatory**| **Description**| | -------- | -------- | -------- | -------- | | type | string | Yes| Event type. The value is **p2pDeviceChange**.| @@ -2009,6 +2147,7 @@ Unregisters the P2P device state change events. **System capability**: SystemCapability.Communication.WiFi.P2P **Parameters** + | **Name**| **Type**| **Mandatory**| **Description**| | -------- | -------- | -------- | -------- | | type | string | Yes| Event type. The value is **p2pDeviceChange**.| @@ -2026,6 +2165,7 @@ Registers the P2P peer device state change events. **System capability**: SystemCapability.Communication.WiFi.P2P **Parameters** + | **Name**| **Type**| **Mandatory**| **Description**| | -------- | -------- | -------- | -------- | | type | string | Yes| Event type. The value is **p2pPeerDeviceChange**.| @@ -2043,6 +2183,7 @@ Unregisters the P2P peer device state change events. **System capability**: SystemCapability.Communication.WiFi.P2P **Parameters** + | **Name**| **Type**| **Mandatory**| **Description**| | -------- | -------- | -------- | -------- | | type | string | Yes| Event type. The value is **p2pPeerDeviceChange**.| @@ -2060,6 +2201,7 @@ Registers the P2P persistent group state change events. **System capability**: SystemCapability.Communication.WiFi.P2P **Parameters** + | **Name**| **Type**| **Mandatory**| **Description**| | -------- | -------- | -------- | -------- | | type | string | Yes| Event type. The value is **p2pPersistentGroupChange**.| @@ -2077,6 +2219,7 @@ Unregisters the P2P persistent group state change events. **System capability**: SystemCapability.Communication.WiFi.P2P **Parameters** + | **Name**| **Type**| **Mandatory**| **Description**| | -------- | -------- | -------- | -------- | | type | string | Yes| Event type. The value is **p2pPersistentGroupChange**.| @@ -2094,6 +2237,7 @@ Registers the P2P device discovery state change events. **System capability**: SystemCapability.Communication.WiFi.P2P **Parameters** + | **Name**| **Type**| **Mandatory**| **Description**| | -------- | -------- | -------- | -------- | | type | string | Yes| Event type. The value is **p2pDiscoveryChange**.| @@ -2118,6 +2262,7 @@ Unregisters the P2P device discovery state change events. **System capability**: SystemCapability.Communication.WiFi.P2P **Parameters** + | **Name**| **Type**| **Mandatory**| **Description**| | -------- | -------- | -------- | -------- | | type | string | Yes| Event type. The value is **p2pDiscoveryChange**.| diff --git a/en/application-dev/reference/apis/js-apis-worker.md b/en/application-dev/reference/apis/js-apis-worker.md index 9fc490de3749cbba00fcbc0c1e05bd5639e9ef5b..5aa129293c705d4c8c9ce5eaf78ac2a6f7960662 100644 --- a/en/application-dev/reference/apis/js-apis-worker.md +++ b/en/application-dev/reference/apis/js-apis-worker.md @@ -64,17 +64,18 @@ A constructor used to create a **Worker** instance. **Example** ```js +import worker from '@ohos.worker'; // Create a worker thread. // In the FA model, the workers and pages directories are at the same level. -const workerInstance = new worker.Worker("workers/worker.js", {name:"first worker"}); +const workerFAModel01 = new worker.Worker("workers/worker.js", {name:"first worker"}); // In the FA model, the workers and pages directories are at different levels. -const workerInstance = new worker.Worker("../workers/worker.js", {name:"first worker"}); +const workerFAModel02 = new worker.Worker("../workers/worker.js", {name:"first worker"}); // In the stage model, the workers and pages directories are at the same level. -const workerInstance = new worker.Worker('entry/ets/workers/worker.ts'); +const workerStageModel01 = new worker.Worker('entry/ets/workers/worker.ts'); // In the stage model, the workers and pages directories are at different levels. -const workerInstance = new worker.Worker('entry/ets/pages/workers/worker.ts'); +const workerStageModel02 = new worker.Worker('entry/ets/pages/workers/worker.ts'); // scriptURL—— Description of "entry/ets/workers/worker.ts". // entry is the value of the name attribute under module in the module.json5 file. @@ -144,8 +145,9 @@ Sends a message to the worker thread. The message data is transferred using the ```js const workerInstance = new worker.Worker("workers/worker.js"); + workerInstance.postMessage("hello world"); -const workerInstance= new worker.Worker("workers/worker.js"); + var buffer = new ArrayBuffer(8); workerInstance.postMessage(buffer, [buffer]); ``` @@ -290,7 +292,7 @@ workerInstance.onerror = function(e) { ### onmessage -onmessage?: (event: MessageEvent) => void +onmessage?: (event: MessageEvent\) => void Defines the event handler to be called when the host thread receives a message sent by the worker thread through **parentPort.postMessage**. The event handler is executed in the host thread. @@ -316,7 +318,7 @@ workerInstance.onmessage = function(e) { ### onmessageerror -onmessageerror?: (event: MessageEvent) => void +onmessageerror?: (event: MessageEvent\) => void Defines the event handler to be called when the worker thread receives a message that cannot be serialized. The event handler is executed in the host thread. @@ -503,7 +505,7 @@ parentPort.onmessage = function(e) { ### onmessage -onmessage?: (event: MessageEvent) => void +onmessage?: (event: MessageEvent\) => void Defines the event handler to be called when the worker thread receives a message sent by the host thread through **worker.postMessage**. The event handler is executed in the worker thread. @@ -535,7 +537,7 @@ parentPort.onmessage = function(e) { ### onmessageerror -onmessageerror?: (event: MessageEvent) => void +onmessageerror?: (event: MessageEvent\) => void Defines the event handler to be called when the worker thread receives a message that cannot be deserialized. The event handler is executed in the worker thread. @@ -780,3 +782,7 @@ Configuration of the **build-profile.json5** file: } } ``` + +## Precautions +Currently, a maximum of seven workers can co-exist. +If the number of workers exceeds the upper limit, the error message "Too many workers, the number of workers exceeds the maximum." is displayed. diff --git a/en/application-dev/reference/apis/js-apis-xml.md b/en/application-dev/reference/apis/js-apis-xml.md index 7544a074dd9261a349698e813ac1b82b77a6ab66..078c1dc0009329300ab7458a7672b63c76271f61 100644 --- a/en/application-dev/reference/apis/js-apis-xml.md +++ b/en/application-dev/reference/apis/js-apis-xml.md @@ -32,9 +32,9 @@ A constructor used to create an **XmlSerializer** instance. **Example** ```js -var arrayBuffer = new ArrayBuffer(1024); -var bufView = new DataView(arrayBuffer); -var thatSer = new xml.XmlSerializer(bufView); +let arrayBuffer = new ArrayBuffer(1024); +let bufView = new DataView(arrayBuffer); +let thatSer = new xml.XmlSerializer(bufView); ``` @@ -56,9 +56,9 @@ Sets an attribute. **Example** ```js -var arrayBuffer = new ArrayBuffer(1024); -var bufView = new DataView(arrayBuffer); -var thatSer = new xml.XmlSerializer(bufView); +let arrayBuffer = new ArrayBuffer(1024); +let bufView = new DataView(arrayBuffer); +let thatSer = new xml.XmlSerializer(bufView); thatSer.setAttributes("importance", "high"); ``` @@ -80,9 +80,9 @@ Adds an empty element. **Example** ```js -var arrayBuffer = new ArrayBuffer(1024); -var bufView = new DataView(arrayBuffer); -var thatSer = new xml.XmlSerializer(bufView); +let arrayBuffer = new ArrayBuffer(1024); +let bufView = new DataView(arrayBuffer); +let thatSer = new xml.XmlSerializer(bufView); thatSer.addEmptyElement("b"); // => ``` @@ -98,9 +98,9 @@ Sets a declaration. **Example** ```js -var arrayBuffer = new ArrayBuffer(1024); -var bufView = new DataView(arrayBuffer); -var thatSer = new xml.XmlSerializer(bufView); +let arrayBuffer = new ArrayBuffer(1024); +let bufView = new DataView(arrayBuffer); +let thatSer = new xml.XmlSerializer(bufView); thatSer.setDeclaration() // => ; ``` @@ -122,8 +122,8 @@ Writes the start tag based on the given element name. **Example** ```js -var arrayBuffer = new ArrayBuffer(1024); -var thatSer = new xml.XmlSerializer(arrayBuffer); +let arrayBuffer = new ArrayBuffer(1024); +let thatSer = new xml.XmlSerializer(arrayBuffer); thatSer.startElement("notel"); thatSer.endElement();// => ''; ``` @@ -140,9 +140,9 @@ Writes the end tag of the element. **Example** ```js -var arrayBuffer = new ArrayBuffer(1024); -var bufView = new DataView(arrayBuffer); -var thatSer = new xml.XmlSerializer(bufView); +let arrayBuffer = new ArrayBuffer(1024); +let bufView = new DataView(arrayBuffer); +let thatSer = new xml.XmlSerializer(bufView); thatSer.setNamespace("h", "http://www.w3.org/TR/html4/"); thatSer.startElement("table"); thatSer.setAttributes("importance", "high"); @@ -169,8 +169,8 @@ Sets the namespace for an element tag. **Example** ```js -var arrayBuffer = new ArrayBuffer(1024); -var thatSer = new xml.XmlSerializer(arrayBuffer); +let arrayBuffer = new ArrayBuffer(1024); +let thatSer = new xml.XmlSerializer(arrayBuffer); thatSer.setDeclaration(); thatSer.setNamespace("h", "http://www.w3.org/TR/html4/"); thatSer.startElement("note"); @@ -194,8 +194,8 @@ Sets the comment. **Example** ```js -var arrayBuffer = new ArrayBuffer(1024); -var thatSer = new xml.XmlSerializer(arrayBuffer); +let arrayBuffer = new ArrayBuffer(1024); +let thatSer = new xml.XmlSerializer(arrayBuffer); thatSer.startElement("note"); thatSer.setComment("Hi!"); thatSer.endElement(); // => '\r\n \r\n'; @@ -219,8 +219,8 @@ Sets CDATA attributes. **Example** ```js -var arrayBuffer = new ArrayBuffer(1028); -var thatSer = new xml.XmlSerializer(arrayBuffer); +let arrayBuffer = new ArrayBuffer(1028); +let thatSer = new xml.XmlSerializer(arrayBuffer); thatSer.setCDATA('root SYSTEM') // => ''; ``` @@ -242,8 +242,8 @@ Sets **Text**. **Example** ```js -var arrayBuffer = new ArrayBuffer(1024); -var thatSer = new xml.XmlSerializer(arrayBuffer); +let arrayBuffer = new ArrayBuffer(1024); +let thatSer = new xml.XmlSerializer(arrayBuffer); thatSer.startElement("note"); thatSer.setAttributes("importance", "high"); thatSer.setText("Happy1"); @@ -268,8 +268,8 @@ Sets **DocType**. **Example** ```js -var arrayBuffer = new ArrayBuffer(1024); -var thatSer = new xml.XmlSerializer(arrayBuffer); +let arrayBuffer = new ArrayBuffer(1024); +let thatSer = new xml.XmlSerializer(arrayBuffer); thatSer.setDocType('root SYSTEM'); // => ''; ``` @@ -295,20 +295,20 @@ Creates and returns an **XmlPullParser** object. The **XmlPullParser** object pa **Example** ```js -var strXml = +let strXml = '' + '' + ' Happy' + ' Work' + ' Play' + ''; -var arrayBuffer = new ArrayBuffer(strXml.length*2); -var bufView = new Uint8Array(arrayBuffer); -var strLen = strXml.length; +let arrayBuffer = new ArrayBuffer(strXml.length); +let bufView = new Uint8Array(arrayBuffer); +let strLen = strXml.length; for (var i = 0; i < strLen; ++i) { bufView[i] = strXml.charCodeAt(i);// Set the ArrayBuffer mode. } -var that = new xml.XmlPullParser(arrayBuffer); +let that = new xml.XmlPullParser(arrayBuffer); ``` @@ -329,30 +329,30 @@ Parses XML information. **Example** ```js -var strXml = +let strXml = '' + '' + ' Happy' + ' Work' + ' Play' + ''; -var arrayBuffer = new ArrayBuffer(strXml.length*2); -var bufView = new Uint8Array(arrayBuffer); -var strLen = strXml.length; +let arrayBuffer = new ArrayBuffer(strXml.length); +let bufView = new Uint8Array(arrayBuffer); +let strLen = strXml.length; for (var i = 0; i < strLen; ++i) { bufView[i] = strXml.charCodeAt(i); } -var that = new xml.XmlPullParser(arrayBuffer); -var arrTag = {}; -var str = ""; -var i = 0; +let that = new xml.XmlPullParser(arrayBuffer); +let arrTag = {}; +let str = ""; +let i = 0; function func(key, value){ arrTag[i] = 'key:'+key+' value:'+ value.getDepth(); str += arrTag[i]; i++; return true; // Determines whether to continuely parse, which is used to continue or terminate parsing. } -var options = {supportDoctype:true, ignoreNameSpace:true, tokenValueCallbackFunction:func} +let options = {supportDoctype:true, ignoreNameSpace:true, tokenValueCallbackFunction:func} that.parse(options); console.log(str); // Output: @@ -387,7 +387,7 @@ Provides APIs to manage the parsed XML information. getColumnNumber(): number -Obtains the column line number, which starts from 1. +Obtains the column line number, starting from 1. **System capability**: SystemCapability.Utils.Lang diff --git a/en/application-dev/reference/arkui-js/js-components-common-animation.md b/en/application-dev/reference/arkui-js/js-components-common-animation.md index 24676a73232a85ae609e6ea07b403bdd78961bb4..72969d608a86f4ce8fdf8ad2eb95431e18b93528 100644 --- a/en/application-dev/reference/arkui-js/js-components-common-animation.md +++ b/en/application-dev/reference/arkui-js/js-components-common-animation.md @@ -6,20 +6,20 @@ Components support dynamic rotation, translation, and scaling effects. These eff > > The initial APIs of this component are supported since API version 7. Newly added APIs will be marked with a superscript to indicate their earliest API version. -| Name | Type | Default Value | Description | -| ------------------------- | ------------------------------------------------------------ | ------------------------------------- | ------------------------------------------------------------ | -| transform-origin | string6+ \| \ \| \ string6+ \| \ \| \ | center center | Origin position of the transformed element. The unit can be px or a percentage (relative to the animation target component). If only one value is specified, the other one is **50%**. The available values for the first string are **left**, **center**, and **right**. The available values for the second string are **top**, **center**, and **bottom**.
Example:
transform-origin: 200px 30%
transform-origin: 100px topt
ransform-origin: center center | -| transform | string | - | Translation, rotation, and scaling attributes.
For details, see **transform**. | -| animation6+ | string | 0s ease 0s 1 normal none running none | Animation attributes in the format of **duration \| timing-function \| delay \| iteration-count \| direction \| fill-mode \| play-state \| name**. The order of the parameters is not specified, but the **duration** and **delay** parameters are parsed based on where they are placed. | -| animation-name | string | - | @keyframes rule. For details, see **@keyframes**. | -| animation-delay | \