提交 27cb16a2 编写于 作者: Z zengyawen 提交者: Gitee

Merge branch 'master' of gitee.com:openharmony/docs into master

Signed-off-by: Nzengyawen <zengyawen1@huawei.com>
...@@ -6,7 +6,7 @@ Your applications can use the APIs provided by the **mediaLibrary** module to pe ...@@ -6,7 +6,7 @@ Your applications can use the APIs provided by the **mediaLibrary** module to pe
> >
> Before developing features, read [MediaLibrary Overview](medialibrary-overview.md) to learn how to obtain a **MediaLibrary** instance and request the permissions to call the APIs of **MediaLibrary**. > Before developing features, read [MediaLibrary Overview](medialibrary-overview.md) to learn how to obtain a **MediaLibrary** instance and request the permissions to call the APIs of **MediaLibrary**.
To ensure the application running efficiency, most **MediaLibrary** API calls are asynchronous, and both callback and promise modes are provided for these APIs. The following code samples use the promise mode. For details about the APIs, see [MediaLibrary API Reference](../reference/apis/js-apis-medialibrary.md). To maximize the application running efficiency, most **MediaLibrary** API calls are asynchronous in callback or promise mode. The following code samples use the promise mode. For details about the APIs, see [MediaLibrary API Reference](../reference/apis/js-apis-medialibrary.md).
## Querying Media Assets ## Querying Media Assets
...@@ -215,7 +215,7 @@ async function getCameraImagePromise() { ...@@ -215,7 +215,7 @@ async function getCameraImagePromise() {
## Obtaining the Thumbnail of an Image or a Video ## Obtaining the Thumbnail of an Image or a Video
You can call [FileAsset.getThumbnail](../reference/apis/js-apis-medialibrary.md#getthumbnail8-2) with the thumbnail size passed in to obtain the thumbnail of an image or a video. Thumbnails are usually displayed on the UI. You can call [FileAsset.getThumbnail](../reference/apis/js-apis-medialibrary.md#getthumbnail8-2) with the thumbnail size passed in to obtain the thumbnail of an image or a video. Your application can use thumbnails to offer a quick preview on images and videos.
**Prerequisites** **Prerequisites**
...@@ -224,8 +224,6 @@ You can call [FileAsset.getThumbnail](../reference/apis/js-apis-medialibrary.md# ...@@ -224,8 +224,6 @@ You can call [FileAsset.getThumbnail](../reference/apis/js-apis-medialibrary.md#
### Obtaining the Thumbnail of an Image ### Obtaining the Thumbnail of an Image
Your application may need to obtain the thumbnail of an image for preview purposes.
The following describes how to obtain the thumbnail (size: 720 x 720) of the first image in the album. The following describes how to obtain the thumbnail (size: 720 x 720) of the first image in the album.
**How to Develop** **How to Develop**
...@@ -273,7 +271,7 @@ You can call [MediaLibrary.createAsset](../reference/apis/js-apis-medialibrary.m ...@@ -273,7 +271,7 @@ You can call [MediaLibrary.createAsset](../reference/apis/js-apis-medialibrary.m
- You have obtained a **MediaLibrary** instance. - You have obtained a **MediaLibrary** instance.
- You have granted the permission **ohos.permission.WRITE_MEDIA**. - You have granted the permission **ohos.permission.WRITE_MEDIA**.
- [Obtain the public directory](medialibrary-filepath-guidelines.md). - [You have obtained a public directory](medialibrary-filepath-guidelines.md).
The following describes how to create a file of the **MediaType.FILE** type. The following describes how to create a file of the **MediaType.FILE** type.
...@@ -296,7 +294,7 @@ async function example() { ...@@ -296,7 +294,7 @@ async function example() {
You can use [FileAsset.trash](../reference/apis/js-apis-medialibrary.md#trash8) to move a media asset to the recycle bin. You can use [FileAsset.trash](../reference/apis/js-apis-medialibrary.md#trash8) to move a media asset to the recycle bin.
By default, files in the recycle bin will be stored for 30 days. During this period, you can set **isTrash** in **trash** to **false** to recover the files from the recycle bin. Application users can also recover the files through the system applications **Files** or **Gallery**. By default, files in the recycle bin will be stored for 30 days before being permanently removed. During this period, you can set **isTrash** in **trash** to **false** to recover the files. Application users can also recover the files through the system applications **Files** or **Gallery**.
**Prerequisites** **Prerequisites**
...@@ -339,11 +337,9 @@ async function example() { ...@@ -339,11 +337,9 @@ async function example() {
## Renaming a Media Asset ## Renaming a Media Asset
Renaming modifies the **FileAsset.displayName** attribute of a file, that is, the displayed file name, including the file name extension. To rename a media asset, modify the **FileAsset.displayName** attribute (which specifies the displayed file name, including the file name extension) and commit the modification through [FileAsset.commitModify](../reference/apis/js-apis-medialibrary.md#commitmodify8-1).
After the modification, call [FileAsset.commitModify](../reference/apis/js-apis-medialibrary.md#commitmodify8-1) to commit the modification to the database.
Before renaming a file, you must call [FetchFileResult](../reference/apis/js-apis-medialibrary.md#fetchfileresult7) to obtain the file. Before renaming a file, you must obtain the file, for example, by calling [FetchFileResult](../reference/apis/js-apis-medialibrary.md#fetchfileresult7).
**Prerequisites** **Prerequisites**
...@@ -358,7 +354,7 @@ The following describes how to rename the first file in the result set as **newt ...@@ -358,7 +354,7 @@ The following describes how to rename the first file in the result set as **newt
2. Call **getFileAssets** to obtain the images in the target album. 2. Call **getFileAssets** to obtain the images in the target album.
3. Call **getFirstObject** to obtain the first image among all the images obtained. 3. Call **getFirstObject** to obtain the first image among all the images obtained.
4. Rename the image as **newImage.jpg**. 4. Rename the image as **newImage.jpg**.
5. Call **FileAsset.commitModify** to commit the modification of the attributes to the database. 5. Call **FileAsset.commitModify** to commit the modification to the database.
```ts ```ts
async function example() { async function example() {
......
此差异已折叠。
# AVSession Overview
## Overview
AVSession, short for audio and video session, is also known as media session.
- Application developers can use the APIs provided by the **AVSession** module to connect their audio and video applications to the system's Media Controller.
- System developers can use the APIs provided by the **AVSession** module to display media information of system audio and video applications and carry out unified playback control.
You can implement the following features through the **AVSession** module:
1. Unified playback control entry
If there are multiple audio and video applications on the device, users need to switch to and access different applications to control media playback. With AVSession, a unified playback control entry of the system (such as Media Controller) is used for playback control of these audio and video applications. No more switching is required.
2. Better background application management
When an application running in the background automatically starts audio playback, it is difficult for users to locate the application. With AVSession, users can quickly find the application that plays the audio clip in Media Controller.
## Basic Concepts
- AVSession
A channel used for information exchange between applications and Media Controller. For AVSession, one end is the media application under control, and the other end is Media Controller. Through AVSession, an application can transfer the media playback information to Media Controller and receive control commands from Media Controller.
- AVSessionController
Object that controls media sessions and thereby controls the playback behavior of applications. Through AVSessionController, Media Controller can control the playback behavior of applications, obtain playback information, and send control commands. It can also monitor the playback state of applications to ensure synchronization of the media session information.
- Media Controller
Holder of AVSessionController. Through AVSessionController, Media Controller sends commands to control media playback of applications.
## Implementation Principle
The **AVSession** module provides two classes: **AVSession** and **AVSessionController**.
**Figure 1** AVSession interaction
![en-us_image_avsession](figures/en-us_image_avsession.png)
- Interaction between the application and Media Controller: First, an audio application creates an **AVSession** object and sets session information, including media metadata, launcher ability, and playback state information. Then, Media Controller creates an **AVSessionController** object to obtain session-related information and send the 'play' command to the audio application. Finally, the audio application responds to the command and updates the playback state.
- Distributed projection: When a connected device creates a local session, Media Controller or the audio application can select another device to be projected based on the device list, synchronize the local session to the remote device, and generate a controllable remote session. The remote session is controlled by sending control commands to the remote device's application through its AVSessionController.
## Constraints
- The playback information displayed in Media Controller is the media information proactively written by the media application to AVSession.
- Media Controller controls the playback of a media application based on the responses of the media application to control commands.
- AVSession can transmit media playback information and control commands. It does not display information or execute control commands.
- Do not develop Media Controller for common applications. For common audio and video applications running on OpenHarmony, the default control end is Media Controller, which is a system application. You do not need to carry out additional development for Media Controller.
- If you want to develop your own system running OpenHarmony, you can develop your own Media Controller.
- For better background management of audio and video applications, the **AVSession** module enforces background control for third-party applications. Only third-party applications that have accessed AVSession can play audio in the background. Otherwise, the system forcibly pauses the playback when a third-party application switches to the background.
此差异已折叠。
# AVSession Management Error Codes
## 6600101 Session Service Exception
**Error Message**
Session service exception
**Description**
The session service is abnormal, and the application cannot obtain a response from the session service. For example, the session service is not running or the communication with the session service fails.
**Possible Causes**
The session service is killed during session restart.
**Solution**
1. The system retries the operation automatically. If the error persists for 3 seconds or more, stop the operation on the session or controller.
2. Destroy the current session or session controller and re-create it. If the re-creation fails, stop the operation on the session.
## 6600102 Session Does Not Exist
**Error Message**
The session does not exist
**Description**
Parameters are set for or commands are sent to the session that does not exist.
**Possible Causes**
The session has been destroyed, and no session record exists on the server.
**Solution**
1. If the error occurs on the application, re-create the session. If the error occurs on Media Controller, stop sending query or control commands to the session.
2. If the error occurs on the session service, query the current session record and pass the correct session ID when creating the controller.
## 6600103 Session Controller Does Not Exist
**Error Message**
The session controller does not exist
**Description**
A control command or an event is sent to the controller that does not exist.
**Possible Causes**
The controller has been destroyed.
**Solution**
Query the session record and create the corresponding controller.
## 6600104 Remote Session Connection Failure
**Error Message**
The remote session connection failed
**Description**
The communication between the local session and the remote session fails.
**Possible Causes**
The communication between devices is interrupted.
**Solution**
Stop sending control commands to the session. Subscribe to output device changes, and resume the sending when the output device is changed.
## 6600105 Invalid Session Command
**Error Message**
Invalid session command
**Description**
The control command or event sent to the session is not supported.
**Possible Causes**
The session does not support this command.
**Solution**
Stop sending the command or event. Query the commands supported by the session, and send a command supported.
## 6600106 Session Not Activated
**Error Message**
The session not active
**Description**
A control command or event is sent to the session that is not activated.
**Possible Causes**
The session is in the inactive state.
**Solution**
Stop sending the command or event. Subscribe to the session activation status, and resume the sending when the session is activated.
## 6600107 Too Many Commands or Events
**Error Message**
Command or event overload
**Description**
The session client sends too many messages or commands to the server in a period of time, causing the server to be overloaded.
**Possible Causes**
The server is overloaded with messages or events.
**Solution**
Control the frequency of sending commands or events.
...@@ -11,7 +11,7 @@ You only need to perform operations in [Resource Files](#resource-files) and [Re ...@@ -11,7 +11,7 @@ You only need to perform operations in [Resource Files](#resource-files) and [Re
Resource files store application content in multiple languages. This framework uses JSON files to store resource definitions. Place the resource file of each locale in the i18n directory described in [File Organization](../ui/js-framework-file.md). Resource files store application content in multiple languages. This framework uses JSON files to store resource definitions. Place the resource file of each locale in the i18n directory described in [File Organization](../ui/js-framework-file.md).
Resource files should be named in _language-script-region_.json format. For example, the resource file for Hong Kong Chinese in the traditional script is named zh-Hant-HK. You can omit the region, for example, zh-CN for simplified Chinese, or omit both the script and region, for example, zh for Chinese. Resource files should be named in _language-script-region_.json format. For example, the resource file for Hong Kong(China) in the traditional script is named zh-Hant-HK. You can omit the region, for example, zh-CN for simplified Chinese, or omit both the script and region, for example, zh for Chinese.
``` ```
......
...@@ -57,7 +57,8 @@ In the stage model, the main window of an application is created and maintained ...@@ -57,7 +57,8 @@ In the stage model, the main window of an application is created and maintained
1. Obtain the main window. 1. Obtain the main window.
Call **getMainWindow** to obtain the main window of the application.
Call **getMainWindow** to obtain the main window of the application.
2. Set the properties of the main window. 2. Set the properties of the main window.
...@@ -83,21 +84,21 @@ class MainAbility extends Ability { ...@@ -83,21 +84,21 @@ class MainAbility extends Ability {
console.info('Succeeded in obtaining the main window. Data: ' + JSON.stringify(data)); console.info('Succeeded in obtaining the main window. Data: ' + JSON.stringify(data));
// 2. Set the touchable property of the main window. // 2. Set the touchable property of the main window.
let isTouchable = true; let isTouchable = true;
windowClass.setTouchable(isTouchable, (err, data) => { windowClass.setTouchable(isTouchable, (err) => {
if (err.code) { if (err.code) {
console.error('Failed to set the window to be touchable. Cause:' + JSON.stringify(err)); console.error('Failed to set the window to be touchable. Cause:' + JSON.stringify(err));
return; return;
} }
console.info('Succeeded in setting the window to be touchable. Data:' + JSON.stringify(data)); console.info('Succeeded in setting the window to be touchable.');
}) })
}) })
// 3. Load the page content to the main window. // 3. Load the page content to the main window.
windowStage.loadContent("pages/page2", (err, data) => { windowStage.loadContent("pages/page2", (err) => {
if (err.code) { if (err.code) {
console.error('Failed to load the content. Cause:' + JSON.stringify(err)); console.error('Failed to load the content. Cause:' + JSON.stringify(err));
return; return;
} }
console.info('Succeeded in loading the content. Data: ' + JSON.stringify(data)); console.info('Succeeded in loading the content.');
}); });
} }
}; };
...@@ -111,11 +112,10 @@ You can create an application subwindow, such as a dialog box, and set its prope ...@@ -111,11 +112,10 @@ You can create an application subwindow, such as a dialog box, and set its prope
### How to Develop ### How to Develop
1. Create or obtain a subwindow. 1. Create a subwindow.
Call **createSubWindow** to create a subwindow.
Call **getSubWindow** to obtain a subwindow. Call **createSubWindow** to create a subwindow.
2. Set the properties of the subwindow. 2. Set the properties of the subwindow.
...@@ -144,44 +144,35 @@ Call **getSubWindow** to obtain a subwindow. ...@@ -144,44 +144,35 @@ Call **getSubWindow** to obtain a subwindow.
} }
sub_windowClass = data; sub_windowClass = data;
console.info('Succeeded in creating the subwindow. Data: ' + JSON.stringify(data)); console.info('Succeeded in creating the subwindow. Data: ' + JSON.stringify(data));
// 1. Obtain an available subwindow.
windowStage_.getSubWindow((err, data) => {
if (err.code) {
console.error('Failed to obtain the subWindow. Cause:' + JSON.stringify(err));
return;
}
console.info('Succeeded in obtaining the subWindow. Data: ' + JSON.stringify(data));
sub_windowClass = data;
});
// 2. Set the position, size, and other properties of the subwindow. // 2. Set the position, size, and other properties of the subwindow.
sub_windowClass.moveTo(300, 300, (err, data) => { sub_windowClass.moveTo(300, 300, (err) => {
if (err.code) { if (err.code) {
console.error('Failed to move the window. Cause:' + JSON.stringify(err)); console.error('Failed to move the window. Cause:' + JSON.stringify(err));
return; return;
} }
console.info('Succeeded in moving the window. Data: ' + JSON.stringify(data)); console.info('Succeeded in moving the window.');
}); });
sub_windowClass.resetSize(500, 1000, (err, data) => { sub_windowClass.resetSize(500, 1000, (err) => {
if (err.code) { if (err.code) {
console.error('Failed to change the window size. Cause:' + JSON.stringify(err)); console.error('Failed to change the window size. Cause:' + JSON.stringify(err));
return; return;
} }
console.info('Succeeded in changing the window size. Data: ' + JSON.stringify(data)); console.info('Succeeded in changing the window size.');
}); });
// 3. Load the page content to the subwindow. // 3. Load the page content to the subwindow.
sub_windowClass.loadContent("pages/page3", (err, data) => { sub_windowClass.loadContent("pages/page3", (err) => {
if (err.code) { if (err.code) {
console.error('Failed to load the content. Cause:' + JSON.stringify(err)); console.error('Failed to load the content. Cause:' + JSON.stringify(err));
return; return;
} }
console.info('Succeeded in loading the content. Data: ' + JSON.stringify(data)); console.info('Succeeded in loading the content.');
// 3. Show the subwindow. // 3. Show the subwindow.
sub_windowClass.show((err, data) => { sub_windowClass.show((err) => {
if (err.code) { if (err.code) {
console.error('Failed to show the window. Cause:' + JSON.stringify(err)); console.error('Failed to show the window. Cause: ' + JSON.stringify(err));
return; return;
} }
console.info('Succeeded in showing the window. Data: ' + JSON.stringify(data)); console.info('Succeeded in showing the window.');
}); });
}); });
}) })
...@@ -189,18 +180,18 @@ Call **getSubWindow** to obtain a subwindow. ...@@ -189,18 +180,18 @@ Call **getSubWindow** to obtain a subwindow.
destroySubWindow() { destroySubWindow() {
// 4. Destroy the subwindow when it is no longer needed (depending on the service logic). // 4. Destroy the subwindow when it is no longer needed (depending on the service logic).
sub_windowClass.destroy((err, data) => { sub_windowClass.destroy((err) => {
if (err.code) { if (err.code) {
console.error('Failed to destroy the window. Cause: ' + JSON.stringify(err)); console.error('Failed to destroy the window. Cause: ' + JSON.stringify(err));
return; return;
} }
console.info('Succeeded in destroying the window. Data: ' + JSON.stringify(data)); console.info('Succeeded in destroying the window.');
}); });
} }
onWindowStageCreate(windowStage) { onWindowStageCreate(windowStage) {
windowStage_ = windowStage; windowStage_ = windowStage;
// Create the subwindow when it is needed, for example, when a click event occurs in the main window. Calling onWindowStageCreate is not always necessary. The code here is for reference only. // Create a subwindow when it is needed, for example, when a click event occurs in the main window. Calling onWindowStageCreate is not always necessary. The code here is for reference only.
this.showSubWindow(); this.showSubWindow();
} }
...@@ -221,7 +212,8 @@ To create a better video watching and gaming experience, you can use the immersi ...@@ -221,7 +212,8 @@ To create a better video watching and gaming experience, you can use the immersi
1. Obtain the main window. 1. Obtain the main window.
Call **getMainWindow** to obtain the main window of the application.
Call **getMainWindow** to obtain the main window of the application.
2. Implement the immersive effect. You can use any of the following methods: 2. Implement the immersive effect. You can use any of the following methods:
- Method 1: Call **setFullScreen** to set the main window to be displayed in full screen. In this case, the navigation bar and status bar are hidden. - Method 1: Call **setFullScreen** to set the main window to be displayed in full screen. In this case, the navigation bar and status bar are hidden.
...@@ -249,30 +241,30 @@ Call **getMainWindow** to obtain the main window of the application. ...@@ -249,30 +241,30 @@ Call **getMainWindow** to obtain the main window of the application.
// 2. Use method 1 to implement the immersive effect. // 2. Use method 1 to implement the immersive effect.
let isFullScreen = true; let isFullScreen = true;
windowClass.setFullScreen(isFullScreen, (err, data) => { windowClass.setFullScreen(isFullScreen, (err) => {
if (err.code) { if (err.code) {
console.error('Failed to enable the full-screen mode. Cause:' + JSON.stringify(err)); console.error('Failed to enable the full-screen mode. Cause:' + JSON.stringify(err));
return; return;
} }
console.info('Succeeded in enabling the full-screen mode. Data: ' + JSON.stringify(data)); console.info('Succeeded in enabling the full-screen mode.');
}); });
// 2. Use method 2 to implement the immersive effect. // 2. Use method 2 to implement the immersive effect.
let names = []; let names = [];
windowClass.setSystemBarEnable(names, (err, data) => { windowClass.setSystemBarEnable(names, (err) => {
if (err.code) { if (err.code) {
console.error('Failed to set the system bar to be visible. Cause:' + JSON.stringify(err)); console.error('Failed to set the system bar to be visible. Cause:' + JSON.stringify(err));
return; return;
} }
console.info('Succeeded in setting the system bar to be visible. Data: ' + JSON.stringify(data)); console.info('Succeeded in setting the system bar to be visible.');
}); });
// 2. Use method 3 to implement the immersive effect. // 2. Use method 3 to implement the immersive effect.
let isLayoutFullScreen = true; let isLayoutFullScreen = true;
windowClass.setLayoutFullScreen(isLayoutFullScreen, (err, data) => { windowClass.setLayoutFullScreen(isLayoutFullScreen, (err) => {
if (err.code) { if (err.code) {
console.error('Failed to set the window layout to full-screen mode. Cause:' + JSON.stringify(err)); console.error('Failed to set the window layout to full-screen mode. Cause:' + JSON.stringify(err));
return; return;
} }
console.info('Succeeded in setting the window layout to full-screen mode. Data: ' + JSON.stringify(data)); console.info('Succeeded in setting the window layout to full-screen mode.');
}); });
let sysBarProps = { let sysBarProps = {
statusBarColor: '#ff00ff', statusBarColor: '#ff00ff',
...@@ -281,21 +273,21 @@ Call **getMainWindow** to obtain the main window of the application. ...@@ -281,21 +273,21 @@ Call **getMainWindow** to obtain the main window of the application.
statusBarContentColor: '#ffffff', statusBarContentColor: '#ffffff',
navigationBarContentColor: '#ffffff' navigationBarContentColor: '#ffffff'
}; };
windowClass.setSystemBarProperties(sysBarProps, (err, data) => { windowClass.setSystemBarProperties(sysBarProps, (err) => {
if (err.code) { if (err.code) {
console.error('Failed to set the system bar properties. Cause: ' + JSON.stringify(err)); console.error('Failed to set the system bar properties. Cause: ' + JSON.stringify(err));
return; return;
} }
console.info('Succeeded in setting the system bar properties. Data: ' + JSON.stringify(data)); console.info('Succeeded in setting the system bar properties.');
}); });
}) })
// 3. Load the page content to the immersive window. // 3. Load the page content to the immersive window.
windowStage.loadContent("pages/page2", (err, data) => { windowStage.loadContent("pages/page2", (err) => {
if (err.code) { if (err.code) {
console.error('Failed to load the content. Cause:' + JSON.stringify(err)); console.error('Failed to load the content. Cause:' + JSON.stringify(err));
return; return;
} }
console.info('Succeeded in loading the content. Data: ' + JSON.stringify(data)); console.info('Succeeded in loading the content.');
}); });
} }
}; };
...@@ -311,7 +303,7 @@ A floating window is created based on an existing task. It is always displayed i ...@@ -311,7 +303,7 @@ A floating window is created based on an existing task. It is always displayed i
1. Apply for permissions. 1. Apply for permissions.
To create a floating window (of the **WindowType.TYPE_FLOAT** type), you must configure the **ohos.permission.SYSTEM_FLOAT_WINDOW** permission in the **requestPermissions** field of the **module.json5** file. For details about the file, see [Application Package Structure Configuration File](../quick-start/stage-structure.md). To create a floating window (of the **WindowType.TYPE_FLOAT** type), you must configure the **ohos.permission.SYSTEM_FLOAT_WINDOW** permission in the **requestPermissions** field of the **module.json5** file. For details about the file, see [Application Package Structure Configuration File](../quick-start/stage-structure.md).
> **NOTE** > **NOTE**
> >
...@@ -368,43 +360,43 @@ To create a floating window (of the **WindowType.TYPE_FLOAT** type), you must co ...@@ -368,43 +360,43 @@ To create a floating window (of the **WindowType.TYPE_FLOAT** type), you must co
console.info('Succeeded in creating the floatWindow. Data: ' + JSON.stringify(data)); console.info('Succeeded in creating the floatWindow. Data: ' + JSON.stringify(data));
windowClass = data; windowClass = data;
// 3. Set the position, size, and properties of the floating window. // 3. Set the position, size, and properties of the floating window.
windowClass.moveTo(300, 300, (err, data) => { windowClass.moveTo(300, 300, (err) => {
if (err.code) { if (err.code) {
console.error('Failed to move the window. Cause:' + JSON.stringify(err)); console.error('Failed to move the window. Cause:' + JSON.stringify(err));
return; return;
} }
console.info('Succeeded in moving the window. Data: ' + JSON.stringify(data)); console.info('Succeeded in moving the window.');
}); });
windowClass.resetSize(500, 1000, (err, data) => { windowClass.resetSize(500, 1000, (err) => {
if (err.code) { if (err.code) {
console.error('Failed to change the window size. Cause:' + JSON.stringify(err)); console.error('Failed to change the window size. Cause:' + JSON.stringify(err));
return; return;
} }
console.info('Succeeded in changing the window size. Data: ' + JSON.stringify(data)); console.info('Succeeded in changing the window size.');
}); });
// 4. Load the page content to the floating window. // 4. Load the page content to the floating window.
windowClass.loadContent("pages/page4", (err, data) => { windowClass.loadContent("pages/page4", (err) => {
if (err.code) { if (err.code) {
console.error('Failed to load the content. Cause:' + JSON.stringify(err)); console.error('Failed to load the content. Cause:' + JSON.stringify(err));
return; return;
} }
console.info('Succeeded in loading the content. Data: ' + JSON.stringify(data)); console.info('Succeeded in loading the content.');
// 4. Show the floating window. // 4. Show the floating window.
windowClass.show((err, data) => { windowClass.show((err) => {
if (err.code) { if (err.code) {
console.error('Failed to show the window. Cause: ' + JSON.stringify(err)); console.error('Failed to show the window. Cause: ' + JSON.stringify(err));
return; return;
} }
console.info('Succeeded in showing the window. Data: ' + JSON.stringify(data)); console.info('Succeeded in showing the window.');
}); });
}); });
// 5. Destroy the floating window when it is no longer needed (depending on the service logic). // 5. Destroy the floating window when it is no longer needed (depending on the service logic).
windowClass.destroy((err, data) => { windowClass.destroy((err) => {
if (err.code) { if (err.code) {
console.error('Failed to destroy the window. Cause: ' + JSON.stringify(err)); console.error('Failed to destroy the window. Cause: ' + JSON.stringify(err));
return; return;
} }
console.info('Succeeded in destroying the window. Data: ' + JSON.stringify(data)); console.info('Succeeded in destroying the window.');
}); });
}); });
} }
......
...@@ -65,46 +65,46 @@ export default class ServiceExtensionAbility1 extends ExtensionContext { ...@@ -65,46 +65,46 @@ export default class ServiceExtensionAbility1 extends ExtensionContext {
console.info('Succeeded in creating the volume window.') console.info('Succeeded in creating the volume window.')
windowClass = data; windowClass = data;
// 2. Change the size and position of the volume bar window, or set its properties such as the background color and brightness. // 2. Change the size and position of the volume bar window, or set its properties such as the background color and brightness.
windowClass.moveTo(300, 300, (err, data) => { windowClass.moveTo(300, 300, (err) => {
if (err.code) { if (err.code) {
console.error('Failed to move the window. Cause:' + JSON.stringify(err)); console.error('Failed to move the window. Cause:' + JSON.stringify(err));
return; return;
} }
console.info('Succeeded in moving the window. Data: ' + JSON.stringify(data)); console.info('Succeeded in moving the window.');
}); });
windowClass.resetSize(500, 1000, (err, data) => { windowClass.resetSize(500, 1000, (err) => {
if (err.code) { if (err.code) {
console.error('Failed to change the window size. Cause:' + JSON.stringify(err)); console.error('Failed to change the window size. Cause:' + JSON.stringify(err));
return; return;
} }
console.info('Succeeded in changing the window size. Data: ' + JSON.stringify(data)); console.info('Succeeded in changing the window size.');
}); });
// 3. Load the page content to the volume bar window. // 3. Load the page content to the volume bar window.
windowClass.loadContent("pages/page_volume", (err, data) => { windowClass.loadContent("pages/page_volume", (err) => {
if (err.code) { if (err.code) {
console.error('Failed to load the content. Cause:' + JSON.stringify(err)); console.error('Failed to load the content. Cause:' + JSON.stringify(err));
return; return;
} }
console.info('Succeeded in loading the content. Data: ' + JSON.stringify(data)); console.info('Succeeded in loading the content.');
// 3. Show the volume bar window. // 3. Show the volume bar window.
windowClass.show((err, data) => { windowClass.show((err) => {
if (err.code) { if (err.code) {
console.error('Failed to show the window. Cause:' + JSON.stringify(err)); console.error('Failed to show the window. Cause:' + JSON.stringify(err));
return; return;
} }
console.info('Succeeded in showing the window. Data: ' + JSON.stringify(data)); console.info('Succeeded in showing the window.');
}); });
}); });
// 4. Hide or destroy the volume bar window. // 4. Hide or destroy the volume bar window.
// Hide the volume bar window when a click event outside the window is detected. // Hide the volume bar window when a click event outside the window is detected.
windowClass.on('touchOutside', () => { windowClass.on('touchOutside', () => {
console.info('touch outside'); console.info('touch outside');
windowClass.hide((err, data) => { windowClass.hide((err) => {
if (err.code) { if (err.code) {
console.error('Failed to hide the window. Cause: ' + JSON.stringify(err)); console.error('Failed to hide the window. Cause: ' + JSON.stringify(err));
return; return;
} }
console.info('Succeeded in hidinging the window. Data: ' + JSON.stringify(data)); console.info('Succeeded in hidinging the window.');
}); });
}); });
}); });
......
...@@ -63,4 +63,8 @@ You are advised to use the stage model for window development. ...@@ -63,4 +63,8 @@ You are advised to use the stage model for window development.
## Constraints ## Constraints
You cannot develop system windows in the FA model. - You cannot develop system windows in the FA model.
- The main window and subwindow have the following size limits: [320, 2560] in width and [240, 2560] in height, both in units of vp.
- The system window has the following size limits: [0, 2560] in width and [0, 2560] in height, both in units of vp.
...@@ -3,32 +3,29 @@ ...@@ -3,32 +3,29 @@
OpenHarmony系统传感器是应用访问底层硬件传感器的一种设备抽象概念。开发者根据传感器提供的[Sensor接口](../reference/apis/js-apis-sensor.md),可以查询设备上的传感器,订阅传感器数据,并根据传感器数据定制相应的算法开发各类应用,比如指南针、运动健康、游戏等。 OpenHarmony系统传感器是应用访问底层硬件传感器的一种设备抽象概念。开发者根据传感器提供的[Sensor接口](../reference/apis/js-apis-sensor.md),可以查询设备上的传感器,订阅传感器数据,并根据传感器数据定制相应的算法开发各类应用,比如指南针、运动健康、游戏等。
传感器是指用于侦测环境中所发生事件或变化,并将此消息发送至其他电子设备(如中央处理器)的设备,通常由敏感组件和转换组件组成。传感器是实现物联网智能化的重要基石,为实现全场景智慧化战略,支撑“1+8+N”产品需求,需要构筑统一的传感器管理框架,达到为各产品/业务提供低时延、低功耗的感知数据的目的。下面为传感器列表:
| 传感器类型 | 描述 | 说明 | 主要用途 | | 传感器类型 | 描述 | 说明 | 主要用途 |
| --------------------------------------- | --------- | ---------------------------------------- | -------------------- | | --------------------------- | ------------------ | ------------------------------------------------------------ | ---------------------------------------- |
| SENSOR_TYPE_ACCELEROMETER | 加速度传感器 | 测量三个物理轴(x、y&nbsp;&nbsp;z)上,施加在设备上的加速度(包括重力加速度),单位&nbsp;:&nbsp;m/s² | 检测运动状态 | | ACCELEROMETER | 加速度传感器 | 测量三个物理轴(x、y&nbsp;&nbsp;z)上,施加在设备上的加速度(包括重力加速度),单位&nbsp;:&nbsp;m/s² | 检测运动状态 |
| SENSOR_TYPE_ACCELEROMETER_UNCALIBRATED | 未校准加速度传感器 | 测量三个物理轴(x、y&nbsp;&nbsp;z)上,施加在设备上的未校准的加速度(包括重力加速度),单位&nbsp;:&nbsp;m/s² | 检测加速度偏差估值 | | ACCELEROMETER_UNCALIBRATED | 未校准加速度传感器 | 测量三个物理轴(x、y&nbsp;&nbsp;z)上,施加在设备上的未校准的加速度(包括重力加速度),单位&nbsp;:&nbsp;m/s² | 检测加速度偏差估值 |
| SENSOR_TYPE_LINEAR_ACCELERATION | 线性加速度传感器 | 测量三个物理轴(x、y&nbsp;&nbsp;z)上,施加在设备上的线性加速度(不包括重力加速度),单位&nbsp;:&nbsp;m/s² | 检测每个单轴方向上的线性加速度 | | LINEAR_ACCELERATION | 线性加速度传感器 | 测量三个物理轴(x、y&nbsp;&nbsp;z)上,施加在设备上的线性加速度(不包括重力加速度),单位&nbsp;:&nbsp;m/s² | 检测每个单轴方向上的线性加速度 |
| SENSOR_TYPE_GRAVITY | 重力传感器 | 测量三个物理轴(x、y&nbsp;&nbsp;z)上,施加在设备上的重力加速度,单位&nbsp;:&nbsp;m/s² | 测量重力大小 | | GRAVITY | 重力传感器 | 测量三个物理轴(x、y&nbsp;&nbsp;z)上,施加在设备上的重力加速度,单位&nbsp;:&nbsp;m/s² | 测量重力大小 |
| SENSOR_TYPE_GYROSCOPE | 陀螺仪传感器 | 测量三个物理轴(x、y&nbsp;&nbsp;z)上,设备的旋转角速度,单位&nbsp;:&nbsp;rad/s | 测量旋转的角速度 | | GYROSCOPE | 陀螺仪传感器 | 测量三个物理轴(x、y&nbsp;&nbsp;z)上,设备的旋转角速度,单位&nbsp;:&nbsp;rad/s | 测量旋转的角速度 |
| SENSOR_TYPE_GYROSCOPE_UNCALIBRATED | 未校准陀螺仪传感器 | 测量三个物理轴(x、y&nbsp;&nbsp;z)上,设备的未校准旋转角速度,单位&nbsp;:&nbsp;rad/s | 测量旋转的角速度及偏差估值 | | GYROSCOPE_UNCALIBRATED | 未校准陀螺仪传感器 | 测量三个物理轴(x、y&nbsp;&nbsp;z)上,设备的未校准旋转角速度,单位&nbsp;:&nbsp;rad/s | 测量旋转的角速度及偏差估值 |
| SENSOR_TYPE_SIGNIFICANT_MOTION | 大幅度动作传感器 | 测量三个物理轴(x、y&nbsp;&nbsp;z)上,设备是否存在大幅度运动;如果取值为1则代表存在大幅度运动,取值为0则代表没有大幅度运动 | 用于检测设备是否存在大幅度运动 | | SIGNIFICANT_MOTION | 大幅度动作传感器 | 测量三个物理轴(x、y&nbsp;&nbsp;z)上,设备是否存在大幅度运动;如果取值为1则代表存在大幅度运动,取值为0则代表没有大幅度运动 | 用于检测设备是否存在大幅度运动 |
| SENSOR_TYPE_PEDOMETER_DETECTION | 计步器检测传感器 | 检测用户的计步动作;如果取值为1则代表用户产生了计步行走的动作;取值为0则代表用户没有发生运动 | 用于检测用户是否有计步的动作 | | PEDOMETER_DETECTION | 计步器检测传感器 | 检测用户的计步动作;如果取值为1则代表用户产生了计步行走的动作;取值为0则代表用户没有发生运动 | 用于检测用户是否有计步的动作 |
| SENSOR_TYPE_PEDOMETER | 计步器传感器 | 统计用户的行走步数 | 用于提供用户行走的步数数据 | | PEDOMETER | 计步器传感器 | 统计用户的行走步数 | 用于提供用户行走的步数数据 |
| SENSOR_TYPE_AMBIENT_TEMPERATURE | 环境温度传感器 | 测量环境温度,单位&nbsp;:&nbsp;摄氏度&nbsp;(°C) | 测量环境温度 | | AMBIENT_TEMPERATURE | 环境温度传感器 | 测量环境温度,单位&nbsp;:&nbsp;摄氏度&nbsp;(°C) | 测量环境温度 |
| SENSOR_TYPE_MAGNETIC_FIELD | 磁场传感器 | 测量三个物理轴向(x、y、z)上,环境地磁场,单位&nbsp;:&nbsp;μT | 创建指南针 | | MAGNETIC_FIELD | 磁场传感器 | 测量三个物理轴向(x、y、z)上,环境地磁场,单位&nbsp;:&nbsp;μT | 创建指南针 |
| SENSOR_TYPE_MAGNETIC_FIELD_UNCALIBRATED | 未校准磁场传感器 | 测量三个物理轴向(x、y、z)上,未校准环境地磁场,单位&nbsp;:&nbsp;μT | 测量地磁偏差估值 | | MAGNETIC_FIELD_UNCALIBRATED | 未校准磁场传感器 | 测量三个物理轴向(x、y、z)上,未校准环境地磁场,单位&nbsp;:&nbsp;μT | 测量地磁偏差估值 |
| SENSOR_TYPE_HUMIDITY | 湿度传感器 | 测量环境的相对湿度,以百分比&nbsp;(%)&nbsp;表示 | 监测露点、绝对湿度和相对湿度 | | HUMIDITY | 湿度传感器 | 测量环境的相对湿度,以百分比&nbsp;(%)&nbsp;表示 | 监测露点、绝对湿度和相对湿度 |
| SENSOR_TYPE_BAROMETER | 气压计传感器 | 测量环境气压,单位&nbsp;:&nbsp;hPa&nbsp;&nbsp;mbar | 测量环境气压 | | BAROMETER | 气压计传感器 | 测量环境气压,单位&nbsp;:&nbsp;hPa&nbsp;&nbsp;mbar | 测量环境气压 |
| SENSOR_TYPE_ORIENTATION | 方向传感器 | 测量设备围绕所有三个物理轴(x、y、z)旋转的角度值,单位:rad | 用于提供屏幕旋转的3个角度值 | | ORIENTATION | 方向传感器 | 测量设备围绕所有三个物理轴(x、y、z)旋转的角度值,单位:rad | 用于提供屏幕旋转的3个角度值 |
| SENSOR_TYPE_ROTATION_VECTOR | 旋转矢量传感器 | 测量设备旋转矢量,复合传感器:由加速度传感器、磁场传感器、陀螺仪传感器合成 | 检测设备相对于东北天坐标系的方向 | | ROTATION_VECTOR | 旋转矢量传感器 | 测量设备旋转矢量,复合传感器:由加速度传感器、磁场传感器、陀螺仪传感器合成 | 检测设备相对于东北天坐标系的方向 |
| SENSOR_TYPE_PROXIMITY | 接近光传感器 | 测量可见物体相对于设备显示屏的接近或远离状态 | 通话中设备相对人的位置 | | PROXIMITY | 接近光传感器 | 测量可见物体相对于设备显示屏的接近或远离状态 | 通话中设备相对人的位置 |
| SENSOR_TYPE_AMBIENT_LIGHT | 环境光传感器 | 测量设备周围光线强度,单位:lux | 自动调节屏幕亮度,检测屏幕上方是否有遮挡 | | AMBIENT_LIGHT | 环境光传感器 | 测量设备周围光线强度,单位:lux | 自动调节屏幕亮度,检测屏幕上方是否有遮挡 |
| SENSOR_TYPE_HEART_RATE | 心率传感器 | 测量用户的心率数值 | 用于提供用户的心率健康数据 | | HEART_RATE | 心率传感器 | 测量用户的心率数值 | 用于提供用户的心率健康数据 |
| SENSOR_TYPE_WEAR_DETECTION | 佩戴检测传感器 | 检测用户是否佩戴 | 用于检测用户是否佩戴智能穿戴 | | WEAR_DETECTION | 佩戴检测传感器 | 检测用户是否佩戴 | 用于检测用户是否佩戴智能穿戴 |
| SENSOR_TYPE_HALL | 霍尔传感器 | 测量设备周围是否存在磁力吸引 | 设备的皮套模式 | | HALL | 霍尔传感器 | 测量设备周围是否存在磁力吸引 | 设备的皮套模式 |
## 运作机制 ## 运作机制
......
...@@ -361,7 +361,7 @@ currentSession.deactivate().then(() => { ...@@ -361,7 +361,7 @@ currentSession.deactivate().then(() => {
| sendControlCommand(command: AVControlCommand, callback: AsyncCallback\<void>): void | 发送控制命令 | | sendControlCommand(command: AVControlCommand, callback: AsyncCallback\<void>): void | 发送控制命令 |
| sendSystemAVKeyEvent(event: KeyEvent, callback: AsyncCallback\<void>): void | 发送系统按键命令 | | sendSystemAVKeyEvent(event: KeyEvent, callback: AsyncCallback\<void>): void | 发送系统按键命令 |
| sendSystemControlCommand(command: AVControlCommand, callback: AsyncCallback\<void>): void | 发送系统控制命令 | | sendSystemControlCommand(command: AVControlCommand, callback: AsyncCallback\<void>): void | 发送系统控制命令 |
| castAudio(session: SessionToken | 'all', audioDevices: Array\<audio.AudioDeviceDescriptor>, callback: AsyncCallback\<void>): void | 远端投播 | | castAudio(session: SessionToken \| 'all', audioDevices: Array\<audio.AudioDeviceDescriptor>, callback: AsyncCallback\<void>): void | 远端投播 |
### 开发步骤 ### 开发步骤
1.导入模块接口 1.导入模块接口
......
...@@ -9,7 +9,7 @@ ElementName信息,通过接口[Context.getElementName](js-apis-Context.md)获 ...@@ -9,7 +9,7 @@ ElementName信息,通过接口[Context.getElementName](js-apis-Context.md)获
## ElementName<sup>(deprecated)</sup> ## ElementName<sup>(deprecated)</sup>
> 从API version 9开始不再维护,建议使用[ElementName](js-apis-bundleManager-elementName.md)替代。 > 从API version 9开始不再维护,建议使用[bundleManager-ElementName](js-apis-bundleManager-elementName.md)替代。
ElementName信息,标识Ability的基本信息,通过接口[Context.getElementName](js-apis-Context.md)获取。 ElementName信息,标识Ability的基本信息,通过接口[Context.getElementName](js-apis-Context.md)获取。
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册