| MediaQueryListener | Listening handle to a media event, which is used to register or unregister the listening callback.|
| condition | string | Yes | Matching condition of a media event. For details, see [Syntax of Media Query Conditions](../../ui/ui-ts-layout-mediaquery.md#syntax-of-media-query-conditions).|
- Example
**Return value**
| Type | Description |
| ------------------ | ---------------------- |
| MediaQueryListener | Listening handle to a media event, which is used to register or deregister the listening callback.|
**Example**
```js
```js
letlistener=mediaquery.matchMediaSync('(orientation: landscape)');// Listen for landscape events.
listener=mediaquery.matchMediaSync('(orientation: landscape)');// Listen for landscape events.
| type | boolean | Yes| Must enter the string **change**.|
**Parameters**
| callback | Callback<MediaQueryResult> | No| Callback to be unregistered. If the default value is used, all callbacks of the handle are unregistered.|
| type | boolean | Yes | Must enter the string **change**. |
| callback | Callback<MediaQueryResult> | No | Callback to be deregistered. If the default value is used, all callbacks of the handle are deregistered.|
- Example
**Example**
```js
```js
importmediaqueryfrom'@ohos.mediaquery'
importmediaqueryfrom'@ohos.mediaquery'
letlistener=mediaquery.matchMediaSync('(orientation: landscape)');// Listen for landscape events.
listener=mediaquery.matchMediaSync('(orientation: landscape)');// Listen for landscape events.
functiononPortrait(mediaQueryResult){
functiononPortrait(mediaQueryResult){
if(mediaQueryResult.matches){
if(mediaQueryResult.matches){
// do something here
// do something here
...
@@ -91,7 +100,7 @@ Unregisters a callback with the corresponding query condition by using the handl
...
@@ -91,7 +100,7 @@ Unregisters a callback with the corresponding query condition by using the handl
}
}
}
}
listener.on('change',onPortrait)// Register a callback.
listener.on('change',onPortrait)// Register a callback.
listener.off('change',onPortrait)// Unregister a callback.
listener.off('change',onPortrait)// Deregister a callback.
```
```
...
@@ -100,10 +109,10 @@ Unregisters a callback with the corresponding query condition by using the handl
...
@@ -100,10 +109,10 @@ Unregisters a callback with the corresponding query condition by using the handl
### Attributes
### Attributes
| Name| Type| Readable| Writable| Description|
| Name | Type | Readable | Writable | Description |