未验证 提交 ebf6831a 编写于 作者: O openharmony_ci 提交者: Gitee

!2908 Done! 2552:测试问题修改+示例代码修改+文档格式整改

Merge pull request !2908 from wusongqing/TR2552
...@@ -968,7 +968,7 @@ close(fd: number, callback: AsyncCallback<void>): void ...@@ -968,7 +968,7 @@ close(fd: number, callback: AsyncCallback<void>): void
Closes this file asset. This API uses an asynchronous callback to return the result. Closes this file asset. This API uses an asynchronous callback to return the result.
**Required permissions**: ohos.permission.READ_MEDIA ('r' enabled) and ohos.permission.WRITE_MEDIA ('w' enabled) **Required permissions**: ohos.permission.READ_MEDIA (when **mode** is set to **r**) and ohos.permission.WRITE_MEDIA (when **mode** is set to **w**)
**System capability**: SystemCapability.Multimedia.MediaLibrary.Core **System capability**: SystemCapability.Multimedia.MediaLibrary.Core
...@@ -1009,7 +1009,7 @@ close(fd: number): Promise<void> ...@@ -1009,7 +1009,7 @@ close(fd: number): Promise<void>
Closes this file asset. This API uses a promise to return the result. Closes this file asset. This API uses a promise to return the result.
**Required permissions**: ohos.permission.READ_MEDIA ('r' enabled) and ohos.permission.WRITE_MEDIA ('w' enabled) **Required permissions**: ohos.permission.READ_MEDIA (when **mode** is set to **r**) and ohos.permission.WRITE_MEDIA (when **mode** is set to **w**)
**System capability**: SystemCapability.Multimedia.MediaLibrary.Core **System capability**: SystemCapability.Multimedia.MediaLibrary.Core
...@@ -2128,7 +2128,7 @@ Enumerates media types. ...@@ -2128,7 +2128,7 @@ Enumerates media types.
**System capability**: SystemCapability.Multimedia.MediaLibrary.Core **System capability**: SystemCapability.Multimedia.MediaLibrary.Core
| Name | Default Value | Description| | Name | Default Value| Description|
| ----- | ------ | ---- | | ----- | ------ | ---- |
| FILE | 1 | File.| | FILE | 1 | File.|
| IMAGE | 3 | Image.| | IMAGE | 3 | Image.|
...@@ -2141,7 +2141,7 @@ Enumerates key file information. ...@@ -2141,7 +2141,7 @@ Enumerates key file information.
**System capability**: SystemCapability.Multimedia.MediaLibrary.Core **System capability**: SystemCapability.Multimedia.MediaLibrary.Core
| Name | Default Value | Description | | Name | Default Value | Description |
| ------------- | ------------------- | ---------------------------------------------------------- | | ------------- | ------------------- | ---------------------------------------------------------- |
| ID | file_id | File ID. | | ID | file_id | File ID. |
| RELATIVE_PATH | relative_path | Relative public directory of the file. | | RELATIVE_PATH | relative_path | Relative public directory of the file. |
...@@ -2169,7 +2169,7 @@ Enumerates directory types. ...@@ -2169,7 +2169,7 @@ Enumerates directory types.
**System capability**: SystemCapability.Multimedia.MediaLibrary.Core **System capability**: SystemCapability.Multimedia.MediaLibrary.Core
| Name | Default Value | Description | | Name | Default Value| Description |
| ------------- | ------ | ------------------ | | ------------- | ------ | ------------------ |
| DIR_CAMERA | 0 | Directory of camera files.| | DIR_CAMERA | 0 | Directory of camera files.|
| DIR_VIDEO | 1 | Directory of video files. | | DIR_VIDEO | 1 | Directory of video files. |
...@@ -2184,7 +2184,7 @@ Enumerates device types. ...@@ -2184,7 +2184,7 @@ Enumerates device types.
**System capability**: SystemCapability.Multimedia.MediaLibrary.Core **System capability**: SystemCapability.Multimedia.MediaLibrary.Core
| Name | Default Value | Description | | Name | Default Value| Description |
| ------------ | ------ | ---------- | | ------------ | ------ | ---------- |
| TYPE_UNKNOWN | 0 | Unknown.| | TYPE_UNKNOWN | 0 | Unknown.|
| TYPE_LAPTOP | 1 | Laptop.| | TYPE_LAPTOP | 1 | Laptop.|
......
# Media Query
> ![icon-note.gif](public_sys-resources/icon-note.gif)**NOTE**
> The APIs of this module are supported since API version 7. Updates will be marked with a superscript to indicate their earliest API version.
## Modules to Import
```
import mediaquery from '@ohos.mediaquery'
```
## Required Permissions
None.
## mediaquery.matchMediaSync
matchMediaSync(condition: string): MediaQueryListener
Sets the media query criteria and returns the corresponding listening handle.
- Parameters
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| condition | string | Yes| Matching condition of a media event.|
- Return value
| Type| Description|
| -------- | -------- |
| MediaQueryListener | Listening handle to a media event, which is used to register or unregister the listening callback.|
- Example
```
listener = mediaquery.matchMediaSync('(orientation: landscape)'); // Listen for landscape events.
```
## MediaQueryListener
Media query handle, including the first query result when the handle is applied for.
### Attributes
| Name| Type| Readable| Writable| Description|
| -------- | -------- | -------- | -------- | -------- |
| matches | boolean | Yes| No| Whether the match condition is met.|
| media | string | Yes| No| Matching condition of a media event.|
### on
on(type: 'change', callback: Callback<MediaQueryResult>): void
Registers a callback with the corresponding query condition by using the handle. This callback is triggered when the media attributes change.
- Parameters
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| type | string | Yes| Must enter the string **change**.|
| callback | Callback<MediaQueryResult> | Yes| Callback registered with media query.|
- Example
For details, see [off Example](#off).
### off
off(type: 'change', callback?: Callback<MediaQueryResult>): void
Unregisters a callback with the corresponding query condition by using the handle, so that no callback is triggered when the media attributes change.
- Parameters
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| type | boolean | Yes| Must enter the string **change**.|
| callback | Callback<MediaQueryResult> | No| Callback to be unregistered. If the default value is used, all callbacks of the handle are unregistered.|
- Example
```
import mediaquery from '@ohos.mediaquery'
listener = mediaquery.matchMediaSync('(orientation: landscape)'); // Listen for landscape events.
function onPortrait(mediaQueryResult) {
if (mediaQueryResult.matches) {
// do something here
} else {
// do something here
}
}
this.listener.on('change', this.onPortrait) // Registration callback.
this.listener.off('change', this.onPortrait) // Deregistration callback.
```
## MediaQueryResult
### Attributes
| Name| Type| Readable| Writable| Description|
| -------- | -------- | -------- | -------- | -------- |
| matches | boolean | Yes| No| Whether the match condition is met.|
| media | string | Yes| No| Matching condition of a media event.|
### Example
```
import mediaquery from '@ohos.mediaquery'
let portraitFunc = null
@Entry
@Component
struct MediaQueryExample {
@State color: string = '#DB7093'
@State text: string = 'Portrait'
listener = mediaquery.matchMediaSync('(orientation: landscape)')
onPortrait(mediaQueryResult) {
if (mediaQueryResult.matches) {
this.color = '#FFD700'
this.text = 'Landscape'
} else {
this.color = '#DB7093'
this.text = 'Portrait'
}
}
aboutToAppear() {
portraitFunc = this.onPortrait.bind(this) //bind current js instance
this.listener.on('change', portraitFunc)
}
build() {
Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) {
Text(this.text).fontSize(24).fontColor(this.color)
}
.width('100%').height('100%')
}
}
```
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册