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

!24038 翻译已完成22878+22880+22549+22905+23003+23311+23317+23334+23160

Merge pull request !24038 from shawn_he/22878-d
...@@ -36,12 +36,6 @@ Your application can use the location function only after the user has granted t ...@@ -36,12 +36,6 @@ Your application can use the location function only after the user has granted t
Since the location information is considered sensitive, your application still needs to obtain the location access permission from the user even if the user has turned on the location function. The system will provide the location service for your application only after it has been granted the permission to access the device location information. Since the location information is considered sensitive, your application still needs to obtain the location access permission from the user even if the user has turned on the location function. The system will provide the location service for your application only after it has been granted the permission to access the device location information.
### Samples
The following sample is provided to help you better understand how to develop location services:
- [`Location`: Location (ArkTS) (API9)](https://gitee.com/openharmony/applications_app_samples/tree/master/device/Location)
## Applying for Location Permissions ## Applying for Location Permissions
...@@ -103,7 +97,7 @@ The following table lists the APIs used to obtain the device location informatio ...@@ -103,7 +97,7 @@ The following table lists the APIs used to obtain the device location informatio
### How to Develop ### How to Develop
1. Before using basic location capabilities, check whether your application has been granted the permission to access device location information. If not, your application first needs to apply for the required permission. For details, see [Applying for Location Permissions](#applying-for-location-permissions). 1. Before using system basic location capabilities, check whether your application has been granted the permission to access the device location information. If not, your application first needs to apply for the required permission. For details, see [Applying for Location Permissions](#applying-for-location-permissions).
2. Import the **geoLocationManager** module by which you can implement all APIs related to the basic location capabilities. 2. Import the **geoLocationManager** module by which you can implement all APIs related to the basic location capabilities.
...@@ -149,7 +143,7 @@ The following table lists the APIs used to obtain the device location informatio ...@@ -149,7 +143,7 @@ The following table lists the APIs used to obtain the device location informatio
Sample code for initializing **requestInfo** for navigation: Sample code for initializing **requestInfo** for navigation:
```ts ```ts
let requestInfo = {'scenario': geoLocationManager.LocationRequestScenario.NAVIGATION, 'timeInterval': 0, 'distanceInterval': 0, 'maxAccuracy': 0}; let requestInfo:geoLocationManager.LocationRequest = {'scenario': geoLocationManager.LocationRequestScenario.NAVIGATION, 'timeInterval': 0, 'distanceInterval': 0, 'maxAccuracy': 0};
``` ```
**Method 2:** **Method 2:**
...@@ -179,14 +173,14 @@ The following table lists the APIs used to obtain the device location informatio ...@@ -179,14 +173,14 @@ The following table lists the APIs used to obtain the device location informatio
Sample code for initializing **requestInfo** for the location accuracy priority policy: Sample code for initializing **requestInfo** for the location accuracy priority policy:
```ts ```ts
let requestInfo = {'priority': geoLocationManager.LocationRequestPriority.ACCURACY, 'timeInterval': 0, 'distanceInterval': 0, 'maxAccuracy': 0}; let requestInfo:geoLocationManager.LocationRequest = {'priority': geoLocationManager.LocationRequestPriority.ACCURACY, 'timeInterval': 0, 'distanceInterval': 0, 'maxAccuracy': 0};
``` ```
4. Instantiate the **Callback** object for the system to report location results. 4. Instantiate the **Callback** object for the system to report location results.
Your application needs to implement the callback defined by the system. When the system successfully obtains the real-time location of a device, it will report the location result to your application through the callback interface. Your application can implement the callback interface in such a way to complete your own service logic. Your application needs to implement the callback defined by the system. When the system successfully obtains the real-time location of a device, it will report the location result to your application through the callback interface. Your application can implement the callback interface in such a way to complete your own service logic.
```ts ```ts
let locationChange = (location) => { let locationChange = (location:geoLocationManager.Location):void => {
console.log('locationChanger: data: ' + JSON.stringify(location)); console.log('locationChanger: data: ' + JSON.stringify(location));
}; };
``` ```
...@@ -209,10 +203,11 @@ The following table lists the APIs used to obtain the device location informatio ...@@ -209,10 +203,11 @@ The following table lists the APIs used to obtain the device location informatio
```ts ```ts
import geoLocationManager from '@ohos.geoLocationManager'; import geoLocationManager from '@ohos.geoLocationManager';
import BusinessError from "@ohos.base";
try { try {
let location = geoLocationManager.getLastLocation(); let location = geoLocationManager.getLastLocation();
} catch (err) { } catch (err) {
console.error("errCode:" + err.code + ",errMessage:" + err.message); console.error("errCode:" + (err as BusinessError.BusinessError).code + ",errMessage:" + (err as BusinessError.BusinessError).message);
} }
``` ```
...@@ -259,10 +254,11 @@ The following table lists the APIs used for mutual conversion between coordinate ...@@ -259,10 +254,11 @@ The following table lists the APIs used for mutual conversion between coordinate
```ts ```ts
import geoLocationManager from '@ohos.geoLocationManager'; import geoLocationManager from '@ohos.geoLocationManager';
import BusinessError from "@ohos.base";
try { try {
let isAvailable = geoLocationManager.isGeocoderAvailable(); let isAvailable = geoLocationManager.isGeocoderAvailable();
} catch (err) { } catch (err) {
console.error("errCode:" + err.code + ",errMessage:" + err.message); console.error("errCode:" + (err as BusinessError.BusinessError).code + ",errMessage:" + (err as BusinessError.BusinessError).message);
} }
``` ```
...@@ -270,7 +266,7 @@ The following table lists the APIs used for mutual conversion between coordinate ...@@ -270,7 +266,7 @@ The following table lists the APIs used for mutual conversion between coordinate
- Call **getAddressesFromLocation** to convert coordinates into geographical location information. - Call **getAddressesFromLocation** to convert coordinates into geographical location information.
```ts ```ts
let reverseGeocodeRequest = {"latitude": 31.12, "longitude": 121.11, "maxItems": 1}; let reverseGeocodeRequest:geoLocationManager.ReverseGeoCodeRequest = {"latitude": 31.12, "longitude": 121.11, "maxItems": 1};
try { try {
geoLocationManager.getAddressesFromLocation(reverseGeocodeRequest, (err, data) => { geoLocationManager.getAddressesFromLocation(reverseGeocodeRequest, (err, data) => {
if (err) { if (err) {
...@@ -280,7 +276,7 @@ The following table lists the APIs used for mutual conversion between coordinate ...@@ -280,7 +276,7 @@ The following table lists the APIs used for mutual conversion between coordinate
} }
}); });
} catch (err) { } catch (err) {
console.error("errCode:" + err.code + ",errMessage:" + err.message); console.error("errCode:" + (err as BusinessError.BusinessError).code + ",errMessage:" + (err as BusinessError.BusinessError).message);
} }
``` ```
...@@ -288,7 +284,7 @@ The following table lists the APIs used for mutual conversion between coordinate ...@@ -288,7 +284,7 @@ The following table lists the APIs used for mutual conversion between coordinate
- Call **getAddressesFromLocationName** to convert geographic descriptions into coordinates. - Call **getAddressesFromLocationName** to convert geographic descriptions into coordinates.
```ts ```ts
let geocodeRequest = {"description": "No. xx, xx Road, Pudong District, Shanghai", "maxItems": 1}; let geocodeRequest:geoLocationManager.GeoCodeRequest = {"description": "No. xx, xx Road, Pudong District, Shanghai", "maxItems": 1};
try { try {
geoLocationManager.getAddressesFromLocationName(geocodeRequest, (err, data) => { geoLocationManager.getAddressesFromLocationName(geocodeRequest, (err, data) => {
if (err) { if (err) {
...@@ -298,7 +294,7 @@ The following table lists the APIs used for mutual conversion between coordinate ...@@ -298,7 +294,7 @@ The following table lists the APIs used for mutual conversion between coordinate
} }
}); });
} catch (err) { } catch (err) {
console.error("errCode:" + err.code + ",errMessage:" + err.message); console.error("errCode:" + (err as BusinessError.BusinessError).code + ",errMessage:" + (err as BusinessError.BusinessError).message);
} }
``` ```
...@@ -332,11 +328,12 @@ The following table lists the APIs used for geofencing. For details, see [Geoloc ...@@ -332,11 +328,12 @@ The following table lists the APIs used for geofencing. For details, see [Geoloc
1. Declare the **ohos.permission.APPROXIMATELY_LOCATION** permission. For details, see [Applying for Location Permissions](#applying-for-location-permissions). 1. Declare the **ohos.permission.APPROXIMATELY_LOCATION** permission. For details, see [Applying for Location Permissions](#applying-for-location-permissions).
2. Import the [geoLocationManager](../reference/apis/js-apis-geoLocationManager.md) and [wantAgent](../reference/apis/js-apis-app-ability-wantAgent.md) modules. 2. Import the [geoLocationManager](../reference/apis/js-apis-geoLocationManager.md), [wantAgent](../reference/apis/js-apis-app-ability-wantAgent.md), and [BusinessError](../reference/apis/js-apis-base.md) modules.
```ts ```ts
import geoLocationManager from '@ohos.geoLocationManager'; import geoLocationManager from '@ohos.geoLocationManager';
import wantAgent from '@ohos.app.ability.wantAgent'; import wantAgent, {WantAgent as _wantAgent} from '@ohos.app.ability.wantAgent';
import BusinessError from "@ohos.base";
``` ```
3. Create a [WantAgentInfo](../reference/apis/js-apis-inner-wantAgent-wantAgentInfo.md) object. 3. Create a [WantAgentInfo](../reference/apis/js-apis-inner-wantAgent-wantAgentInfo.md) object.
...@@ -344,10 +341,10 @@ The following table lists the APIs used for geofencing. For details, see [Geoloc ...@@ -344,10 +341,10 @@ The following table lists the APIs used for geofencing. For details, see [Geoloc
Scenario 1: Create a **WantAgentInfo** object for starting an ability. Scenario 1: Create a **WantAgentInfo** object for starting an ability.
```ts ```ts
let wantAgentObj = null; // Save the created WantAgent object for completing the trigger operations at a later time. let wantAgentObj:_wantAgent|null = null; // Save the created WantAgent object for completing the trigger operations at a later time.
// Set the operation type through operationType of the WantAgentInfo object. // Set the operation type through operationType of the WantAgentInfo object.
let wantAgentInfo = { let wantAgentInfo:wantAgent.WantAgentInfo = {
wants: [ wants: [
{ {
deviceId: '', deviceId: '',
...@@ -368,10 +365,10 @@ The following table lists the APIs used for geofencing. For details, see [Geoloc ...@@ -368,10 +365,10 @@ The following table lists the APIs used for geofencing. For details, see [Geoloc
Scenario 2: Create a **WantAgentInfo** object for publishing [common events](../application-models/common-event-overview.md). Scenario 2: Create a **WantAgentInfo** object for publishing [common events](../application-models/common-event-overview.md).
```ts ```ts
let wantAgentObj = null; // Save the created WantAgent object for completing the trigger operations at a later time. let wantAgentObj:_wantAgent|null = null; // Save the created WantAgent object for completing the trigger operations at a later time.
// Set the operation type through operationType of the WantAgentInfo object. // Set the operation type through operationType of the WantAgentInfo object.
let wantAgentInfo = { let wantAgentInfo:wantAgent.WantAgentInfo = {
wants: [ wants: [
{ {
action: "event_name", // Set the event name. action: "event_name", // Set the event name.
...@@ -397,13 +394,14 @@ After obtaining the **WantAgent** object, call the geofencing API to add a geofe ...@@ -397,13 +394,14 @@ After obtaining the **WantAgent** object, call the geofencing API to add a geofe
} }
console.info('getWantAgent success'); console.info('getWantAgent success');
wantAgentObj = data; wantAgentObj = data;
let requestInfo = {'priority': 0x201, 'scenario': 0x301, "geofence": {"latitude": 121, "longitude": 26, "radius": 100, "expiration": 10000}}; let requestInfo:geoLocationManager.GeofenceRequest = {'scenario': 0x301, "geofence": {"latitude": 121, "longitude": 26, "radius": 100, "expiration": 10000}};
try { try {
geoLocationManager.on('gnssFenceStatusChange', requestInfo, wantAgentObj); geoLocationManager.on('gnssFenceStatusChange', requestInfo, wantAgentObj);
} catch (err) { } catch (err) {
console.error("errCode:" + err.code + ",errMessage:" + err.message); console.error("errCode:" + (err as BusinessError.BusinessError).code + ",errMessage:" + (err as BusinessError.BusinessError).message);
} }
}); });
``` ```
5. Have the system automatically trigger the action defined for the **WantAgent** object when a device enters or exits the geofence. 5. Have the system automatically trigger the action defined for the **WantAgent** object when a device enters or exits the geofence.
...@@ -394,6 +394,27 @@ promise.then(data => { ...@@ -394,6 +394,27 @@ promise.then(data => {
}); });
``` ```
## call.hasCallSync<sup>10+</sup>
hasCallSync\(\): boolean
Checks whether a call is in progress.
**System capability**: SystemCapability.Telephony.CallManager
**Return value**
| Type | Description |
| ---------------------- |-------------|
| boolean | Promise used to return the result.|
**Example**
```js
let hasCall = call.hasCallSync();
console.log(`hasCallSync success, has call is ' + hasCall);
```
## call.getCallState ## call.getCallState
...@@ -443,6 +464,27 @@ promise.then(data => { ...@@ -443,6 +464,27 @@ promise.then(data => {
}); });
``` ```
## call.getCallStateSync<sup>10+</sup>
getCallStateSync\(\): CallState
Obtains the call status.
**System capability**: SystemCapability.Telephony.CallManager
**Return value**
| Type | Description |
| ------------------------------------- |-------------|
| [CallState](#callstate) | Promise used to return the result.|
**Example**
```js
let callState = call.getCallStateSync();
console.log(`the call state is:` + callState);
```
## call.hasVoiceCapability<sup>7+</sup> ## call.hasVoiceCapability<sup>7+</sup>
hasVoiceCapability\(\): boolean hasVoiceCapability\(\): boolean
...@@ -2821,7 +2863,7 @@ call.off('mmiCodeResult', data => { ...@@ -2821,7 +2863,7 @@ call.off('mmiCodeResult', data => {
## call.on('audioDeviceChange')<sup>10+</sup> ## call.on('audioDeviceChange')<sup>10+</sup>
on\(type: 'audioDeviceChange', callback: Callback\<AudioDeviceInfo\>\): void on\(type: 'audioDeviceChange', callback: Callback\<AudioDeviceCallbackInfo\>\): void
Subscribes to audio device change events. This API uses an asynchronous callback to return the result. Subscribes to audio device change events. This API uses an asynchronous callback to return the result.
...@@ -2836,7 +2878,7 @@ Subscribes to audio device change events. This API uses an asynchronous callback ...@@ -2836,7 +2878,7 @@ Subscribes to audio device change events. This API uses an asynchronous callback
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| -------- | ----------------------------------------------- | ---- | --------------------------------------------------- | | -------- | ----------------------------------------------- | ---- | --------------------------------------------------- |
| type | string | Yes | Audio device change. This field has a fixed value of **audioDeviceChange**.| | type | string | Yes | Audio device change. This field has a fixed value of **audioDeviceChange**.|
| callback | Callback<[AudioDeviceInfo](#audiodeviceinfo10)> | Yes | Callback used to return the result. | | callback | Callback<[AudioDeviceCallbackInfo](#audiodevicecallbackinfo10)> | Yes | Callback used to return the result. |
**Error codes** **Error codes**
...@@ -2863,7 +2905,7 @@ call.on('audioDeviceChange', data => { ...@@ -2863,7 +2905,7 @@ call.on('audioDeviceChange', data => {
## call.off('audioDeviceChange')<sup>10+</sup> ## call.off('audioDeviceChange')<sup>10+</sup>
off\(type: 'audioDeviceChange', callback?: Callback\<AudioDeviceInfo\>\): void off\(type: 'audioDeviceChange', callback?: Callback\<AudioDeviceCallbackInfo\>\): void
Unsubscribes from **audioDeviceChange** events. This API uses an asynchronous callback to return the result. Unsubscribes from **audioDeviceChange** events. This API uses an asynchronous callback to return the result.
...@@ -2878,7 +2920,7 @@ Unsubscribes from **audioDeviceChange** events. This API uses an asynchronous ca ...@@ -2878,7 +2920,7 @@ Unsubscribes from **audioDeviceChange** events. This API uses an asynchronous ca
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| -------- | ---------------------------------------------------------- | ---- | --------------------------------------------------- | | -------- | ---------------------------------------------------------- | ---- | --------------------------------------------------- |
| type | string | Yes | Audio device change. This field has a fixed value of **audioDeviceChange**.| | type | string | Yes | Audio device change. This field has a fixed value of **audioDeviceChange**.|
| callback | Callback<[AudioDeviceInfo](#audiodeviceinfo10)> | No | Callback used to return the result. If this parameter is not set, no subscription cancellation result will be received. | | callback | Callback<[AudioDeviceCallbackInfo](#audiodevicecallbackinfo10)> | No | Callback used to return the result. If this parameter is not set, no subscription cancellation result will be received. |
**Error codes** **Error codes**
...@@ -4978,7 +5020,7 @@ Enumerates audio device types. ...@@ -4978,7 +5020,7 @@ Enumerates audio device types.
| DEVICE_WIRED_HEADSET | 2 | Wired headset device.| | DEVICE_WIRED_HEADSET | 2 | Wired headset device.|
| DEVICE_BLUETOOTH_SCO | 3 | Bluetooth SCO device. | | DEVICE_BLUETOOTH_SCO | 3 | Bluetooth SCO device. |
## AudioDeviceInfo<sup>10+</sup> ## AudioDeviceCallbackInfo<sup>10+</sup>
Defines the audio device information. Defines the audio device information.
...@@ -5191,10 +5233,12 @@ Enumerates call ability event IDs. ...@@ -5191,10 +5233,12 @@ Enumerates call ability event IDs.
**System capability**: SystemCapability.Telephony.CallManager **System capability**: SystemCapability.Telephony.CallManager
| Name | Value | Description | | Name | Value | Description |
| ------------------------ | ---- | --------------- | | ------------------------------------- | ---- | --------------- |
| EVENT_DIAL_NO_CARRIER | 1 | No available carrier during dialing. | | EVENT_DIAL_NO_CARRIER | 1 | No available carrier during dialing. |
| EVENT_INVALID_FDN_NUMBER | 2 | Invalid FDN.| | EVENT_INVALID_FDN_NUMBER | 2 | Invalid FDN.|
| EVENT_HOLD_CALL_FAILED<sup>11+</sup> | 3 | Failed to place the call on hold.|
| EVENT_SWAP_CALL_FAILED<sup>11+</sup> | 4 | Failed to place the current call on hold and answer the waiting call.|
## DialScene<sup>8+</sup> ## DialScene<sup>8+</sup>
......
# @ohos.multimodalInput.inputDeviceCooperate (Screen Hopping) # @ohos.multimodalInput.inputDeviceCooperate (Screen Hopping) (To Be Deprecated Soon)
The **inputDeviceCooperate** module implements screen hopping for two or more networked devices to share the keyboard and mouse for collaborative operations. The **inputDeviceCooperate** module implements screen hopping for two or more networked devices to share the keyboard and mouse for collaborative operations.
...@@ -108,8 +108,8 @@ For details about the error codes, see [Screen Hopping Error Codes](../errorcode ...@@ -108,8 +108,8 @@ For details about the error codes, see [Screen Hopping Error Codes](../errorcode
| ID| Error Message| | ID| Error Message|
| -------- | ---------------------------------------- | | -------- | ---------------------------------------- |
| 4400001 | This error code is reported if an invalid device descriptor is passed to the screen hopping API. | | 4400001 | Incorrect descriptor for the target device. |
| 4400002 | This error code is reported if the screen hopping status is abnormal when the screen hopping API is called. | | 4400002 | Screen hop failed. |
**Example** **Example**
...@@ -158,8 +158,8 @@ For details about the error codes, see [Screen Hopping Error Codes](../errorcode ...@@ -158,8 +158,8 @@ For details about the error codes, see [Screen Hopping Error Codes](../errorcode
| ID| Error Message| | ID| Error Message|
| -------- | ---------------------------------------- | | -------- | ---------------------------------------- |
| 4400001 | This error code is reported if an invalid device descriptor is passed to the screen hopping API. | | 4400001 | Incorrect descriptor for the target device. |
| 4400002 | This error code is reported if the screen hopping status is abnormal when the screen hopping API is called. | | 4400002 | Screen hop failed. |
**Example** **Example**
......
# @ohos.deviceStatus.dragInteraction (Drag Interaction)
The **dragInteraction** module provides the APIs to enable and disable listening for dragging status changes.
> **NOTE**
>
> - The initial APIs of this module are supported since API version 10. Newly added APIs will be marked with a superscript to indicate their earliest API version.
>
> - The APIs provided by this module are system APIs.
## Modules to Import
```js
import dragInteraction from '@ohos.deviceStatus.dragInteraction'
```
## dragInteraction.on('drag')
on(type: 'drag', callback: Callback&lt;DragState&gt;): void;
Enables listening for dragging status changes.
**System capability**: SystemCapability.Msdp.DeviceStatus.Drag
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ---------------------------- | ---- | ---------------------------- |
| type | string | Yes | Event type. This field has a fixed value of **drag**.|
| callback | Callback&lt;[DragState](#dragstate)&gt; | Yes | Callback used to return the dragging status.|
**Example**
```js
try {
dragInteraction.on('drag', (data) => {
console.log(`Drag interaction event: ${JSON.stringify(data)}`);
});
} catch (error) {
console.log(`Register failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
}
```
## dragInteraction.off('drag')
off(type: 'drag', callback?: Callback&lt;DragState&gt;): void;
Disables listening for dragging status changes.
**System capability**: SystemCapability.Msdp.DeviceStatus.Drag
**Parameters**
| Name | Type | Mandatory | Description |
| -------- | ---------------------------- | ---- | ---------------------------- |
| type | string | Yes | Event type. This field has a fixed value of **drag**.|
| callback | Callback&lt;[DragState](#dragstate)> | No | Callback to be unregistered. If this parameter is not specified, all callbacks registered by the current application will be unregistered.|
**Example**
```js
// Unregister a single callback.
function callback(event) {
console.log(`Drag interaction event: ${JSON.stringify(event)}`);
return false;
}
try {
dragInteraction.on('drag', callback);
dragInteraction.off("drag", callback);
} catch (error) {
console.log(`Execute failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
}
```
```js
// Unregister all callbacks.
function callback(event) {
console.log(`Drag interaction event: ${JSON.stringify(event)}`);
return false;
}
try {
dragInteraction.on('drag', callback);
dragInteraction.off("drag");
} catch (error) {
console.log(`Execute failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
}
```
## DragState
Enumerates dragging states.
**System capability**: SystemCapability.Msdp.DeviceStatus.Drag
| Name | Value | Description |
| -------- | ----------------- | ----------------- |
| MSG_DRAG_STATE_START | 1 | Dragging starts.|
| MSG_DRAG_STATE_STOP | 2 | Dragging is ended. |
| MSG_DRAG_STATE_CANCEL | 3 | Dragging is canceled. |
...@@ -426,14 +426,15 @@ For details about the error codes, see [Location Error Codes](../errorcodes/erro ...@@ -426,14 +426,15 @@ For details about the error codes, see [Location Error Codes](../errorcodes/erro
```ts ```ts
import geoLocationManager from '@ohos.geoLocationManager'; import geoLocationManager from '@ohos.geoLocationManager';
let requestInfo = {'priority': geoLocationManager.LocationRequestPriority.FIRST_FIX, 'scenario': geoLocationManager.LocationRequestScenario.UNSET, 'timeInterval': 1, 'distanceInterval': 0, 'maxAccuracy': 0}; import BusinessError from "@ohos.base";
let locationChange = (location) => { let requestInfo:geoLocationManager.LocationRequest = {'priority': geoLocationManager.LocationRequestPriority.FIRST_FIX, 'scenario': geoLocationManager.LocationRequestScenario.UNSET, 'timeInterval': 1, 'distanceInterval': 0, 'maxAccuracy': 0};
let locationChange = (location:geoLocationManager.Location):void => {
console.log('locationChanger: data: ' + JSON.stringify(location)); console.log('locationChanger: data: ' + JSON.stringify(location));
}; };
try { try {
geoLocationManager.on('locationChange', requestInfo, locationChange); geoLocationManager.on('locationChange', requestInfo, locationChange);
} catch (err) { } catch (err) {
console.error("errCode:" + err.code + ",errMessage:" + err.message); console.error("errCode:" + (err as BusinessError.BusinessError).code + ",errMessage:" + (err as BusinessError.BusinessError).message);
} }
``` ```
...@@ -470,15 +471,16 @@ For details about the error codes, see [Location Error Codes](../errorcodes/erro ...@@ -470,15 +471,16 @@ For details about the error codes, see [Location Error Codes](../errorcodes/erro
```ts ```ts
import geoLocationManager from '@ohos.geoLocationManager'; import geoLocationManager from '@ohos.geoLocationManager';
let requestInfo = {'priority': geoLocationManager.LocationRequestPriority.FIRST_FIX, 'scenario': geoLocationManager.LocationRequestScenario.UNSET, 'timeInterval': 1, 'distanceInterval': 0, 'maxAccuracy': 0}; import BusinessError from "@ohos.base";
let locationChange = (location) => { let requestInfo:geoLocationManager.LocationRequest = {'priority': geoLocationManager.LocationRequestPriority.FIRST_FIX, 'scenario': geoLocationManager.LocationRequestScenario.UNSET, 'timeInterval': 1, 'distanceInterval': 0, 'maxAccuracy': 0};
console.log('locationChanger: data: ' + JSON.stringify(location)); let locationChange = (location:geoLocationManager.Location):void => {
console.log('locationChanger: data: ' + JSON.stringify(location));
}; };
try { try {
geoLocationManager.on('locationChange', requestInfo, locationChange); geoLocationManager.on('locationChange', requestInfo, locationChange);
geoLocationManager.off('locationChange', locationChange); geoLocationManager.off('locationChange', locationChange);
} catch (err) { } catch (err) {
console.error("errCode:" + err.code + ",errMessage:" + err.message); console.error("errCode:" + (err as BusinessError.BusinessError).code + ",errMessage:" + (err as BusinessError.BusinessError).message);
} }
``` ```
...@@ -510,13 +512,14 @@ For details about the error codes, see [Location Error Codes](../errorcodes/erro ...@@ -510,13 +512,14 @@ For details about the error codes, see [Location Error Codes](../errorcodes/erro
```ts ```ts
import geoLocationManager from '@ohos.geoLocationManager'; import geoLocationManager from '@ohos.geoLocationManager';
let locationEnabledChange = (state) => { import BusinessError from "@ohos.base";
let locationEnabledChange = (state:boolean):void => {
console.log('locationEnabledChange: ' + JSON.stringify(state)); console.log('locationEnabledChange: ' + JSON.stringify(state));
} }
try { try {
geoLocationManager.on('locationEnabledChange', locationEnabledChange); geoLocationManager.on('locationEnabledChange', locationEnabledChange);
} catch (err) { } catch (err) {
console.error("errCode:" + err.code + ",errMessage:" + err.message); console.error("errCode:" + (err as BusinessError.BusinessError).code + ",errMessage:" + (err as BusinessError.BusinessError).message);
} }
``` ```
...@@ -548,14 +551,15 @@ For details about the error codes, see [Location Error Codes](../errorcodes/erro ...@@ -548,14 +551,15 @@ For details about the error codes, see [Location Error Codes](../errorcodes/erro
```ts ```ts
import geoLocationManager from '@ohos.geoLocationManager'; import geoLocationManager from '@ohos.geoLocationManager';
let locationEnabledChange = (state) => { import BusinessError from "@ohos.base";
let locationEnabledChange = (state:boolean):void => {
console.log('locationEnabledChange: state: ' + JSON.stringify(state)); console.log('locationEnabledChange: state: ' + JSON.stringify(state));
} }
try { try {
geoLocationManager.on('locationEnabledChange', locationEnabledChange); geoLocationManager.on('locationEnabledChange', locationEnabledChange);
geoLocationManager.off('locationEnabledChange', locationEnabledChange); geoLocationManager.off('locationEnabledChange', locationEnabledChange);
} catch (err) { } catch (err) {
console.error("errCode:" + err.code + ",errMessage:" + err.message); console.error("errCode:" + (err as BusinessError.BusinessError).code + ",errMessage:" + (err as BusinessError.BusinessError).message);
} }
``` ```
...@@ -592,14 +596,15 @@ For details about the error codes, see [Location Error Codes](../errorcodes/erro ...@@ -592,14 +596,15 @@ For details about the error codes, see [Location Error Codes](../errorcodes/erro
```ts ```ts
import geoLocationManager from '@ohos.geoLocationManager'; import geoLocationManager from '@ohos.geoLocationManager';
let cachedLocationsCb = (locations) => { import BusinessError from "@ohos.base";
let cachedLocationsCb = (locations:Array<geoLocationManager.Location>):void => {
console.log('cachedGnssLocationsChange: locations: ' + JSON.stringify(locations)); console.log('cachedGnssLocationsChange: locations: ' + JSON.stringify(locations));
} }
let requestInfo = {'reportingPeriodSec': 10, 'wakeUpCacheQueueFull': true}; let requestInfo:geoLocationManager.CachedGnssLocationsRequest = {'reportingPeriodSec': 10, 'wakeUpCacheQueueFull': true};
try { try {
geoLocationManager.on('cachedGnssLocationsChange', requestInfo, cachedLocationsCb); geoLocationManager.on('cachedGnssLocationsChange', requestInfo, cachedLocationsCb);
} catch (err) { } catch (err) {
console.error("errCode:" + err.code + ",errMessage:" + err.message); console.error("errCode:" + (err as BusinessError.BusinessError).code + ",errMessage:" + (err as BusinessError.BusinessError).message);
} }
``` ```
...@@ -635,15 +640,16 @@ For details about the error codes, see [Location Error Codes](../errorcodes/erro ...@@ -635,15 +640,16 @@ For details about the error codes, see [Location Error Codes](../errorcodes/erro
```ts ```ts
import geoLocationManager from '@ohos.geoLocationManager'; import geoLocationManager from '@ohos.geoLocationManager';
let cachedLocationsCb = (locations) => { import BusinessError from "@ohos.base";
let cachedLocationsCb = (locations:Array<geoLocationManager.Location>):void => {
console.log('cachedGnssLocationsChange: locations: ' + JSON.stringify(locations)); console.log('cachedGnssLocationsChange: locations: ' + JSON.stringify(locations));
} }
let requestInfo = {'reportingPeriodSec': 10, 'wakeUpCacheQueueFull': true}; let requestInfo:geoLocationManager.CachedGnssLocationsRequest = {'reportingPeriodSec': 10, 'wakeUpCacheQueueFull': true};
try { try {
geoLocationManager.on('cachedGnssLocationsChange', requestInfo, cachedLocationsCb); geoLocationManager.on('cachedGnssLocationsChange', requestInfo, cachedLocationsCb);
geoLocationManager.off('cachedGnssLocationsChange'); geoLocationManager.off('cachedGnssLocationsChange');
} catch (err) { } catch (err) {
console.error("errCode:" + err.code + ",errMessage:" + err.message); console.error("errCode:" + (err as BusinessError.BusinessError).code + ",errMessage:" + (err as BusinessError.BusinessError).message);
} }
``` ```
...@@ -678,14 +684,15 @@ For details about the error codes, see [Location Error Codes](../errorcodes/erro ...@@ -678,14 +684,15 @@ For details about the error codes, see [Location Error Codes](../errorcodes/erro
```ts ```ts
import geoLocationManager from '@ohos.geoLocationManager'; import geoLocationManager from '@ohos.geoLocationManager';
let gnssStatusCb = (satelliteStatusInfo) => { import BusinessError from "@ohos.base";
let gnssStatusCb = (satelliteStatusInfo:geoLocationManager.SatelliteStatusInfo):void => {
console.log('satelliteStatusChange: ' + JSON.stringify(satelliteStatusInfo)); console.log('satelliteStatusChange: ' + JSON.stringify(satelliteStatusInfo));
} }
try { try {
geoLocationManager.on('satelliteStatusChange', gnssStatusCb); geoLocationManager.on('satelliteStatusChange', gnssStatusCb);
} catch (err) { } catch (err) {
console.error("errCode:" + err.code + ",errMessage:" + err.message); console.error("errCode:" + (err as BusinessError.BusinessError).code + ",errMessage:" + (err as BusinessError.BusinessError).message);
} }
``` ```
...@@ -721,14 +728,15 @@ For details about the error codes, see [Location Error Codes](../errorcodes/erro ...@@ -721,14 +728,15 @@ For details about the error codes, see [Location Error Codes](../errorcodes/erro
```ts ```ts
import geoLocationManager from '@ohos.geoLocationManager'; import geoLocationManager from '@ohos.geoLocationManager';
let gnssStatusCb = (satelliteStatusInfo) => { import BusinessError from "@ohos.base";
let gnssStatusCb = (satelliteStatusInfo:geoLocationManager.SatelliteStatusInfo):void => {
console.log('satelliteStatusChange: ' + JSON.stringify(satelliteStatusInfo)); console.log('satelliteStatusChange: ' + JSON.stringify(satelliteStatusInfo));
} }
try { try {
geoLocationManager.on('satelliteStatusChange', gnssStatusCb); geoLocationManager.on('satelliteStatusChange', gnssStatusCb);
geoLocationManager.off('satelliteStatusChange', gnssStatusCb); geoLocationManager.off('satelliteStatusChange', gnssStatusCb);
} catch (err) { } catch (err) {
console.error("errCode:" + err.code + ",errMessage:" + err.message); console.error("errCode:" + (err as BusinessError.BusinessError).code + ",errMessage:" + (err as BusinessError.BusinessError).message);
} }
``` ```
...@@ -764,14 +772,15 @@ For details about the error codes, see [Location Error Codes](../errorcodes/erro ...@@ -764,14 +772,15 @@ For details about the error codes, see [Location Error Codes](../errorcodes/erro
```ts ```ts
import geoLocationManager from '@ohos.geoLocationManager'; import geoLocationManager from '@ohos.geoLocationManager';
let nmeaCb = (str) => { import BusinessError from "@ohos.base";
let nmeaCb = (str:string):void => {
console.log('nmeaMessage: ' + JSON.stringify(str)); console.log('nmeaMessage: ' + JSON.stringify(str));
} }
try { try {
geoLocationManager.on('nmeaMessage', nmeaCb ); geoLocationManager.on('nmeaMessage', nmeaCb );
} catch (err) { } catch (err) {
console.error("errCode:" + err.code + ",errMessage:" + err.message); console.error("errCode:" + (err as BusinessError.BusinessError).code + ",errMessage:" + (err as BusinessError.BusinessError).message);
} }
``` ```
...@@ -807,7 +816,8 @@ For details about the error codes, see [Location Error Codes](../errorcodes/erro ...@@ -807,7 +816,8 @@ For details about the error codes, see [Location Error Codes](../errorcodes/erro
```ts ```ts
import geoLocationManager from '@ohos.geoLocationManager'; import geoLocationManager from '@ohos.geoLocationManager';
let nmeaCb = (str) => { import BusinessError from "@ohos.base";
let nmeaCb = (str:string):void => {
console.log('nmeaMessage: ' + JSON.stringify(str)); console.log('nmeaMessage: ' + JSON.stringify(str));
} }
...@@ -815,7 +825,7 @@ For details about the error codes, see [Location Error Codes](../errorcodes/erro ...@@ -815,7 +825,7 @@ For details about the error codes, see [Location Error Codes](../errorcodes/erro
geoLocationManager.on('nmeaMessage', nmeaCb); geoLocationManager.on('nmeaMessage', nmeaCb);
geoLocationManager.off('nmeaMessage', nmeaCb); geoLocationManager.off('nmeaMessage', nmeaCb);
} catch (err) { } catch (err) {
console.error("errCode:" + err.code + ",errMessage:" + err.message); console.error("errCode:" + (err as BusinessError.BusinessError).code + ",errMessage:" + (err as BusinessError.BusinessError).message);
} }
``` ```
...@@ -853,8 +863,9 @@ For details about the error codes, see [Location Error Codes](../errorcodes/erro ...@@ -853,8 +863,9 @@ For details about the error codes, see [Location Error Codes](../errorcodes/erro
```ts ```ts
import geoLocationManager from '@ohos.geoLocationManager'; import geoLocationManager from '@ohos.geoLocationManager';
import wantAgent from '@ohos.app.ability.wantAgent'; import wantAgent from '@ohos.app.ability.wantAgent';
import BusinessError from "@ohos.base";
let wantAgentInfo = {
let wantAgentInfo:wantAgent.WantAgentInfo = {
wants: [ wants: [
{ {
bundleName: "com.example.myapplication", bundleName: "com.example.myapplication",
...@@ -868,11 +879,11 @@ For details about the error codes, see [Location Error Codes](../errorcodes/erro ...@@ -868,11 +879,11 @@ For details about the error codes, see [Location Error Codes](../errorcodes/erro
}; };
wantAgent.getWantAgent(wantAgentInfo).then((wantAgentObj) => { wantAgent.getWantAgent(wantAgentInfo).then((wantAgentObj) => {
let requestInfo = {'priority': 0x201, 'scenario': 0x301, "geofence": {"latitude": 121, "longitude": 26, "radius": 100, "expiration": 10000}}; let requestInfo:geoLocationManager.GeofenceRequest = {'scenario': 0x301, "geofence": {"latitude": 121, "longitude": 26, "radius": 100, "expiration": 10000}};
try { try {
geoLocationManager.on('gnssFenceStatusChange', requestInfo, wantAgentObj); geoLocationManager.on('gnssFenceStatusChange', requestInfo, wantAgentObj);
} catch (err) { } catch (err) {
console.error("errCode:" + err.code + ",errMessage:" + err.message); console.error("errCode:" + (err as BusinessError.BusinessError).code + ",errMessage:" + (err as BusinessError.BusinessError).message);
} }
}); });
``` ```
...@@ -911,8 +922,9 @@ For details about the error codes, see [Location Error Codes](../errorcodes/erro ...@@ -911,8 +922,9 @@ For details about the error codes, see [Location Error Codes](../errorcodes/erro
```ts ```ts
import geoLocationManager from '@ohos.geoLocationManager'; import geoLocationManager from '@ohos.geoLocationManager';
import wantAgent from '@ohos.app.ability.wantAgent'; import wantAgent from '@ohos.app.ability.wantAgent';
import BusinessError from "@ohos.base";
let wantAgentInfo = { let wantAgentInfo:wantAgent.WantAgentInfo = {
wants: [ wants: [
{ {
bundleName: "com.example.myapplication", bundleName: "com.example.myapplication",
...@@ -926,12 +938,12 @@ For details about the error codes, see [Location Error Codes](../errorcodes/erro ...@@ -926,12 +938,12 @@ For details about the error codes, see [Location Error Codes](../errorcodes/erro
}; };
wantAgent.getWantAgent(wantAgentInfo).then((wantAgentObj) => { wantAgent.getWantAgent(wantAgentInfo).then((wantAgentObj) => {
let requestInfo = {'priority': 0x201, 'scenario': 0x301, "geofence": {"latitude": 121, "longitude": 26, "radius": 100, "expiration": 10000}}; let requestInfo:geoLocationManager.GeofenceRequest = {'scenario': 0x301, "geofence": {"latitude": 121, "longitude": 26, "radius": 100, "expiration": 10000}};;
try { try {
geoLocationManager.on('gnssFenceStatusChange', requestInfo, wantAgentObj); geoLocationManager.on('gnssFenceStatusChange', requestInfo, wantAgentObj);
geoLocationManager.off('gnssFenceStatusChange', requestInfo, wantAgentObj); geoLocationManager.off('gnssFenceStatusChange', requestInfo, wantAgentObj);
} catch (err) { } catch (err) {
console.error("errCode:" + err.code + ",errMessage:" + err.message); console.error("errCode:" + (err as BusinessError.BusinessError).code + ",errMessage:" + (err as BusinessError.BusinessError).message);
} }
}); });
``` ```
...@@ -966,14 +978,15 @@ For details about the error codes, see [Location Error Codes](../errorcodes/erro ...@@ -966,14 +978,15 @@ For details about the error codes, see [Location Error Codes](../errorcodes/erro
```ts ```ts
import geoLocationManager from '@ohos.geoLocationManager'; import geoLocationManager from '@ohos.geoLocationManager';
let callback = (code) => { import BusinessError from "@ohos.base";
let callback = (code:geoLocationManager.CountryCode):void => {
console.log('countryCodeChange: ' + JSON.stringify(code)); console.log('countryCodeChange: ' + JSON.stringify(code));
} }
try { try {
geoLocationManager.on('countryCodeChange', callback); geoLocationManager.on('countryCodeChange', callback);
} catch (err) { } catch (err) {
console.error("errCode:" + err.code + ",errMessage:" + err.message); console.error("errCode:" + (err as BusinessError.BusinessError).code + ",errMessage:" + (err as BusinessError.BusinessError).message);
} }
``` ```
...@@ -1006,7 +1019,8 @@ For details about the error codes, see [Location Error Codes](../errorcodes/erro ...@@ -1006,7 +1019,8 @@ For details about the error codes, see [Location Error Codes](../errorcodes/erro
```ts ```ts
import geoLocationManager from '@ohos.geoLocationManager'; import geoLocationManager from '@ohos.geoLocationManager';
let callback = (code) => { import BusinessError from "@ohos.base";
let callback = (code:geoLocationManager.CountryCode):void => {
console.log('countryCodeChange: ' + JSON.stringify(code)); console.log('countryCodeChange: ' + JSON.stringify(code));
} }
...@@ -1014,7 +1028,7 @@ For details about the error codes, see [Location Error Codes](../errorcodes/erro ...@@ -1014,7 +1028,7 @@ For details about the error codes, see [Location Error Codes](../errorcodes/erro
geoLocationManager.on('countryCodeChange', callback); geoLocationManager.on('countryCodeChange', callback);
geoLocationManager.off('countryCodeChange', callback); geoLocationManager.off('countryCodeChange', callback);
} catch (err) { } catch (err) {
console.error("errCode:" + err.code + ",errMessage:" + err.message); console.error("errCode:" + (err as BusinessError.BusinessError).code + ",errMessage:" + (err as BusinessError.BusinessError).message);
} }
``` ```
...@@ -1051,14 +1065,15 @@ For details about the error codes, see [Location Error Codes](../errorcodes/erro ...@@ -1051,14 +1065,15 @@ For details about the error codes, see [Location Error Codes](../errorcodes/erro
```ts ```ts
import geoLocationManager from '@ohos.geoLocationManager'; import geoLocationManager from '@ohos.geoLocationManager';
let callback = (code) => { import BusinessError from "@ohos.base";
let callback = (code:Array<geoLocationManager.LocatingRequiredData>):void => {
console.log('locatingRequiredDataChange: ' + JSON.stringify(code)); console.log('locatingRequiredDataChange: ' + JSON.stringify(code));
} }
let config = {'type': 1, 'needStartScan': true, 'scanInterval': 10000}; let config:geoLocationManager.LocatingRequiredDataConfig = {'type': 1, 'needStartScan': true, 'scanInterval': 10000};
try { try {
geoLocationManager.on('locatingRequiredDataChange', config, callback); geoLocationManager.on('locatingRequiredDataChange', config, callback);
} catch (err) { } catch (err) {
console.error("errCode:" + err.code + ",errMessage:" + err.message); console.error("errCode:" + (err as BusinessError.BusinessError).code + ",errMessage:" + (err as BusinessError.BusinessError).message);
} }
``` ```
...@@ -1090,15 +1105,16 @@ For details about the error codes, see [Location Error Codes](../errorcodes/erro ...@@ -1090,15 +1105,16 @@ For details about the error codes, see [Location Error Codes](../errorcodes/erro
```ts ```ts
import geoLocationManager from '@ohos.geoLocationManager'; import geoLocationManager from '@ohos.geoLocationManager';
let callback = (code) => { import BusinessError from "@ohos.base";
let callback = (code:Array<geoLocationManager.LocatingRequiredData>):void => {
console.log('locatingRequiredDataChange: ' + JSON.stringify(code)); console.log('locatingRequiredDataChange: ' + JSON.stringify(code));
} }
let config = {'type': 1, 'needStartScan': true, 'scanInterval': 10000}; let config:geoLocationManager.LocatingRequiredDataConfig = {'type': 1, 'needStartScan': true, 'scanInterval': 10000};
try { try {
geoLocationManager.on('locatingRequiredDataChange', config, callback); geoLocationManager.on('locatingRequiredDataChange', config, callback);
geoLocationManager.off('locatingRequiredDataChange', callback); geoLocationManager.off('locatingRequiredDataChange', callback);
} catch (err) { } catch (err) {
console.error("errCode:" + err.code + ",errMessage:" + err.message); console.error("errCode:" + (err as BusinessError.BusinessError).code + ",errMessage:" + (err as BusinessError.BusinessError).message);
} }
``` ```
...@@ -1134,8 +1150,9 @@ For details about the error codes, see [Location Error Codes](../errorcodes/erro ...@@ -1134,8 +1150,9 @@ For details about the error codes, see [Location Error Codes](../errorcodes/erro
```ts ```ts
import geoLocationManager from '@ohos.geoLocationManager'; import geoLocationManager from '@ohos.geoLocationManager';
let requestInfo = {'priority': geoLocationManager.LocationRequestPriority.FIRST_FIX, 'scenario': geoLocationManager.LocationRequestScenario.UNSET,'maxAccuracy': 0}; import BusinessError from "@ohos.base";
let locationChange = (err, location) => { let requestInfo:geoLocationManager.CurrentLocationRequest = {'priority': geoLocationManager.LocationRequestPriority.FIRST_FIX, 'scenario': geoLocationManager.LocationRequestScenario.UNSET,'maxAccuracy': 0};
let locationChange = (err:BusinessError.BusinessError, location:geoLocationManager.Location):void => {
if (err) { if (err) {
console.log('locationChanger: err=' + JSON.stringify(err)); console.log('locationChanger: err=' + JSON.stringify(err));
} }
...@@ -1147,7 +1164,7 @@ For details about the error codes, see [Location Error Codes](../errorcodes/erro ...@@ -1147,7 +1164,7 @@ For details about the error codes, see [Location Error Codes](../errorcodes/erro
try { try {
geoLocationManager.getCurrentLocation(requestInfo, locationChange); geoLocationManager.getCurrentLocation(requestInfo, locationChange);
} catch (err) { } catch (err) {
console.error("errCode:" + err.code + ",errMessage:" + err.message); console.error("errCode:" + (err as BusinessError.BusinessError).code + ",errMessage:" + (err as BusinessError.BusinessError).message);
} }
``` ```
...@@ -1181,7 +1198,8 @@ For details about the error codes, see [Location Error Codes](../errorcodes/erro ...@@ -1181,7 +1198,8 @@ For details about the error codes, see [Location Error Codes](../errorcodes/erro
```ts ```ts
import geoLocationManager from '@ohos.geoLocationManager'; import geoLocationManager from '@ohos.geoLocationManager';
let locationChange = (err, location) => { import BusinessError from "@ohos.base";
let locationChange = (err:BusinessError.BusinessError, location:geoLocationManager.Location) => {
if (err) { if (err) {
console.log('locationChanger: err=' + JSON.stringify(err)); console.log('locationChanger: err=' + JSON.stringify(err));
} }
...@@ -1193,7 +1211,7 @@ For details about the error codes, see [Location Error Codes](../errorcodes/erro ...@@ -1193,7 +1211,7 @@ For details about the error codes, see [Location Error Codes](../errorcodes/erro
try { try {
geoLocationManager.getCurrentLocation(locationChange); geoLocationManager.getCurrentLocation(locationChange);
} catch (err) { } catch (err) {
console.error("errCode:" + err.code + ",errMessage:" + err.message); console.error("errCode:" + (err as BusinessError.BusinessError).code + ",errMessage:" + (err as BusinessError.BusinessError).message);
} }
``` ```
...@@ -1233,16 +1251,17 @@ For details about the error codes, see [Location Error Codes](../errorcodes/erro ...@@ -1233,16 +1251,17 @@ For details about the error codes, see [Location Error Codes](../errorcodes/erro
```ts ```ts
import geoLocationManager from '@ohos.geoLocationManager'; import geoLocationManager from '@ohos.geoLocationManager';
let requestInfo = {'priority': geoLocationManager.LocationRequestPriority.FIRST_FIX, 'scenario': geoLocationManager.LocationRequestScenario.UNSET,'maxAccuracy': 0}; import BusinessError from "@ohos.base";
let requestInfo:geoLocationManager.CurrentLocationRequest = {'priority': geoLocationManager.LocationRequestPriority.FIRST_FIX, 'scenario': geoLocationManager.LocationRequestScenario.UNSET,'maxAccuracy': 0};
try { try {
geoLocationManager.getCurrentLocation(requestInfo).then((result) => { geoLocationManager.getCurrentLocation(requestInfo).then((result) => {
console.log('current location: ' + JSON.stringify(result)); console.log('current location: ' + JSON.stringify(result));
}) })
.catch((error) => { .catch((error:number) => {
console.log('promise, getCurrentLocation: error=' + JSON.stringify(error)); console.log('promise, getCurrentLocation: error=' + JSON.stringify(error));
}); });
} catch (err) { } catch (err) {
console.error("errCode:" + err.code + ",errMessage:" + err.message); console.error("errCode:" + (err as BusinessError.BusinessError).code + ",errMessage:" + (err as BusinessError.BusinessError).message);
} }
``` ```
...@@ -1277,10 +1296,11 @@ For details about the error codes, see [Location Error Codes](../errorcodes/erro ...@@ -1277,10 +1296,11 @@ For details about the error codes, see [Location Error Codes](../errorcodes/erro
```ts ```ts
import geoLocationManager from '@ohos.geoLocationManager'; import geoLocationManager from '@ohos.geoLocationManager';
import BusinessError from "@ohos.base";
try { try {
let location = geoLocationManager.getLastLocation(); let location = geoLocationManager.getLastLocation();
} catch (err) { } catch (err) {
console.error("errCode:" + err.code + ",errMessage:" + err.message); console.error("errCode:" + (err as BusinessError.BusinessError).code + ",errMessage:" + (err as BusinessError.BusinessError).message);
} }
``` ```
...@@ -1311,10 +1331,11 @@ For details about the error codes, see [Location Error Codes](../errorcodes/erro ...@@ -1311,10 +1331,11 @@ For details about the error codes, see [Location Error Codes](../errorcodes/erro
```ts ```ts
import geoLocationManager from '@ohos.geoLocationManager'; import geoLocationManager from '@ohos.geoLocationManager';
import BusinessError from "@ohos.base";
try { try {
let locationEnabled = geoLocationManager.isLocationEnabled(); let locationEnabled = geoLocationManager.isLocationEnabled();
} catch (err) { } catch (err) {
console.error("errCode:" + err.code + ",errMessage:" + err.message); console.error("errCode:" + (err as BusinessError.BusinessError).code + ",errMessage:" + (err as BusinessError.BusinessError).message);
} }
``` ```
...@@ -1349,6 +1370,7 @@ For details about the error codes, see [Location Error Codes](../errorcodes/erro ...@@ -1349,6 +1370,7 @@ For details about the error codes, see [Location Error Codes](../errorcodes/erro
```ts ```ts
import geoLocationManager from '@ohos.geoLocationManager'; import geoLocationManager from '@ohos.geoLocationManager';
import BusinessError from "@ohos.base";
try { try {
geoLocationManager.enableLocation((err, data) => { geoLocationManager.enableLocation((err, data) => {
if (err) { if (err) {
...@@ -1356,7 +1378,7 @@ For details about the error codes, see [Location Error Codes](../errorcodes/erro ...@@ -1356,7 +1378,7 @@ For details about the error codes, see [Location Error Codes](../errorcodes/erro
} }
}); });
} catch (err) { } catch (err) {
console.error("errCode:" + err.code + ",errMessage:" + err.message); console.error("errCode:" + (err as BusinessError.BusinessError).code + ",errMessage:" + (err as BusinessError.BusinessError).message);
} }
``` ```
...@@ -1391,15 +1413,16 @@ For details about the error codes, see [Location Error Codes](../errorcodes/erro ...@@ -1391,15 +1413,16 @@ For details about the error codes, see [Location Error Codes](../errorcodes/erro
```ts ```ts
import geoLocationManager from '@ohos.geoLocationManager'; import geoLocationManager from '@ohos.geoLocationManager';
import BusinessError from "@ohos.base";
try { try {
geoLocationManager.enableLocation().then((result) => { geoLocationManager.enableLocation().then((result) => {
console.log('promise, enableLocation succeed'); console.log('promise, enableLocation succeed');
}) })
.catch((error) => { .catch((error:number) => {
console.log('promise, enableLocation: error=' + JSON.stringify(error)); console.log('promise, enableLocation: error=' + JSON.stringify(error));
}); });
} catch (err) { } catch (err) {
console.error("errCode:" + err.code + ",errMessage:" + err.message); console.error("errCode:" + (err as BusinessError.BusinessError).code + ",errMessage:" + (err as BusinessError.BusinessError).message);
} }
``` ```
...@@ -1427,10 +1450,11 @@ For details about the error codes, see [Location Error Codes](../errorcodes/erro ...@@ -1427,10 +1450,11 @@ For details about the error codes, see [Location Error Codes](../errorcodes/erro
```ts ```ts
import geoLocationManager from '@ohos.geoLocationManager'; import geoLocationManager from '@ohos.geoLocationManager';
import BusinessError from "@ohos.base";
try { try {
geoLocationManager.disableLocation(); geoLocationManager.disableLocation();
} catch (err) { } catch (err) {
console.error("errCode:" + err.code + ",errMessage:" + err.message); console.error("errCode:" + (err as BusinessError.BusinessError).code + ",errMessage:" + (err as BusinessError.BusinessError).message);
} }
``` ```
...@@ -1463,7 +1487,8 @@ For details about the error codes, see [Location Error Codes](../errorcodes/erro ...@@ -1463,7 +1487,8 @@ For details about the error codes, see [Location Error Codes](../errorcodes/erro
```ts ```ts
import geoLocationManager from '@ohos.geoLocationManager'; import geoLocationManager from '@ohos.geoLocationManager';
let reverseGeocodeRequest = {"latitude": 31.12, "longitude": 121.11, "maxItems": 1}; import BusinessError from "@ohos.base";
let reverseGeocodeRequest:geoLocationManager.ReverseGeoCodeRequest = {"latitude": 31.12, "longitude": 121.11, "maxItems": 1};
try { try {
geoLocationManager.getAddressesFromLocation(reverseGeocodeRequest, (err, data) => { geoLocationManager.getAddressesFromLocation(reverseGeocodeRequest, (err, data) => {
if (err) { if (err) {
...@@ -1474,7 +1499,7 @@ For details about the error codes, see [Location Error Codes](../errorcodes/erro ...@@ -1474,7 +1499,7 @@ For details about the error codes, see [Location Error Codes](../errorcodes/erro
} }
}); });
} catch (err) { } catch (err) {
console.error("errCode:" + err.code + ",errMessage:" + err.message); console.error("errCode:" + (err as BusinessError.BusinessError).code + ",errMessage:" + (err as BusinessError.BusinessError).message);
} }
``` ```
...@@ -1512,16 +1537,17 @@ For details about the error codes, see [Location Error Codes](../errorcodes/erro ...@@ -1512,16 +1537,17 @@ For details about the error codes, see [Location Error Codes](../errorcodes/erro
```ts ```ts
import geoLocationManager from '@ohos.geoLocationManager'; import geoLocationManager from '@ohos.geoLocationManager';
let reverseGeocodeRequest = {"latitude": 31.12, "longitude": 121.11, "maxItems": 1}; import BusinessError from "@ohos.base";
let reverseGeocodeRequest:geoLocationManager.ReverseGeoCodeRequest = {"latitude": 31.12, "longitude": 121.11, "maxItems": 1};
try { try {
geoLocationManager.getAddressesFromLocation(reverseGeocodeRequest).then((data) => { geoLocationManager.getAddressesFromLocation(reverseGeocodeRequest).then((data) => {
console.log('getAddressesFromLocation: ' + JSON.stringify(data)); console.log('getAddressesFromLocation: ' + JSON.stringify(data));
}) })
.catch((error) => { .catch((error:number) => {
console.log('promise, getAddressesFromLocation: error=' + JSON.stringify(error)); console.log('promise, getAddressesFromLocation: error=' + JSON.stringify(error));
}); });
} catch (err) { } catch (err) {
console.error("errCode:" + err.code + ",errMessage:" + err.message); console.error("errCode:" + (err as BusinessError.BusinessError).code + ",errMessage:" + (err as BusinessError.BusinessError).message);
} }
``` ```
...@@ -1554,7 +1580,8 @@ For details about the error codes, see [Location Error Codes](../errorcodes/erro ...@@ -1554,7 +1580,8 @@ For details about the error codes, see [Location Error Codes](../errorcodes/erro
```ts ```ts
import geoLocationManager from '@ohos.geoLocationManager'; import geoLocationManager from '@ohos.geoLocationManager';
let geocodeRequest = {"description": "No. xx, xx Road, Pudong District, Shanghai", "maxItems": 1}; import BusinessError from "@ohos.base";
let geocodeRequest:geoLocationManager.GeoCodeRequest = {"description": "No. xx, xx Road, Pudong District, Shanghai", "maxItems": 1};
try { try {
geoLocationManager.getAddressesFromLocationName(geocodeRequest, (err, data) => { geoLocationManager.getAddressesFromLocationName(geocodeRequest, (err, data) => {
if (err) { if (err) {
...@@ -1565,7 +1592,7 @@ For details about the error codes, see [Location Error Codes](../errorcodes/erro ...@@ -1565,7 +1592,7 @@ For details about the error codes, see [Location Error Codes](../errorcodes/erro
} }
}); });
} catch (err) { } catch (err) {
console.error("errCode:" + err.code + ",errMessage:" + err.message); console.error("errCode:" + (err as BusinessError.BusinessError).code + ",errMessage:" + (err as BusinessError.BusinessError).message);
} }
``` ```
...@@ -1603,16 +1630,17 @@ For details about the error codes, see [Location Error Codes](../errorcodes/erro ...@@ -1603,16 +1630,17 @@ For details about the error codes, see [Location Error Codes](../errorcodes/erro
```ts ```ts
import geoLocationManager from '@ohos.geoLocationManager'; import geoLocationManager from '@ohos.geoLocationManager';
let geocodeRequest = {"description": "No. xx, xx Road, Pudong District, Shanghai", "maxItems": 1}; import BusinessError from "@ohos.base";
let geocodeRequest:geoLocationManager.GeoCodeRequest = {"description": "No. xx, xx Road, Pudong District, Shanghai", "maxItems": 1};
try { try {
geoLocationManager.getAddressesFromLocationName(geocodeRequest).then((result) => { geoLocationManager.getAddressesFromLocationName(geocodeRequest).then((result) => {
console.log('getAddressesFromLocationName: ' + JSON.stringify(result)); console.log('getAddressesFromLocationName: ' + JSON.stringify(result));
}) })
.catch((error) => { .catch((error:number) => {
console.log('promise, getAddressesFromLocationName: error=' + JSON.stringify(error)); console.log('promise, getAddressesFromLocationName: error=' + JSON.stringify(error));
}); });
} catch (err) { } catch (err) {
console.error("errCode:" + err.code + ",errMessage:" + err.message); console.error("errCode:" + (err as BusinessError.BusinessError).code + ",errMessage:" + (err as BusinessError.BusinessError).message);
} }
``` ```
...@@ -1642,10 +1670,11 @@ For details about the error codes, see [Location Error Codes](../errorcodes/erro ...@@ -1642,10 +1670,11 @@ For details about the error codes, see [Location Error Codes](../errorcodes/erro
```ts ```ts
import geoLocationManager from '@ohos.geoLocationManager'; import geoLocationManager from '@ohos.geoLocationManager';
import BusinessError from "@ohos.base";
try { try {
let isAvailable = geoLocationManager.isGeocoderAvailable(); let isAvailable = geoLocationManager.isGeocoderAvailable();
} catch (err) { } catch (err) {
console.error("errCode:" + err.code + ",errMessage:" + err.message); console.error("errCode:" + (err as BusinessError.BusinessError).code + ",errMessage:" + (err as BusinessError.BusinessError).message);
} }
``` ```
...@@ -1679,6 +1708,7 @@ For details about the error codes, see [Location Error Codes](../errorcodes/erro ...@@ -1679,6 +1708,7 @@ For details about the error codes, see [Location Error Codes](../errorcodes/erro
```ts ```ts
import geoLocationManager from '@ohos.geoLocationManager'; import geoLocationManager from '@ohos.geoLocationManager';
import BusinessError from "@ohos.base";
try { try {
geoLocationManager.getCachedGnssLocationsSize((err, size) => { geoLocationManager.getCachedGnssLocationsSize((err, size) => {
if (err) { if (err) {
...@@ -1689,7 +1719,7 @@ For details about the error codes, see [Location Error Codes](../errorcodes/erro ...@@ -1689,7 +1719,7 @@ For details about the error codes, see [Location Error Codes](../errorcodes/erro
} }
}); });
} catch (err) { } catch (err) {
console.error("errCode:" + err.code + ",errMessage:" + err.message); console.error("errCode:" + (err as BusinessError.BusinessError).code + ",errMessage:" + (err as BusinessError.BusinessError).message);
} }
``` ```
...@@ -1723,15 +1753,16 @@ For details about the error codes, see [Location Error Codes](../errorcodes/erro ...@@ -1723,15 +1753,16 @@ For details about the error codes, see [Location Error Codes](../errorcodes/erro
```ts ```ts
import geoLocationManager from '@ohos.geoLocationManager'; import geoLocationManager from '@ohos.geoLocationManager';
import BusinessError from "@ohos.base";
try { try {
geoLocationManager.getCachedGnssLocationsSize().then((result) => { geoLocationManager.getCachedGnssLocationsSize().then((result) => {
console.log('promise, getCachedGnssLocationsSize: ' + JSON.stringify(result)); console.log('promise, getCachedGnssLocationsSize: ' + JSON.stringify(result));
}) })
.catch((error) => { .catch((error:number) => {
console.log('promise, getCachedGnssLocationsSize: error=' + JSON.stringify(error)); console.log('promise, getCachedGnssLocationsSize: error=' + JSON.stringify(error));
}); });
} catch (err) { } catch (err) {
console.error("errCode:" + err.code + ",errMessage:" + err.message); console.error("errCode:" + (err as BusinessError.BusinessError).code + ",errMessage:" + (err as BusinessError.BusinessError).message);
} }
``` ```
...@@ -1766,6 +1797,7 @@ For details about the error codes, see [Location Error Codes](../errorcodes/erro ...@@ -1766,6 +1797,7 @@ For details about the error codes, see [Location Error Codes](../errorcodes/erro
```ts ```ts
import geoLocationManager from '@ohos.geoLocationManager'; import geoLocationManager from '@ohos.geoLocationManager';
import BusinessError from "@ohos.base";
try { try {
geoLocationManager.flushCachedGnssLocations((err, result) => { geoLocationManager.flushCachedGnssLocations((err, result) => {
if (err) { if (err) {
...@@ -1773,7 +1805,7 @@ For details about the error codes, see [Location Error Codes](../errorcodes/erro ...@@ -1773,7 +1805,7 @@ For details about the error codes, see [Location Error Codes](../errorcodes/erro
} }
}); });
} catch (err) { } catch (err) {
console.error("errCode:" + err.code + ",errMessage:" + err.message); console.error("errCode:" + (err as BusinessError.BusinessError).code + ",errMessage:" + (err as BusinessError.BusinessError).message);
} }
``` ```
...@@ -1808,15 +1840,16 @@ For details about the error codes, see [Location Error Codes](../errorcodes/erro ...@@ -1808,15 +1840,16 @@ For details about the error codes, see [Location Error Codes](../errorcodes/erro
```ts ```ts
import geoLocationManager from '@ohos.geoLocationManager'; import geoLocationManager from '@ohos.geoLocationManager';
import BusinessError from "@ohos.base";
try { try {
geoLocationManager.flushCachedGnssLocations().then((result) => { geoLocationManager.flushCachedGnssLocations().then((result) => {
console.log('promise, flushCachedGnssLocations success'); console.log('promise, flushCachedGnssLocations success');
}) })
.catch((error) => { .catch((error:number) => {
console.log('promise, flushCachedGnssLocations: error=' + JSON.stringify(error)); console.log('promise, flushCachedGnssLocations: error=' + JSON.stringify(error));
}); });
} catch (err) { } catch (err) {
console.error("errCode:" + err.code + ",errMessage:" + err.message); console.error("errCode:" + (err as BusinessError.BusinessError).code + ",errMessage:" + (err as BusinessError.BusinessError).message);
} }
``` ```
...@@ -1848,7 +1881,8 @@ For details about the error codes, see [Location Error Codes](../errorcodes/erro ...@@ -1848,7 +1881,8 @@ For details about the error codes, see [Location Error Codes](../errorcodes/erro
```ts ```ts
import geoLocationManager from '@ohos.geoLocationManager'; import geoLocationManager from '@ohos.geoLocationManager';
let requestInfo = {'scenario': 0x301, 'command': "command_1"}; import BusinessError from "@ohos.base";
let requestInfo:geoLocationManager.LocationCommand = {'scenario': 0x301, 'command': "command_1"};
try { try {
geoLocationManager.sendCommand(requestInfo, (err, result) => { geoLocationManager.sendCommand(requestInfo, (err, result) => {
if (err) { if (err) {
...@@ -1856,7 +1890,7 @@ For details about the error codes, see [Location Error Codes](../errorcodes/erro ...@@ -1856,7 +1890,7 @@ For details about the error codes, see [Location Error Codes](../errorcodes/erro
} }
}); });
} catch (err) { } catch (err) {
console.error("errCode:" + err.code + ",errMessage:" + err.message); console.error("errCode:" + (err as BusinessError.BusinessError).code + ",errMessage:" + (err as BusinessError.BusinessError).message);
} }
``` ```
...@@ -1893,16 +1927,17 @@ For details about the error codes, see [Location Error Codes](../errorcodes/erro ...@@ -1893,16 +1927,17 @@ For details about the error codes, see [Location Error Codes](../errorcodes/erro
```ts ```ts
import geoLocationManager from '@ohos.geoLocationManager'; import geoLocationManager from '@ohos.geoLocationManager';
let requestInfo = {'scenario': 0x301, 'command': "command_1"}; import BusinessError from "@ohos.base";
let requestInfo:geoLocationManager.LocationCommand = {'scenario': 0x301, 'command': "command_1"};
try { try {
geoLocationManager.sendCommand(requestInfo).then((result) => { geoLocationManager.sendCommand(requestInfo).then((result) => {
console.log('promise, sendCommand success'); console.log('promise, sendCommand success');
}) })
.catch((error) => { .catch((error:number) => {
console.log('promise, sendCommand: error=' + JSON.stringify(error)); console.log('promise, sendCommand: error=' + JSON.stringify(error));
}); });
} catch (err) { } catch (err) {
console.error("errCode:" + err.code + ",errMessage:" + err.message); console.error("errCode:" + (err as BusinessError.BusinessError).code + ",errMessage:" + (err as BusinessError.BusinessError).message);
} }
``` ```
...@@ -1934,6 +1969,7 @@ For details about the error codes, see [Location Error Codes](../errorcodes/erro ...@@ -1934,6 +1969,7 @@ For details about the error codes, see [Location Error Codes](../errorcodes/erro
```ts ```ts
import geoLocationManager from '@ohos.geoLocationManager'; import geoLocationManager from '@ohos.geoLocationManager';
import BusinessError from "@ohos.base";
try { try {
geoLocationManager.getCountryCode((err, result) => { geoLocationManager.getCountryCode((err, result) => {
if (err) { if (err) {
...@@ -1944,7 +1980,7 @@ For details about the error codes, see [Location Error Codes](../errorcodes/erro ...@@ -1944,7 +1980,7 @@ For details about the error codes, see [Location Error Codes](../errorcodes/erro
} }
}); });
} catch (err) { } catch (err) {
console.error("errCode:" + err.code + ",errMessage:" + err.message); console.error("errCode:" + (err as BusinessError.BusinessError).code + ",errMessage:" + (err as BusinessError.BusinessError).message);
} }
``` ```
...@@ -1976,16 +2012,17 @@ For details about the error codes, see [Location Error Codes](../errorcodes/erro ...@@ -1976,16 +2012,17 @@ For details about the error codes, see [Location Error Codes](../errorcodes/erro
```ts ```ts
import geoLocationManager from '@ohos.geoLocationManager'; import geoLocationManager from '@ohos.geoLocationManager';
import BusinessError from "@ohos.base";
try { try {
geoLocationManager.getCountryCode() geoLocationManager.getCountryCode()
.then((result) => { .then((result) => {
console.log('promise, getCountryCode: result=' + JSON.stringify(result)); console.log('promise, getCountryCode: result=' + JSON.stringify(result));
}) })
.catch((error) => { .catch((error:number) => {
console.log('promise, getCountryCode: error=' + JSON.stringify(error)); console.log('promise, getCountryCode: error=' + JSON.stringify(error));
}); });
} catch (err) { } catch (err) {
console.error("errCode:" + err.code + ",errMessage:" + err.message); console.error("errCode:" + (err as BusinessError.BusinessError).code + ",errMessage:" + (err as BusinessError.BusinessError).message);
} }
``` ```
...@@ -2013,10 +2050,11 @@ For details about the error codes, see [Location Error Codes](../errorcodes/erro ...@@ -2013,10 +2050,11 @@ For details about the error codes, see [Location Error Codes](../errorcodes/erro
```ts ```ts
import geoLocationManager from '@ohos.geoLocationManager'; import geoLocationManager from '@ohos.geoLocationManager';
import BusinessError from "@ohos.base";
try { try {
geoLocationManager.enableLocationMock(); geoLocationManager.enableLocationMock();
} catch (err) { } catch (err) {
console.error("errCode:" + err.code + ",errMessage:" + err.message); console.error("errCode:" + (err as BusinessError.BusinessError).code + ",errMessage:" + (err as BusinessError.BusinessError).message);
} }
``` ```
...@@ -2044,10 +2082,11 @@ For details about the error codes, see [Location Error Codes](../errorcodes/erro ...@@ -2044,10 +2082,11 @@ For details about the error codes, see [Location Error Codes](../errorcodes/erro
```ts ```ts
import geoLocationManager from '@ohos.geoLocationManager'; import geoLocationManager from '@ohos.geoLocationManager';
import BusinessError from "@ohos.base";
try { try {
geoLocationManager.disableLocationMock(); geoLocationManager.disableLocationMock();
} catch (err) { } catch (err) {
console.error("errCode:" + err.code + ",errMessage:" + err.message); console.error("errCode:" + (err as BusinessError.BusinessError).code + ",errMessage:" + (err as BusinessError.BusinessError).message);
} }
``` ```
...@@ -2083,19 +2122,20 @@ For details about the error codes, see [Location Error Codes](../errorcodes/erro ...@@ -2083,19 +2122,20 @@ For details about the error codes, see [Location Error Codes](../errorcodes/erro
```ts ```ts
import geoLocationManager from '@ohos.geoLocationManager'; import geoLocationManager from '@ohos.geoLocationManager';
let locations = [ import BusinessError from "@ohos.base";
let locations:Array<geoLocationManager.Location> = [
{"latitude": 30.12, "longitude": 120.11, "altitude": 123, "accuracy": 1, "speed": 5.2, "timeStamp": 16594326109, "direction": 123.11, "timeSinceBoot": 1000000000, "additionSize": 0, "isFromMock": true}, {"latitude": 30.12, "longitude": 120.11, "altitude": 123, "accuracy": 1, "speed": 5.2, "timeStamp": 16594326109, "direction": 123.11, "timeSinceBoot": 1000000000, "additionSize": 0, "isFromMock": true},
{"latitude": 31.13, "longitude": 121.11, "altitude": 123, "accuracy": 2, "speed": 5.2, "timeStamp": 16594326109, "direction": 123.11, "timeSinceBoot": 2000000000, "additionSize": 0, "isFromMock": true}, {"latitude": 31.13, "longitude": 121.11, "altitude": 123, "accuracy": 2, "speed": 5.2, "timeStamp": 16594326109, "direction": 123.11, "timeSinceBoot": 2000000000, "additionSize": 0, "isFromMock": true},
{"latitude": 32.14, "longitude": 122.11, "altitude": 123, "accuracy": 3, "speed": 5.2, "timeStamp": 16594326109, "direction": 123.11, "timeSinceBoot": 3000000000, "additionSize": 0, "isFromMock": true}, {"latitude": 32.14, "longitude": 122.11, "altitude": 123, "accuracy": 3, "speed": 5.2, "timeStamp": 16594326109, "direction": 123.11, "timeSinceBoot": 3000000000, "additionSize": 0, "isFromMock": true},
{"latitude": 33.15, "longitude": 123.11, "altitude": 123, "accuracy": 4, "speed": 5.2, "timeStamp": 16594326109, "direction": 123.11, "timeSinceBoot": 4000000000, "additionSize": 0, "isFromMock": true}, {"latitude": 33.15, "longitude": 123.11, "altitude": 123, "accuracy": 4, "speed": 5.2, "timeStamp": 16594326109, "direction": 123.11, "timeSinceBoot": 4000000000, "additionSize": 0, "isFromMock": true},
{"latitude": 34.16, "longitude": 124.11, "altitude": 123, "accuracy": 5, "speed": 5.2, "timeStamp": 16594326109, "direction": 123.11, "timeSinceBoot": 5000000000, "additionSize": 0, "isFromMock": true} {"latitude": 34.16, "longitude": 124.11, "altitude": 123, "accuracy": 5, "speed": 5.2, "timeStamp": 16594326109, "direction": 123.11, "timeSinceBoot": 5000000000, "additionSize": 0, "isFromMock": true}
]; ];
let config = {"timeInterval": 5, "locations": locations}; let config:geoLocationManager.LocationMockConfig = {"timeInterval": 5, "locations": locations};
try { try {
geoLocationManager.enableLocationMock(); geoLocationManager.enableLocationMock();
geoLocationManager.setMockedLocations(config); geoLocationManager.setMockedLocations(config);
} catch (err) { } catch (err) {
console.error("errCode:" + err.code + ",errMessage:" + err.message); console.error("errCode:" + (err as BusinessError.BusinessError).code + ",errMessage:" + (err as BusinessError.BusinessError).message);
} }
``` ```
...@@ -2122,10 +2162,11 @@ For details about the error codes, see [Location Error Codes](../errorcodes/erro ...@@ -2122,10 +2162,11 @@ For details about the error codes, see [Location Error Codes](../errorcodes/erro
```ts ```ts
import geoLocationManager from '@ohos.geoLocationManager'; import geoLocationManager from '@ohos.geoLocationManager';
import BusinessError from "@ohos.base";
try { try {
geoLocationManager.enableReverseGeocodingMock(); geoLocationManager.enableReverseGeocodingMock();
} catch (err) { } catch (err) {
console.error("errCode:" + err.code + ",errMessage:" + err.message); console.error("errCode:" + (err as BusinessError.BusinessError).code + ",errMessage:" + (err as BusinessError.BusinessError).message);
} }
``` ```
...@@ -2152,10 +2193,11 @@ For details about the error codes, see [Location Error Codes](../errorcodes/erro ...@@ -2152,10 +2193,11 @@ For details about the error codes, see [Location Error Codes](../errorcodes/erro
```ts ```ts
import geoLocationManager from '@ohos.geoLocationManager'; import geoLocationManager from '@ohos.geoLocationManager';
import BusinessError from "@ohos.base";
try { try {
geoLocationManager.disableReverseGeocodingMock(); geoLocationManager.disableReverseGeocodingMock();
} catch (err) { } catch (err) {
console.error("errCode:" + err.code + ",errMessage:" + err.message); console.error("errCode:" + (err as BusinessError.BusinessError).code + ",errMessage:" + (err as BusinessError.BusinessError).message);
} }
``` ```
...@@ -2190,18 +2232,19 @@ For details about the error codes, see [Location Error Codes](../errorcodes/erro ...@@ -2190,18 +2232,19 @@ For details about the error codes, see [Location Error Codes](../errorcodes/erro
```ts ```ts
import geoLocationManager from '@ohos.geoLocationManager'; import geoLocationManager from '@ohos.geoLocationManager';
let mockInfos = [ import BusinessError from "@ohos.base";
{"location": {"locale": "zh", "latitude": 30.12, "longitude": 120.11, "maxItems": 1}, "geoAddress": {"locale": "zh", "latitude": 30.12, "longitude": 120.11, "maxItems": 1, "isFromMock": true}}, let mockInfos:Array<geoLocationManager.ReverseGeocodingMockInfo> = [
{"location": {"locale": "zh", "latitude": 31.12, "longitude": 121.11, "maxItems": 1}, "geoAddress": {"locale": "zh", "latitude": 31.12, "longitude": 121.11, "maxItems": 1, "isFromMock": true}}, {"location": {"locale": "zh", "latitude": 30.12, "longitude": 120.11, "maxItems": 1}, "geoAddress": {"locale": "zh", "latitude": 30.12, "longitude": 120.11, "isFromMock": true}},
{"location": {"locale": "zh", "latitude": 32.12, "longitude": 122.11, "maxItems": 1}, "geoAddress": {"locale": "zh", "latitude": 32.12, "longitude": 122.11, "maxItems": 1, "isFromMock": true}}, {"location": {"locale": "zh", "latitude": 31.12, "longitude": 121.11, "maxItems": 1}, "geoAddress": {"locale": "zh", "latitude": 31.12, "longitude": 121.11, "isFromMock": true}},
{"location": {"locale": "zh", "latitude": 33.12, "longitude": 123.11, "maxItems": 1}, "geoAddress": {"locale": "zh", "latitude": 33.12, "longitude": 123.11, "maxItems": 1, "isFromMock": true}}, {"location": {"locale": "zh", "latitude": 32.12, "longitude": 122.11, "maxItems": 1}, "geoAddress": {"locale": "zh", "latitude": 32.12, "longitude": 122.11, "isFromMock": true}},
{"location": {"locale": "zh", "latitude": 34.12, "longitude": 124.11, "maxItems": 1}, "geoAddress": {"locale": "zh", "latitude": 34.12, "longitude": 124.11, "maxItems": 1, "isFromMock": true}}, {"location": {"locale": "zh", "latitude": 33.12, "longitude": 123.11, "maxItems": 1}, "geoAddress": {"locale": "zh", "latitude": 33.12, "longitude": 123.11, "isFromMock": true}},
{"location": {"locale": "zh", "latitude": 34.12, "longitude": 124.11, "maxItems": 1}, "geoAddress": {"locale": "zh", "latitude": 34.12, "longitude": 124.11, "isFromMock": true}},
]; ];
try { try {
geoLocationManager.enableReverseGeocodingMock(); geoLocationManager.enableReverseGeocodingMock();
geoLocationManager.setReverseGeocodingMockInfo(mockInfos); geoLocationManager.setReverseGeocodingMockInfo(mockInfos);
} catch (err) { } catch (err) {
console.error("errCode:" + err.code + ",errMessage:" + err.message); console.error("errCode:" + (err as BusinessError.BusinessError).code + ",errMessage:" + (err as BusinessError.BusinessError).message);
} }
``` ```
...@@ -2240,10 +2283,11 @@ For details about the error codes, see [Location Error Codes](../errorcodes/erro ...@@ -2240,10 +2283,11 @@ For details about the error codes, see [Location Error Codes](../errorcodes/erro
```ts ```ts
import geoLocationManager from '@ohos.geoLocationManager'; import geoLocationManager from '@ohos.geoLocationManager';
import BusinessError from "@ohos.base";
try { try {
let isConfirmed = geoLocationManager.isLocationPrivacyConfirmed(1); let isConfirmed = geoLocationManager.isLocationPrivacyConfirmed(1);
} catch (err) { } catch (err) {
console.error("errCode:" + err.code + ",errMessage:" + err.message); console.error("errCode:" + (err as BusinessError.BusinessError).code + ",errMessage:" + (err as BusinessError.BusinessError).message);
} }
``` ```
...@@ -2279,10 +2323,11 @@ For details about the error codes, see [Location Error Codes](../errorcodes/erro ...@@ -2279,10 +2323,11 @@ For details about the error codes, see [Location Error Codes](../errorcodes/erro
```ts ```ts
import geoLocationManager from '@ohos.geoLocationManager'; import geoLocationManager from '@ohos.geoLocationManager';
import BusinessError from "@ohos.base";
try { try {
geoLocationManager.setLocationPrivacyConfirmStatus(1, true); geoLocationManager.setLocationPrivacyConfirmStatus(1, true);
} catch (err) { } catch (err) {
console.error("errCode:" + err.code + ",errMessage:" + err.message); console.error("errCode:" + (err as BusinessError.BusinessError).code + ",errMessage:" + (err as BusinessError.BusinessError).message);
} }
``` ```
...@@ -2323,15 +2368,16 @@ For details about the error codes, see [Location Error Codes](../errorcodes/erro ...@@ -2323,15 +2368,16 @@ For details about the error codes, see [Location Error Codes](../errorcodes/erro
```ts ```ts
import geoLocationManager from '@ohos.geoLocationManager'; import geoLocationManager from '@ohos.geoLocationManager';
let config = {'type': 1, 'needStartScan': true, 'scanInterval': 10000}; import BusinessError from "@ohos.base";
let config:geoLocationManager.LocatingRequiredDataConfig = {'type': 1, 'needStartScan': true, 'scanInterval': 10000};
try { try {
geoLocationManager.getLocatingRequiredData(config).then((result) => { geoLocationManager.getLocatingRequiredData(config).then((result) => {
console.log('getLocatingRequiredData return: ' + JSON.stringify(result)); console.log('getLocatingRequiredData return: ' + JSON.stringify(result));
}) })
.catch((error) => { .catch((error:number) => {
console.log('promise, getLocatingRequiredData: error=' + JSON.stringify(error)); console.log('promise, getLocatingRequiredData: error=' + JSON.stringify(error));
}); });
} catch (err) { } catch (err) {
console.error("errCode:" + err.code + ",errMessage:" + err.message); console.error("errCode:" + (err as BusinessError.BusinessError).code + ",errMessage:" + (err as BusinessError.BusinessError).message);
} }
``` ```
...@@ -60,7 +60,7 @@ Registers a listener for location changes with a location request initiated. ...@@ -60,7 +60,7 @@ Registers a listener for location changes with a location request initiated.
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| type | string | Yes| Event type. The value **locationChange** indicates a location change event.| | type | string | Yes| Event type. The value **locationChange** indicates a location change event.|
| request | [LocationRequest](#locationrequestdeprecated) | Yes| Location request.| | request | [LocationRequest](#locationrequestdeprecated) | Yes| Location request.|
| callback | Callback&lt;[Location](#locationdeprecated)&gt; | Yes| Callback used to return the location change event.| | callback | Callback&lt;[Location](#locationdeprecated)&gt; | Yes| Callback used to receive the location change event.|
...@@ -68,8 +68,8 @@ Registers a listener for location changes with a location request initiated. ...@@ -68,8 +68,8 @@ Registers a listener for location changes with a location request initiated.
```ts ```ts
import geolocation from '@ohos.geolocation'; import geolocation from '@ohos.geolocation';
let requestInfo = {'priority': 0x203, 'scenario': 0x300, 'timeInterval': 0, 'distanceInterval': 0, 'maxAccuracy': 0}; let requestInfo:geolocation.LocationRequest = {'priority': 0x203, 'scenario': 0x300, 'timeInterval': 0, 'distanceInterval': 0, 'maxAccuracy': 0};
let locationChange = (location) => { let locationChange = (location:geolocation.Location):void => {
console.log('locationChanger: data: ' + JSON.stringify(location)); console.log('locationChanger: data: ' + JSON.stringify(location));
}; };
geolocation.on('locationChange', requestInfo, locationChange); geolocation.on('locationChange', requestInfo, locationChange);
...@@ -101,8 +101,8 @@ Unregisters the listener for location changes with the corresponding location re ...@@ -101,8 +101,8 @@ Unregisters the listener for location changes with the corresponding location re
```ts ```ts
import geolocation from '@ohos.geolocation'; import geolocation from '@ohos.geolocation';
let requestInfo = {'priority': 0x203, 'scenario': 0x300, 'timeInterval': 0, 'distanceInterval': 0, 'maxAccuracy': 0}; let requestInfo:geolocation.LocationRequest = {'priority': 0x203, 'scenario': 0x300, 'timeInterval': 0, 'distanceInterval': 0, 'maxAccuracy': 0};
let locationChange = (location) => { let locationChange = (location:geolocation.Location):void => {
console.log('locationChanger: data: ' + JSON.stringify(location)); console.log('locationChanger: data: ' + JSON.stringify(location));
}; };
geolocation.on('locationChange', requestInfo, locationChange); geolocation.on('locationChange', requestInfo, locationChange);
...@@ -128,14 +128,14 @@ Registers a listener for location service status change events. ...@@ -128,14 +128,14 @@ Registers a listener for location service status change events.
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| type | string | Yes| Event type. The value **locationServiceState** indicates a location service status change event.| | type | string | Yes| Event type. The value **locationServiceState** indicates a location service status change event.|
| callback | Callback&lt;boolean&gt; | Yes| Callback used to return the location service status change event.| | callback | Callback&lt;boolean&gt; | Yes| Callback used to receive the location service status change event.|
**Example** **Example**
```ts ```ts
import geolocation from '@ohos.geolocation'; import geolocation from '@ohos.geolocation';
let locationServiceState = (state) => { let locationServiceState = (state:boolean):void => {
console.log('locationServiceState: ' + JSON.stringify(state)); console.log('locationServiceState: ' + JSON.stringify(state));
} }
geolocation.on('locationServiceState', locationServiceState); geolocation.on('locationServiceState', locationServiceState);
...@@ -167,7 +167,7 @@ Unregisters the listener for location service status change events. ...@@ -167,7 +167,7 @@ Unregisters the listener for location service status change events.
```ts ```ts
import geolocation from '@ohos.geolocation'; import geolocation from '@ohos.geolocation';
let locationServiceState = (state) => { let locationServiceState = (state:boolean):void => {
console.log('locationServiceState: state: ' + JSON.stringify(state)); console.log('locationServiceState: state: ' + JSON.stringify(state));
} }
geolocation.on('locationServiceState', locationServiceState); geolocation.on('locationServiceState', locationServiceState);
...@@ -195,17 +195,17 @@ Registers a listener for cached GNSS location reports. ...@@ -195,17 +195,17 @@ Registers a listener for cached GNSS location reports.
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| type | string | Yes| Event type. The value **cachedGnssLocationsReporting** indicates reporting of cached GNSS locations.| | type | string | Yes| Event type. The value **cachedGnssLocationsReporting** indicates reporting of cached GNSS locations.|
| request | [CachedGnssLocationsRequest](#cachedgnsslocationsrequestdeprecated) | Yes| Request for reporting cached GNSS location.| | request | [CachedGnssLocationsRequest](#cachedgnsslocationsrequestdeprecated) | Yes| Request for reporting cached GNSS location.|
| callback | Callback&lt;Array&lt;[Location](#locationdeprecated)&gt;&gt; | Yes| Callback used to return cached GNSS locations.| | callback | Callback&lt;Array&lt;[Location](#locationdeprecated)&gt;&gt; | Yes| Callback used to receive the cached GNSS locations.|
**Example** **Example**
```ts ```ts
import geolocation from '@ohos.geolocation'; import geolocation from '@ohos.geolocation';
let cachedLocationsCb = (locations) => { let cachedLocationsCb = (locations:Array<geolocation.Location>):void => {
console.log('cachedGnssLocationsReporting: locations: ' + JSON.stringify(locations)); console.log('cachedGnssLocationsReporting: locations: ' + JSON.stringify(locations));
} }
let requestInfo = {'reportingPeriodSec': 10, 'wakeUpCacheQueueFull': true}; let requestInfo:geolocation.CachedGnssLocationsRequest = {'reportingPeriodSec': 10, 'wakeUpCacheQueueFull': true};
geolocation.on('cachedGnssLocationsReporting', requestInfo, cachedLocationsCb); geolocation.on('cachedGnssLocationsReporting', requestInfo, cachedLocationsCb);
``` ```
...@@ -236,10 +236,10 @@ Unregisters the listener for cached GNSS location reports. ...@@ -236,10 +236,10 @@ Unregisters the listener for cached GNSS location reports.
```ts ```ts
import geolocation from '@ohos.geolocation'; import geolocation from '@ohos.geolocation';
let cachedLocationsCb = (locations) => { let cachedLocationsCb = (locations:Array<geolocation.Location>):void => {
console.log('cachedGnssLocationsReporting: locations: ' + JSON.stringify(locations)); console.log('cachedGnssLocationsReporting: locations: ' + JSON.stringify(locations));
} }
let requestInfo = {'reportingPeriodSec': 10, 'wakeUpCacheQueueFull': true}; let requestInfo:geolocation.CachedGnssLocationsRequest = {'reportingPeriodSec': 10, 'wakeUpCacheQueueFull': true};
geolocation.on('cachedGnssLocationsReporting', requestInfo, cachedLocationsCb); geolocation.on('cachedGnssLocationsReporting', requestInfo, cachedLocationsCb);
geolocation.off('cachedGnssLocationsReporting'); geolocation.off('cachedGnssLocationsReporting');
``` ```
...@@ -264,14 +264,14 @@ Registers a listener for GNSS satellite status change events. ...@@ -264,14 +264,14 @@ Registers a listener for GNSS satellite status change events.
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| type | string | Yes| Event type. The value **gnssStatusChange** indicates a GNSS satellite status change.| | type | string | Yes| Event type. The value **gnssStatusChange** indicates a GNSS satellite status change.|
| callback | Callback&lt;[SatelliteStatusInfo](#satellitestatusinfodeprecated)&gt; | Yes| Callback used to return GNSS satellite status changes.| | callback | Callback&lt;[SatelliteStatusInfo](#satellitestatusinfodeprecated)&gt; | Yes| Callback used to receive GNSS satellite status changes.|
**Example** **Example**
```ts ```ts
import geolocation from '@ohos.geolocation'; import geolocation from '@ohos.geolocation';
let gnssStatusCb = (satelliteStatusInfo) => { let gnssStatusCb = (satelliteStatusInfo:geolocation.SatelliteStatusInfo):void => {
console.log('gnssStatusChange: ' + JSON.stringify(satelliteStatusInfo)); console.log('gnssStatusChange: ' + JSON.stringify(satelliteStatusInfo));
} }
geolocation.on('gnssStatusChange', gnssStatusCb); geolocation.on('gnssStatusChange', gnssStatusCb);
...@@ -303,7 +303,7 @@ Unregisters the listener for GNSS satellite status change events. ...@@ -303,7 +303,7 @@ Unregisters the listener for GNSS satellite status change events.
```ts ```ts
import geolocation from '@ohos.geolocation'; import geolocation from '@ohos.geolocation';
let gnssStatusCb = (satelliteStatusInfo) => { let gnssStatusCb = (satelliteStatusInfo:geolocation.SatelliteStatusInfo) => {
console.log('gnssStatusChange: ' + JSON.stringify(satelliteStatusInfo)); console.log('gnssStatusChange: ' + JSON.stringify(satelliteStatusInfo));
} }
geolocation.on('gnssStatusChange', gnssStatusCb); geolocation.on('gnssStatusChange', gnssStatusCb);
...@@ -330,14 +330,14 @@ Registers a listener for GNSS NMEA message change events. ...@@ -330,14 +330,14 @@ Registers a listener for GNSS NMEA message change events.
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| type | string | Yes| Event type. The value **nmeaMessageChange** indicates a GNSS NMEA message change.| | type | string | Yes| Event type. The value **nmeaMessageChange** indicates a GNSS NMEA message change.|
| callback | Callback&lt;string&gt; | Yes| Callback used to return GNSS NMEA message changes.| | callback | Callback&lt;string&gt; | Yes| Callback used to receive GNSS NMEA message changes.|
**Example** **Example**
```ts ```ts
import geolocation from '@ohos.geolocation'; import geolocation from '@ohos.geolocation';
let nmeaCb = (str) => { let nmeaCb = (str:string):void => {
console.log('nmeaMessageChange: ' + JSON.stringify(str)); console.log('nmeaMessageChange: ' + JSON.stringify(str));
} }
geolocation.on('nmeaMessageChange', nmeaCb ); geolocation.on('nmeaMessageChange', nmeaCb );
...@@ -370,7 +370,7 @@ Unregisters the listener for GNSS NMEA message change events. ...@@ -370,7 +370,7 @@ Unregisters the listener for GNSS NMEA message change events.
```ts ```ts
import geolocation from '@ohos.geolocation'; import geolocation from '@ohos.geolocation';
let nmeaCb = (str) => { let nmeaCb = (str:string):void => {
console.log('nmeaMessageChange: ' + JSON.stringify(str)); console.log('nmeaMessageChange: ' + JSON.stringify(str));
} }
geolocation.on('nmeaMessageChange', nmeaCb); geolocation.on('nmeaMessageChange', nmeaCb);
...@@ -398,7 +398,7 @@ Registers a listener for status change events of the specified geofence. ...@@ -398,7 +398,7 @@ Registers a listener for status change events of the specified geofence.
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| type | string | Yes| Event type. The value **fenceStatusChange** indicates a geofence status change.| | type | string | Yes| Event type. The value **fenceStatusChange** indicates a geofence status change.|
| request | [GeofenceRequest](#geofencerequestdeprecated) | Yes| Geofencing request.| | request | [GeofenceRequest](#geofencerequestdeprecated) | Yes| Geofencing request.|
| want | [WantAgent](js-apis-app-ability-wantAgent.md) | Yes| **WantAgent** used to return geofence (entrance or exit) events.| | want | [WantAgent](js-apis-app-ability-wantAgent.md) | Yes| **WantAgent** used to receive geofence (entrance or exit) events.|
**Example** **Example**
...@@ -406,7 +406,7 @@ Registers a listener for status change events of the specified geofence. ...@@ -406,7 +406,7 @@ Registers a listener for status change events of the specified geofence.
import geolocation from '@ohos.geolocation'; import geolocation from '@ohos.geolocation';
import wantAgent from '@ohos.app.ability.wantAgent'; import wantAgent from '@ohos.app.ability.wantAgent';
let wantAgentInfo = { let wantAgentInfo:wantAgent.WantAgentInfo = {
wants: [ wants: [
{ {
bundleName: "com.example.myapplication", bundleName: "com.example.myapplication",
...@@ -420,7 +420,7 @@ Registers a listener for status change events of the specified geofence. ...@@ -420,7 +420,7 @@ Registers a listener for status change events of the specified geofence.
}; };
wantAgent.getWantAgent(wantAgentInfo).then((wantAgentObj) => { wantAgent.getWantAgent(wantAgentInfo).then((wantAgentObj) => {
let requestInfo = {'priority': 0x201, 'scenario': 0x301, "geofence": {"latitude": 121, "longitude": 26, "radius": 100, "expiration": 10000}}; let requestInfo:geolocation.GeofenceRequest = {'priority': 0x201, 'scenario': 0x301, "geofence": {"latitude": 121, "longitude": 26, "radius": 100, "expiration": 10000}};
geolocation.on('fenceStatusChange', requestInfo, wantAgentObj); geolocation.on('fenceStatusChange', requestInfo, wantAgentObj);
}); });
``` ```
...@@ -446,7 +446,7 @@ Unregisters the listener for status change events of the specified geofence. ...@@ -446,7 +446,7 @@ Unregisters the listener for status change events of the specified geofence.
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| type | string | Yes| Event type. The value **fenceStatusChange** indicates a geofence status change.| | type | string | Yes| Event type. The value **fenceStatusChange** indicates a geofence status change.|
| request | [GeofenceRequest](#geofencerequestdeprecated) | Yes| Geofencing request.| | request | [GeofenceRequest](#geofencerequestdeprecated) | Yes| Geofencing request.|
| want | [WantAgent](js-apis-app-ability-wantAgent.md) | Yes| **WantAgent** used to return geofence (entrance or exit) events.| | want | [WantAgent](js-apis-app-ability-wantAgent.md) | Yes| **WantAgent** used to receive geofence (entrance or exit) events.|
**Example** **Example**
...@@ -454,7 +454,7 @@ Unregisters the listener for status change events of the specified geofence. ...@@ -454,7 +454,7 @@ Unregisters the listener for status change events of the specified geofence.
import geolocation from '@ohos.geolocation'; import geolocation from '@ohos.geolocation';
import wantAgent from '@ohos.app.ability.wantAgent'; import wantAgent from '@ohos.app.ability.wantAgent';
let wantAgentInfo = { let wantAgentInfo:wantAgent.WantAgentInfo = {
wants: [ wants: [
{ {
bundleName: "com.example.myapplication", bundleName: "com.example.myapplication",
...@@ -468,7 +468,7 @@ Unregisters the listener for status change events of the specified geofence. ...@@ -468,7 +468,7 @@ Unregisters the listener for status change events of the specified geofence.
}; };
wantAgent.getWantAgent(wantAgentInfo).then((wantAgentObj) => { wantAgent.getWantAgent(wantAgentInfo).then((wantAgentObj) => {
let requestInfo = {'priority': 0x201, 'scenario': 0x301, "geofence": {"latitude": 121, "longitude": 26, "radius": 100, "expiration": 10000}}; let requestInfo:geolocation.GeofenceRequest = {'priority': 0x201, 'scenario': 0x301, "geofence": {"latitude": 121, "longitude": 26, "radius": 100, "expiration": 10000}};
geolocation.on('fenceStatusChange', requestInfo, wantAgentObj); geolocation.on('fenceStatusChange', requestInfo, wantAgentObj);
geolocation.off('fenceStatusChange', requestInfo, wantAgentObj); geolocation.off('fenceStatusChange', requestInfo, wantAgentObj);
}); });
...@@ -493,14 +493,15 @@ Obtains the current location. This API uses an asynchronous callback to return t ...@@ -493,14 +493,15 @@ Obtains the current location. This API uses an asynchronous callback to return t
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| request | [CurrentLocationRequest](#currentlocationrequestdeprecated) | Yes| Location request.| | request | [CurrentLocationRequest](#currentlocationrequestdeprecated) | Yes| Location request.|
| callback | AsyncCallback&lt;[Location](#locationdeprecated)&gt; | Yes| Callback used to return the current location.| | callback | AsyncCallback&lt;[Location](#locationdeprecated)&gt; | Yes| Callback used to receive the current location.|
**Example** **Example**
```ts ```ts
import geolocation from '@ohos.geolocation'; import geolocation from '@ohos.geolocation';
let requestInfo = {'priority': 0x203, 'scenario': 0x300,'maxAccuracy': 0}; import BusinessError from "@ohos.base"
let locationChange = (err, location) => { let requestInfo:geolocation.CurrentLocationRequest = {'priority': 0x203, 'scenario': 0x300,'maxAccuracy': 0};
let locationChange = (err:BusinessError.BusinessError, location:geolocation.Location) => {
if (err) { if (err) {
console.log('locationChanger: err=' + JSON.stringify(err)); console.log('locationChanger: err=' + JSON.stringify(err));
} }
...@@ -530,13 +531,14 @@ Obtains the current location. This API uses an asynchronous callback to return t ...@@ -530,13 +531,14 @@ Obtains the current location. This API uses an asynchronous callback to return t
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| callback | AsyncCallback&lt;[Location](#locationdeprecated)&gt; | Yes| Callback used to return the current location.| | callback | AsyncCallback&lt;[Location](#locationdeprecated)&gt; | Yes| Callback used to receive the current location.|
**Example** **Example**
```ts ```ts
import geolocation from '@ohos.geolocation'; import geolocation from '@ohos.geolocation';
let locationChange = (err, location) => { import BusinessError from "@ohos.base"
let locationChange = (err:BusinessError.BusinessError, location:geolocation.Location):void => {
if (err) { if (err) {
console.log('locationChanger: err=' + JSON.stringify(err)); console.log('locationChanger: err=' + JSON.stringify(err));
} }
...@@ -578,7 +580,7 @@ Obtains the current location. This API uses a promise to return the result. ...@@ -578,7 +580,7 @@ Obtains the current location. This API uses a promise to return the result.
```ts ```ts
import geolocation from '@ohos.geolocation'; import geolocation from '@ohos.geolocation';
let requestInfo = {'priority': 0x203, 'scenario': 0x300,'maxAccuracy': 0}; let requestInfo:geolocation.CurrentLocationRequest = {'priority': 0x203, 'scenario': 0x300,'maxAccuracy': 0};
geolocation.getCurrentLocation(requestInfo).then((result) => { geolocation.getCurrentLocation(requestInfo).then((result) => {
console.log('current location: ' + JSON.stringify(result)); console.log('current location: ' + JSON.stringify(result));
}); });
...@@ -602,7 +604,7 @@ Obtains the previous location. This API uses an asynchronous callback to return ...@@ -602,7 +604,7 @@ Obtains the previous location. This API uses an asynchronous callback to return
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| callback | AsyncCallback&lt;[Location](#locationdeprecated)&gt; | Yes| Callback used to return the previous location.| | callback | AsyncCallback&lt;[Location](#locationdeprecated)&gt; | Yes| Callback used to receive the previous location.|
**Example** **Example**
...@@ -667,7 +669,7 @@ Checks whether the location service is enabled. This API uses an asynchronous ca ...@@ -667,7 +669,7 @@ Checks whether the location service is enabled. This API uses an asynchronous ca
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| callback | AsyncCallback&lt;boolean&gt; | Yes| Callback used to return the location service status.| | callback | AsyncCallback&lt;boolean&gt; | Yes| Callback used to receive the location service status.|
**Example** **Example**
...@@ -730,7 +732,7 @@ Requests to enable the location service. This API uses an asynchronous callback ...@@ -730,7 +732,7 @@ Requests to enable the location service. This API uses an asynchronous callback
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| callback | AsyncCallback&lt;boolean&gt; | Yes| Callback used to return the location service status.| | callback | AsyncCallback&lt;boolean&gt; | Yes| Callback used to receive the location service status.|
**Example** **Example**
...@@ -793,7 +795,7 @@ Checks whether the (reverse) geocoding service is available. This API uses an as ...@@ -793,7 +795,7 @@ Checks whether the (reverse) geocoding service is available. This API uses an as
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| callback | AsyncCallback&lt;boolean&gt; | Yes| Callback used to return the (reverse) geocoding service status.| | callback | AsyncCallback&lt;boolean&gt; | Yes| Callback used to receive the (reverse) geocoding service status.|
**Example** **Example**
...@@ -857,13 +859,13 @@ Converts coordinates into geographic descriptions through reverse geocoding. Thi ...@@ -857,13 +859,13 @@ Converts coordinates into geographic descriptions through reverse geocoding. Thi
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| request | [ReverseGeoCodeRequest](#reversegeocoderequestdeprecated) | Yes| Reverse geocoding request.| | request | [ReverseGeoCodeRequest](#reversegeocoderequestdeprecated) | Yes| Reverse geocoding request.|
| callback | AsyncCallback&lt;Array&lt;[GeoAddress](#geoaddressdeprecated)&gt;&gt; | Yes| Callback used to return the reverse geocoding result.| | callback | AsyncCallback&lt;Array&lt;[GeoAddress](#geoaddressdeprecated)&gt;&gt; | Yes| Callback used to receive the reverse geocoding result.|
**Example** **Example**
```ts ```ts
import geolocation from '@ohos.geolocation'; import geolocation from '@ohos.geolocation';
let reverseGeocodeRequest = {"latitude": 31.12, "longitude": 121.11, "maxItems": 1}; let reverseGeocodeRequest:geolocation.ReverseGeoCodeRequest = {"latitude": 31.12, "longitude": 121.11, "maxItems": 1};
geolocation.getAddressesFromLocation(reverseGeocodeRequest, (err, data) => { geolocation.getAddressesFromLocation(reverseGeocodeRequest, (err, data) => {
if (err) { if (err) {
console.log('getAddressesFromLocation: err=' + JSON.stringify(err)); console.log('getAddressesFromLocation: err=' + JSON.stringify(err));
...@@ -904,7 +906,7 @@ Converts coordinates into geographic descriptions through reverse geocoding. Thi ...@@ -904,7 +906,7 @@ Converts coordinates into geographic descriptions through reverse geocoding. Thi
```ts ```ts
import geolocation from '@ohos.geolocation'; import geolocation from '@ohos.geolocation';
let reverseGeocodeRequest = {"latitude": 31.12, "longitude": 121.11, "maxItems": 1}; let reverseGeocodeRequest:geolocation.ReverseGeoCodeRequest = {"latitude": 31.12, "longitude": 121.11, "maxItems": 1};
geolocation.getAddressesFromLocation(reverseGeocodeRequest).then((data) => { geolocation.getAddressesFromLocation(reverseGeocodeRequest).then((data) => {
console.log('getAddressesFromLocation: ' + JSON.stringify(data)); console.log('getAddressesFromLocation: ' + JSON.stringify(data));
}); });
...@@ -929,13 +931,13 @@ Converts geographic descriptions into coordinates through geocoding. This API us ...@@ -929,13 +931,13 @@ Converts geographic descriptions into coordinates through geocoding. This API us
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| request | [GeoCodeRequest](#geocoderequestdeprecated) | Yes| Geocoding request.| | request | [GeoCodeRequest](#geocoderequestdeprecated) | Yes| Geocoding request.|
| callback | AsyncCallback&lt;Array&lt;[GeoAddress](#geoaddressdeprecated)&gt;&gt; | Yes| Callback used to return the geocoding result.| | callback | AsyncCallback&lt;Array&lt;[GeoAddress](#geoaddressdeprecated)&gt;&gt; | Yes| Callback used to receive the geocoding result.|
**Example** **Example**
```ts ```ts
import geolocation from '@ohos.geolocation'; import geolocation from '@ohos.geolocation';
let geocodeRequest = {"description": "No. xx, xx Road, Pudong District, Shanghai", "maxItems": 1}; let geocodeRequest:geolocation.GeoCodeRequest = {"description": "No. xx, xx Road, Pudong District, Shanghai", "maxItems": 1};
geolocation.getAddressesFromLocationName(geocodeRequest, (err, data) => { geolocation.getAddressesFromLocationName(geocodeRequest, (err, data) => {
if (err) { if (err) {
console.log('getAddressesFromLocationName: err=' + JSON.stringify(err)); console.log('getAddressesFromLocationName: err=' + JSON.stringify(err));
...@@ -970,13 +972,13 @@ Converts geographic descriptions into coordinates through geocoding. This API us ...@@ -970,13 +972,13 @@ Converts geographic descriptions into coordinates through geocoding. This API us
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| Promise&lt;Array&lt;[GeoAddress](#geoaddressdeprecated)&gt;&gt; | Array&lt;[GeoAddress](#geoaddressdeprecated)&gt;|NA|Promise used to return the geocoding result.| | Promise&lt;Array&lt;[GeoAddress](#geoaddressdeprecated)&gt;&gt; | Array&lt;[GeoAddress](#geoaddressdeprecated)&gt;|NA|Promise used to receive the geocoding result.|
**Example** **Example**
```ts ```ts
import geolocation from '@ohos.geolocation'; import geolocation from '@ohos.geolocation';
let geocodeRequest = {"description": "No. xx, xx Road, Pudong District, Shanghai", "maxItems": 1}; let geocodeRequest:geolocation.GeoCodeRequest = {"description": "No. xx, xx Road, Pudong District, Shanghai", "maxItems": 1};
geolocation.getAddressesFromLocationName(geocodeRequest).then((result) => { geolocation.getAddressesFromLocationName(geocodeRequest).then((result) => {
console.log('getAddressesFromLocationName: ' + JSON.stringify(result)); console.log('getAddressesFromLocationName: ' + JSON.stringify(result));
}); });
...@@ -1001,7 +1003,7 @@ Obtains the number of cached GNSS locations. ...@@ -1001,7 +1003,7 @@ Obtains the number of cached GNSS locations.
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| callback | AsyncCallback&lt;number&gt; | Yes| Callback used to return the number of cached GNSS locations. | | callback | AsyncCallback&lt;number&gt; | Yes| Callback used to receive the number of cached GNSS locations. |
**Example** **Example**
...@@ -1066,7 +1068,7 @@ Obtains all cached GNSS locations and clears the GNSS cache queue. ...@@ -1066,7 +1068,7 @@ Obtains all cached GNSS locations and clears the GNSS cache queue.
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| callback | AsyncCallback&lt;boolean&gt; | Yes| Callback used to return the operation result.| | callback | AsyncCallback&lt;boolean&gt; | Yes| Callback used to receive the operation result.|
**Example** **Example**
...@@ -1101,7 +1103,7 @@ Obtains all cached GNSS locations and clears the GNSS cache queue. ...@@ -1101,7 +1103,7 @@ Obtains all cached GNSS locations and clears the GNSS cache queue.
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| Promise&lt;boolean&gt; |boolean|NA| Promise used to return the operation result.| | Promise&lt;boolean&gt; |boolean|NA| Promise used to indicate whether the cached GNSS locations are cleared successfully.|
**Example** **Example**
...@@ -1132,13 +1134,13 @@ Sends an extended command to the location subsystem. ...@@ -1132,13 +1134,13 @@ Sends an extended command to the location subsystem.
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| command | [LocationCommand](#locationcommanddeprecated) | Yes| Extended command (string) to be sent.| | command | [LocationCommand](#locationcommanddeprecated) | Yes| Extended command (string) to be sent.|
| callback | AsyncCallback&lt;boolean&gt; | Yes| Callback used to return the operation result.| | callback | AsyncCallback&lt;boolean&gt; | Yes| Callback used to receive the operation result.|
**Example** **Example**
```ts ```ts
import geolocation from '@ohos.geolocation'; import geolocation from '@ohos.geolocation';
let requestInfo = {'scenario': 0x301, 'command': "command_1"}; let requestInfo:geolocation.LocationCommand = {'scenario': 0x301, 'command': "command_1"};
geolocation.sendCommand(requestInfo, (err, result) => { geolocation.sendCommand(requestInfo, (err, result) => {
if (err) { if (err) {
console.log('sendCommand: err=' + JSON.stringify(err)); console.log('sendCommand: err=' + JSON.stringify(err));
...@@ -1180,7 +1182,7 @@ Sends an extended command to the location subsystem. ...@@ -1180,7 +1182,7 @@ Sends an extended command to the location subsystem.
```ts ```ts
import geolocation from '@ohos.geolocation'; import geolocation from '@ohos.geolocation';
let requestInfo = {'scenario': 0x301, 'command': "command_1"}; let requestInfo:geolocation.LocationCommand = {'scenario': 0x301, 'command': "command_1"};
geolocation.sendCommand(requestInfo).then((result) => { geolocation.sendCommand(requestInfo).then((result) => {
console.log('promise, sendCommand: ' + JSON.stringify(result)); console.log('promise, sendCommand: ' + JSON.stringify(result));
}); });
......
...@@ -122,7 +122,7 @@ Defines parameters for an **AppEventInfo** object. ...@@ -122,7 +122,7 @@ Defines parameters for an **AppEventInfo** object.
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| --------- | ----------------------- | ---- | ------------------------------------------------------------ | | --------- | ----------------------- | ---- | ------------------------------------------------------------ |
| domain | string | Yes | Event domain. The value is a string of up to 32 characters, including digits (0 to 9), letters (a to z), and underscores (\_). It must start with a lowercase letter and cannot end with an underscore (_).| | domain | string | Yes | Event domain. The value is a string of up to 16 characters, including digits (0 to 9), letters (a to z), and underscores (\_). It must start with a lowercase letter and cannot end with an underscore (_).|
| name | string | Yes | Event name. The value is a string of up to 48 characters, including digits (0 to 9), letters (a to z), and underscores (\_). It must start with a lowercase letter or dollar sign ($) and cannot end with an underscore (_).| | name | string | Yes | Event name. The value is a string of up to 48 characters, including digits (0 to 9), letters (a to z), and underscores (\_). It must start with a lowercase letter or dollar sign ($) and cannot end with an underscore (_).|
| eventType | [EventType](#eventtype) | Yes | Event type. | | eventType | [EventType](#eventtype) | Yes | Event type. |
| params | object | Yes | Event parameter object, which consists of a parameter name and a parameter value. The specifications are as follows:<br>- The parameter name is a string of up to 16 characters, including digits (0 to 9), letters (a to z), and underscores (\_). It must start with a lowercase letter or dollar sign ($) and cannot end with an underscore (_).<br>- The parameter value can be a string, number, boolean, or array. If the parameter value is a string, its maximum length is 8*1024 characters. If this limit is exceeded, excess characters will be discarded. If the parameter value is a number, the value must be within the range of **Number.MIN_SAFE_INTEGER** to **Number.MAX_SAFE_INTEGER**. Otherwise, uncertain values may be generated. If the parameter value is an array, the elements in the array must be of the same type, which can only be string, number, or boolean. In addition, the number of elements must be less than 100. If this limit is exceeded, excess elements will be discarded.<br>- The maximum number of parameters is 32. If this limit is exceeded, excess parameters will be discarded.| | params | object | Yes | Event parameter object, which consists of a parameter name and a parameter value. The specifications are as follows:<br>- The parameter name is a string of up to 16 characters, including digits (0 to 9), letters (a to z), and underscores (\_). It must start with a lowercase letter or dollar sign ($) and cannot end with an underscore (_).<br>- The parameter value can be a string, number, boolean, or array. If the parameter value is a string, its maximum length is 8*1024 characters. If this limit is exceeded, excess characters will be discarded. If the parameter value is a number, the value must be within the range of **Number.MIN_SAFE_INTEGER** to **Number.MAX_SAFE_INTEGER**. Otherwise, uncertain values may be generated. If the parameter value is an array, the elements in the array must be of the same type, which can only be string, number, or boolean. In addition, the number of elements must be less than 100. If this limit is exceeded, excess elements will be discarded.<br>- The maximum number of parameters is 32. If this limit is exceeded, excess parameters will be discarded.|
......
...@@ -98,7 +98,7 @@ For details about the error codes, see [I18N Error Codes](../errorcodes/errorcod ...@@ -98,7 +98,7 @@ For details about the error codes, see [I18N Error Codes](../errorcodes/errorcod
let displayLanguage: string = I18n.System.getDisplayLanguage("zh", "en-GB"); // displayLanguage = Chinese let displayLanguage: string = I18n.System.getDisplayLanguage("zh", "en-GB"); // displayLanguage = Chinese
} catch(error) { } catch(error) {
let err: BusinessError = error as BusinessError; let err: BusinessError = error as BusinessError;
console.error(`call System.getDisplayCountry failed, error code: ${err.code}, message: ${err.message}.`); console.error(`call System.getDisplayLanguage failed, error code: ${err.code}, message: ${err.message}.`);
} }
``` ```
...@@ -132,7 +132,7 @@ For details about the error codes, see [I18N Error Codes](../errorcodes/errorcod ...@@ -132,7 +132,7 @@ For details about the error codes, see [I18N Error Codes](../errorcodes/errorcod
let systemLanguages: Array<string> = I18n.System.getSystemLanguages(); // [ "en-Latn-US", "zh-Hans" ] let systemLanguages: Array<string> = I18n.System.getSystemLanguages(); // [ "en-Latn-US", "zh-Hans" ]
} catch(error) { } catch(error) {
let err: BusinessError = error as BusinessError; let err: BusinessError = error as BusinessError;
console.error(`call System.getDisplayCountry failed, error code: ${err.code}, message: ${err.message}.`); console.error(`call System.getSystemLanguages failed, error code: ${err.code}, message: ${err.message}.`);
} }
``` ```
...@@ -172,7 +172,7 @@ For details about the error codes, see [I18N Error Codes](../errorcodes/errorcod ...@@ -172,7 +172,7 @@ For details about the error codes, see [I18N Error Codes](../errorcodes/errorcod
let systemCountries: Array<string> = I18n.System.getSystemCountries('zh'); // systemCountries = [ "ZW", "YT", "YE", ..., "ER", "CN", "DE" ], 240 countries or regions in total let systemCountries: Array<string> = I18n.System.getSystemCountries('zh'); // systemCountries = [ "ZW", "YT", "YE", ..., "ER", "CN", "DE" ], 240 countries or regions in total
} catch(error) { } catch(error) {
let err: BusinessError = error as BusinessError; let err: BusinessError = error as BusinessError;
console.error(`call System.getDisplayCountry failed, error code: ${err.code}, message: ${err.message}.`); console.error(`call System.getSystemCountries failed, error code: ${err.code}, message: ${err.message}.`);
} }
``` ```
...@@ -213,7 +213,7 @@ For details about the error codes, see [I18N Error Codes](../errorcodes/errorcod ...@@ -213,7 +213,7 @@ For details about the error codes, see [I18N Error Codes](../errorcodes/errorcod
let res: boolean = I18n.System.isSuggested('zh', 'CN'); // res = true let res: boolean = I18n.System.isSuggested('zh', 'CN'); // res = true
} catch(error) { } catch(error) {
let err: BusinessError = error as BusinessError; let err: BusinessError = error as BusinessError;
console.error(`call System.getDisplayCountry failed, error code: ${err.code}, message: ${err.message}.`); console.error(`call System.isSuggested failed, error code: ${err.code}, message: ${err.message}.`);
} }
``` ```
...@@ -247,7 +247,7 @@ For details about the error codes, see [I18N Error Codes](../errorcodes/errorcod ...@@ -247,7 +247,7 @@ For details about the error codes, see [I18N Error Codes](../errorcodes/errorcod
let systemLanguage: string = I18n.System.getSystemLanguage(); // systemLanguage indicates the current system language. let systemLanguage: string = I18n.System.getSystemLanguage(); // systemLanguage indicates the current system language.
} catch(error) { } catch(error) {
let err: BusinessError = error as BusinessError; let err: BusinessError = error as BusinessError;
console.error(`call System.getDisplayCountry failed, error code: ${err.code}, message: ${err.message}.`); console.error(`call System.getSystemLanguage failed, error code: ${err.code}, message: ${err.message}.`);
} }
``` ```
...@@ -285,7 +285,7 @@ For details about the error codes, see [I18N Error Codes](../errorcodes/errorcod ...@@ -285,7 +285,7 @@ For details about the error codes, see [I18N Error Codes](../errorcodes/errorcod
I18n.System.setSystemLanguage('zh'); // Set the current system language to zh. I18n.System.setSystemLanguage('zh'); // Set the current system language to zh.
} catch(error) { } catch(error) {
let err: BusinessError = error as BusinessError; let err: BusinessError = error as BusinessError;
console.error(`call System.getDisplayCountry failed, error code: ${err.code}, message: ${err.message}.`); console.error(`call System.setSystemLanguage failed, error code: ${err.code}, message: ${err.message}.`);
} }
``` ```
...@@ -319,7 +319,7 @@ For details about the error codes, see [I18N Error Codes](../errorcodes/errorcod ...@@ -319,7 +319,7 @@ For details about the error codes, see [I18N Error Codes](../errorcodes/errorcod
let systemRegion: string = I18n.System.getSystemRegion(); // Obtain the current system region. let systemRegion: string = I18n.System.getSystemRegion(); // Obtain the current system region.
} catch(error) { } catch(error) {
let err: BusinessError = error as BusinessError; let err: BusinessError = error as BusinessError;
console.error(`call System.getDisplayCountry failed, error code: ${err.code}, message: ${err.message}.`); console.error(`call System.getSystemRegion failed, error code: ${err.code}, message: ${err.message}.`);
} }
``` ```
...@@ -357,7 +357,7 @@ For details about the error codes, see [I18N Error Codes](../errorcodes/errorcod ...@@ -357,7 +357,7 @@ For details about the error codes, see [I18N Error Codes](../errorcodes/errorcod
I18n.System.setSystemRegion('CN'); // Set the current system region to CN. I18n.System.setSystemRegion('CN'); // Set the current system region to CN.
} catch(error) { } catch(error) {
let err: BusinessError = error as BusinessError; let err: BusinessError = error as BusinessError;
console.error(`call System.getDisplayCountry failed, error code: ${err.code}, message: ${err.message}.`); console.error(`call System.setSystemRegion failed, error code: ${err.code}, message: ${err.message}.`);
} }
``` ```
...@@ -391,7 +391,7 @@ For details about the error codes, see [I18N Error Codes](../errorcodes/errorcod ...@@ -391,7 +391,7 @@ For details about the error codes, see [I18N Error Codes](../errorcodes/errorcod
let systemLocale: string = I18n.System.getSystemLocale(); // Obtain the current system locale. let systemLocale: string = I18n.System.getSystemLocale(); // Obtain the current system locale.
} catch(error) { } catch(error) {
let err: BusinessError = error as BusinessError; let err: BusinessError = error as BusinessError;
console.error(`call System.getDisplayCountry failed, error code: ${err.code}, message: ${err.message}.`); console.error(`call System.getSystemLocale failed, error code: ${err.code}, message: ${err.message}.`);
} }
``` ```
...@@ -429,7 +429,7 @@ For details about the error codes, see [I18N Error Codes](../errorcodes/errorcod ...@@ -429,7 +429,7 @@ For details about the error codes, see [I18N Error Codes](../errorcodes/errorcod
I18n.System.setSystemLocale('zh-CN'); // Set the current system locale to zh-CN. I18n.System.setSystemLocale('zh-CN'); // Set the current system locale to zh-CN.
} catch(error) { } catch(error) {
let err: BusinessError = error as BusinessError; let err: BusinessError = error as BusinessError;
console.error(`call System.getDisplayCountry failed, error code: ${err.code}, message: ${err.message}.`); console.error(`call System.setSystemLocale failed, error code: ${err.code}, message: ${err.message}.`);
} }
``` ```
...@@ -463,7 +463,7 @@ For details about the error codes, see [I18N Error Codes](../errorcodes/errorcod ...@@ -463,7 +463,7 @@ For details about the error codes, see [I18N Error Codes](../errorcodes/errorcod
let is24HourClock: boolean = I18n.System.is24HourClock(); // Check whether the 24-hour clock is enabled. let is24HourClock: boolean = I18n.System.is24HourClock(); // Check whether the 24-hour clock is enabled.
} catch(error) { } catch(error) {
let err: BusinessError = error as BusinessError; let err: BusinessError = error as BusinessError;
console.error(`call System.getDisplayCountry failed, error code: ${err.code}, message: ${err.message}.`); console.error(`call System.is24HourClock failed, error code: ${err.code}, message: ${err.message}.`);
} }
``` ```
...@@ -502,7 +502,7 @@ For details about the error codes, see [I18N Error Codes](../errorcodes/errorcod ...@@ -502,7 +502,7 @@ For details about the error codes, see [I18N Error Codes](../errorcodes/errorcod
I18n.System.set24HourClock(true); I18n.System.set24HourClock(true);
} catch(error) { } catch(error) {
let err: BusinessError = error as BusinessError; let err: BusinessError = error as BusinessError;
console.error(`call System.getDisplayCountry failed, error code: ${err.code}, message: ${err.message}.`); console.error(`call System.set24HourClock failed, error code: ${err.code}, message: ${err.message}.`);
} }
``` ```
...@@ -544,7 +544,7 @@ For details about the error codes, see [I18N Error Codes](../errorcodes/errorcod ...@@ -544,7 +544,7 @@ For details about the error codes, see [I18N Error Codes](../errorcodes/errorcod
I18n.System.addPreferredLanguage(language, index); // Add zh-CN to the first place in the preferred language list. I18n.System.addPreferredLanguage(language, index); // Add zh-CN to the first place in the preferred language list.
} catch(error) { } catch(error) {
let err: BusinessError = error as BusinessError; let err: BusinessError = error as BusinessError;
console.error(`call System.getDisplayCountry failed, error code: ${err.code}, message: ${err.message}.`); console.error(`call System.addPreferredLanguage failed, error code: ${err.code}, message: ${err.message}.`);
} }
``` ```
...@@ -584,7 +584,7 @@ For details about the error codes, see [I18N Error Codes](../errorcodes/errorcod ...@@ -584,7 +584,7 @@ For details about the error codes, see [I18N Error Codes](../errorcodes/errorcod
I18n.System.removePreferredLanguage(index); I18n.System.removePreferredLanguage(index);
} catch(error) { } catch(error) {
let err: BusinessError = error as BusinessError; let err: BusinessError = error as BusinessError;
console.error(`call System.getDisplayCountry failed, error code: ${err.code}, message: ${err.message}.`); console.error(`call System.removePreferredLanguage failed, error code: ${err.code}, message: ${err.message}.`);
} }
``` ```
...@@ -618,7 +618,7 @@ For details about the error codes, see [I18N Error Codes](../errorcodes/errorcod ...@@ -618,7 +618,7 @@ For details about the error codes, see [I18N Error Codes](../errorcodes/errorcod
let preferredLanguageList: Array<string> = I18n.System.getPreferredLanguageList(); // Obtain the current preferred language list. let preferredLanguageList: Array<string> = I18n.System.getPreferredLanguageList(); // Obtain the current preferred language list.
} catch(error) { } catch(error) {
let err: BusinessError = error as BusinessError; let err: BusinessError = error as BusinessError;
console.error(`call System.getDisplayCountry failed, error code: ${err.code}, message: ${err.message}.`); console.error(`call System.getPreferredLanguageList failed, error code: ${err.code}, message: ${err.message}.`);
} }
``` ```
...@@ -652,7 +652,7 @@ For details about the error codes, see [I18N Error Codes](../errorcodes/errorcod ...@@ -652,7 +652,7 @@ For details about the error codes, see [I18N Error Codes](../errorcodes/errorcod
let firstPreferredLanguage: string = I18n.System.getFirstPreferredLanguage(); // Obtain the first language in the preferred language list. let firstPreferredLanguage: string = I18n.System.getFirstPreferredLanguage(); // Obtain the first language in the preferred language list.
} catch(error) { } catch(error) {
let err: BusinessError = error as BusinessError; let err: BusinessError = error as BusinessError;
console.error(`call System.getDisplayCountry failed, error code: ${err.code}, message: ${err.message}.`); console.error(`call System.getFirstPreferredLanguage failed, error code: ${err.code}, message: ${err.message}.`);
} }
``` ```
...@@ -686,7 +686,7 @@ For details about the error codes, see [I18N Error Codes](../errorcodes/errorcod ...@@ -686,7 +686,7 @@ For details about the error codes, see [I18N Error Codes](../errorcodes/errorcod
let appPreferredLanguage: string = I18n.System.getAppPreferredLanguage(); // Obtain the preferred language of an application. let appPreferredLanguage: string = I18n.System.getAppPreferredLanguage(); // Obtain the preferred language of an application.
} catch(error) { } catch(error) {
let err: BusinessError = error as BusinessError; let err: BusinessError = error as BusinessError;
console.error(`call System.getDisplayCountry failed, error code: ${err.code}, message: ${err.message}.`); console.error(`call System.getAppPreferredLanguage failed, error code: ${err.code}, message: ${err.message}.`);
} }
``` ```
...@@ -724,7 +724,7 @@ For details about the error codes, see [I18N Error Codes](../errorcodes/errorcod ...@@ -724,7 +724,7 @@ For details about the error codes, see [I18N Error Codes](../errorcodes/errorcod
I18n.System.setUsingLocalDigit(true); // Enable the local digit switch. I18n.System.setUsingLocalDigit(true); // Enable the local digit switch.
} catch(error) { } catch(error) {
let err: BusinessError = error as BusinessError; let err: BusinessError = error as BusinessError;
console.error(`call System.getDisplayCountry failed, error code: ${err.code}, message: ${err.message}.`); console.error(`call System.setUsingLocalDigit failed, error code: ${err.code}, message: ${err.message}.`);
} }
``` ```
...@@ -758,7 +758,7 @@ For details about the error codes, see [I18N Error Codes](../errorcodes/errorcod ...@@ -758,7 +758,7 @@ For details about the error codes, see [I18N Error Codes](../errorcodes/errorcod
let status: boolean = I18n.System.getUsingLocalDigit(); // Check whether the local digit switch is enabled. let status: boolean = I18n.System.getUsingLocalDigit(); // Check whether the local digit switch is enabled.
} catch(error) { } catch(error) {
let err: BusinessError = error as BusinessError; let err: BusinessError = error as BusinessError;
console.error(`call System.getDisplayCountry failed, error code: ${err.code}, message: ${err.message}.`); console.error(`call System.getUsingLocalDigit failed, error code: ${err.code}, message: ${err.message}.`);
} }
``` ```
...@@ -1913,7 +1913,7 @@ Converts the input string from the source format to the target format. ...@@ -1913,7 +1913,7 @@ Converts the input string from the source format to the target format.
static isDigit(char: string): boolean static isDigit(char: string): boolean
Checks whether the input character string is composed of digits. Checks whether the input string is composed of digits.
**System capability**: SystemCapability.Global.I18n **System capability**: SystemCapability.Global.I18n
...@@ -2121,7 +2121,7 @@ Checks whether the input character is an uppercase letter. ...@@ -2121,7 +2121,7 @@ Checks whether the input character is an uppercase letter.
static getType(char: string): string static getType(char: string): string
Obtains the category value of the input character string. Obtains the category value of the input string.
**System capability**: SystemCapability.Global.I18n **System capability**: SystemCapability.Global.I18n
...@@ -2203,7 +2203,7 @@ Converts one measurement unit into another and formats the unit based on the spe ...@@ -2203,7 +2203,7 @@ Converts one measurement unit into another and formats the unit based on the spe
| Type | Description | | Type | Description |
| ------ | ----------------------- | | ------ | ----------------------- |
| string | Character string obtained after formatting based on the measurement unit specified by **toUnit**.| | string | string obtained after formatting based on the measurement unit specified by **toUnit**.|
**Example** **Example**
```ts ```ts
...@@ -2371,7 +2371,7 @@ For details about the error codes, see [I18N Error Codes](../errorcodes/errorcod ...@@ -2371,7 +2371,7 @@ For details about the error codes, see [I18N Error Codes](../errorcodes/errorcod
let sortedLanguages: Array<I18n.LocaleItem> = systemLocaleManager.getLanguageInfoArray(languages, sortOptions); let sortedLanguages: Array<I18n.LocaleItem> = systemLocaleManager.getLanguageInfoArray(languages, sortOptions);
} catch(error) { } catch(error) {
let err: BusinessError = error as BusinessError; let err: BusinessError = error as BusinessError;
console.error(`call System.getDisplayCountry failed, error code: ${err.code}, message: ${err.message}.`); console.error(`call systemLocaleManager.getLanguageInfoArray failed, error code: ${err.code}, message: ${err.message}.`);
} }
``` ```
...@@ -2420,7 +2420,7 @@ For details about the error codes, see [I18N Error Codes](../errorcodes/errorcod ...@@ -2420,7 +2420,7 @@ For details about the error codes, see [I18N Error Codes](../errorcodes/errorcod
let sortedRegions: Array<I18n.LocaleItem> = systemLocaleManager.getRegionInfoArray(regions, sortOptions); let sortedRegions: Array<I18n.LocaleItem> = systemLocaleManager.getRegionInfoArray(regions, sortOptions);
} catch(error) { } catch(error) {
let err: BusinessError = error as BusinessError; let err: BusinessError = error as BusinessError;
console.error(`call System.getDisplayCountry failed, error code: ${err.code}, message: ${err.message}.`); console.error(`call systemLocaleManager.getRegionInfoArray failed, error code: ${err.code}, message: ${err.message}.`);
} }
``` ```
...@@ -2452,7 +2452,7 @@ Obtains the array of time zone city items after sorting. ...@@ -2452,7 +2452,7 @@ Obtains the array of time zone city items after sorting.
} }
} catch(error) { } catch(error) {
let err: BusinessError = error as BusinessError; let err: BusinessError = error as BusinessError;
console.error(`call System.getDisplayCountry failed, error code: ${err.code}, message: ${err.message}.`); console.error(`call SystemLocaleManager.getTimeZoneCityItemArray failed, error code: ${err.code}, message: ${err.message}.`);
} }
``` ```
...@@ -2837,7 +2837,7 @@ This API is supported since API version 8 and is deprecated since API version 9. ...@@ -2837,7 +2837,7 @@ This API is supported since API version 8 and is deprecated since API version 9.
| Type | Description | | Type | Description |
| ------ | ----------------------- | | ------ | ----------------------- |
| string | Character string obtained after formatting based on the measurement unit specified by **toUnit**.| | string | string obtained after formatting based on the measurement unit specified by **toUnit**.|
## Character<sup>(deprecated)</sup> ## Character<sup>(deprecated)</sup>
...@@ -2847,7 +2847,7 @@ This API is supported since API version 8 and is deprecated since API version 9. ...@@ -2847,7 +2847,7 @@ This API is supported since API version 8 and is deprecated since API version 9.
static isDigit(char: string): boolean static isDigit(char: string): boolean
Checks whether the input character string is composed of digits. Checks whether the input string is composed of digits.
This API is supported since API version 8 and is deprecated since API version 9. You are advised to use [isDigit](#isdigit9). This API is supported since API version 8 and is deprecated since API version 9. You are advised to use [isDigit](#isdigit9).
...@@ -3031,7 +3031,7 @@ This API is supported since API version 8 and is deprecated since API version 9. ...@@ -3031,7 +3031,7 @@ This API is supported since API version 8 and is deprecated since API version 9.
static getType(char: string): string static getType(char: string): string
Obtains the type of the input character string. Obtains the type of the input string.
This API is supported since API version 8 and is deprecated since API version 9. You are advised to use [getType](#gettype9). This API is supported since API version 8 and is deprecated since API version 9. You are advised to use [getType](#gettype9).
......
...@@ -3,21 +3,20 @@ ...@@ -3,21 +3,20 @@
The **inputConsumer** module implements listening for combination key events. The **inputConsumer** module implements listening for combination key events.
> **NOTE** > **NOTE**
>
> - The initial APIs of this module are supported since API version 8. Newly added APIs will be marked with a superscript to indicate their earliest API version. > - The initial APIs of this module are supported since API version 8. Newly added APIs will be marked with a superscript to indicate their earliest API version.
>
> - The APIs provided by this module are system APIs. > - The APIs provided by this module are system APIs.
## Modules to Import ## Modules to Import
```js ```js
import inputConsumer from '@ohos.multimodalInput.inputConsumer'; import inputConsumer from '@ohos.multimodalInput.inputConsumer';
``` ```
## inputConsumer.on ## inputConsumer.on
on(type: "key", keyOptions: KeyOptions, callback: Callback&lt;KeyOptions&gt;): void on(type: 'key', keyOptions: KeyOptions, callback: Callback&lt;KeyOptions&gt;): void
Enables listening for combination key events. This API uses an asynchronous callback to return the combination key data when a combination key event that meets the specified condition occurs. Enables listening for combination key events. This API uses an asynchronous callback to return the combination key data when a combination key event that meets the specified condition occurs.
...@@ -55,7 +54,7 @@ try { ...@@ -55,7 +54,7 @@ try {
## inputConsumer.off ## inputConsumer.off
off(type: "key", keyOptions: KeyOptions, callback?: Callback&lt;KeyOptions&gt;): void off(type: 'key', keyOptions: KeyOptions, callback?: Callback&lt;KeyOptions&gt;): void
Disables listening for combination key events. Disables listening for combination key events.
...@@ -67,15 +66,15 @@ Disables listening for combination key events. ...@@ -67,15 +66,15 @@ Disables listening for combination key events.
| ---------- | -------------------------- | ---- | ------------------------------- | | ---------- | -------------------------- | ---- | ------------------------------- |
| type | string | Yes | Event type. Currently, only **key** is supported. | | type | string | Yes | Event type. Currently, only **key** is supported. |
| keyOptions | [KeyOptions](#keyoptions) | Yes | Combination key options. | | keyOptions | [KeyOptions](#keyoptions) | Yes | Combination key options. |
| callback | Callback&lt;KeyOptions&gt; | No | Callback for which listening is disabled. If this parameter is not specified, listening will be disabled for all callbacks registered by the current application.| | callback | Callback&lt;KeyOptions&gt; | No | Callback to unregister. If this parameter is not specified, listening will be disabled for all callbacks registered by the current application.|
**Example** **Example**
```js ```js
let leftAltKey = 2045; let leftAltKey = 2045;
let tabKey = 2049; let tabKey = 2049;
// Disable listening for a single callback function. // Disable listening for a single callback.
let callback = (keyOptions: inputConsumer.KeyOptions) => { let callback = function (keyOptions) {
console.log(`keyOptions: ${JSON.stringify(keyOptions)}`); console.log(`keyOptions: ${JSON.stringify(keyOptions)}`);
} }
let keyOption: inputConsumer.KeyOptions = {preKeys: [leftAltKey], finalKey: tabKey, isFinalKeyDown: true, finalKeyDownDuration: 0}; let keyOption: inputConsumer.KeyOptions = {preKeys: [leftAltKey], finalKey: tabKey, isFinalKeyDown: true, finalKeyDownDuration: 0};
...@@ -90,8 +89,8 @@ try { ...@@ -90,8 +89,8 @@ try {
```js ```js
let leftAltKey = 2045; let leftAltKey = 2045;
let tabKey = 2049; let tabKey = 2049;
// Disable listening for all callback functions. // Disable listening for all callbacks.
let callback = (keyOptions: inputConsumer.KeyOptions) => { let callback = function (keyOptions) {
console.log(`keyOptions: ${JSON.stringify(keyOptions)}`); console.log(`keyOptions: ${JSON.stringify(keyOptions)}`);
} }
let keyOption: inputConsumer.KeyOptions = {preKeys: [leftAltKey], finalKey: tabKey, isFinalKeyDown: true, finalKeyDownDuration: 0}; let keyOption: inputConsumer.KeyOptions = {preKeys: [leftAltKey], finalKey: tabKey, isFinalKeyDown: true, finalKeyDownDuration: 0};
...@@ -104,7 +103,6 @@ try { ...@@ -104,7 +103,6 @@ try {
} }
``` ```
## KeyOptions ## KeyOptions
Represents combination key options. Represents combination key options.
...@@ -113,7 +111,7 @@ Represents combination key options. ...@@ -113,7 +111,7 @@ Represents combination key options.
| Name | Type | Readable | Writable | Description | | Name | Type | Readable | Writable | Description |
| --------- | ------ | ---- | ---- | ------- | | --------- | ------ | ---- | ---- | ------- |
| preKeys | Array<number> | Yes | No| Front key set. The number of front keys ranges from 0 to 4. There is no requirement on the sequence of the keys.| | preKeys | Array\<number> | Yes | No| Preceding key set. The number of preceding keys ranges from 0 to 4. There is no requirement on the sequence of the keys.<br>For example, in the combination keys **Ctrl+Alt+A**, **Ctrl+Alt** are called preceding keys.|
| finalKey | number | Yes | No| Final key. This parameter is mandatory. A callback function is triggered by the final key.| | finalKey | number | Yes | No| Final key. This parameter is mandatory. A callback is triggered by the final key.<br>For example, in the combination keys **Ctrl+Alt+A**, **A** is called the final key.|
| isFinalKeyDown | boolean | Yes | No| Whether the final key is pressed.| | isFinalKeyDown | boolean | Yes | No| Whether the final key is pressed.<br>The value **true** indicates that the key is pressed, and the value **false** indicates the opposite.|
| finalKeyDownDuration | number | Yes | No| Duration within which the final key is pressed. If the value is **0**, the callback function is triggered immediately. If the value is greater than **0** and the value of **isFinalKeyDown** is **true**, the callback function is triggered when the key press duration is longer than the value of this parameter. If the value of **isFinalKeyDown** is **false**, the callback function is triggered when the duration from key press to key release is less than the value of this parameter. | | finalKeyDownDuration | number | Yes | No| Duration for pressing a key, in μs.<br>If the value of this field is **0**, a callback is triggered immediately.<br>If the value of this field is greater than **0** and **isFinalKeyDown** is **true**, a callback is triggered when the key keeps being pressed after the specified duration expires. If **isFinalKeyDown** is **false**, a callback is triggered when the key is released before the specified duration expires. |
# @ohos.multimodalInput.inputEvent (Input Event) # @ohos.multimodalInput.inputEvent (Input Event)
The **inputEvent** module describes basic events reported by an input device. The **inputEvent** module provides the basic events reported by the device.
> **NOTE**<br> > **NOTE**
>
> The initial APIs of this module are supported since API version 9. Newly added APIs will be marked with a superscript to indicate their earliest API version. > The initial APIs of this module are supported since API version 9. Newly added APIs will be marked with a superscript to indicate their earliest API version.
## Modules to Import ## Modules to Import
...@@ -13,16 +14,14 @@ import InputEvent from '@ohos.multimodalInput.inputEvent'; ...@@ -13,16 +14,14 @@ import InputEvent from '@ohos.multimodalInput.inputEvent';
## InputEvent ## InputEvent
Defines an input event. Represents an input event.
**System capability**: SystemCapability.MultimodalInput.Input.Core **System capability**: SystemCapability.MultimodalInput.Input.Core
**Parameters** | Name | Type | Readable | Writable | Description |
| ---------- | ------ | ---- | ---- | -------------- |
| Name| Type| Readable| Writable| Description| | id | number | Yes | No | Event ID.|
| -------- | -------- | -------- | -------- | -------- | | deviceId | number | Yes | No | ID of the device that reports the input event. |
| id | number | Yes| No| Unique event ID generated by the server.| | actionTime | number | Yes | No | Time when the input event is reported. |
| deviceId | number | Yes| No| ID of the device that reports the input event.| | screenId | number | Yes | No | ID of the target screen. |
| actionTime | number | Yes| No| Time when the event is reported.| | windowId | number | Yes | No | ID of the target window. |
| screenId | number | Yes| No| ID of the target screen.|
| windowId | number | Yes| No| ID of the target window.|
# @ohos.multimodalInput.inputEventClient (Key Event Injection) # @ohos.multimodalInput.inputEventClient (Key Injection)
The **inputEventClient** module implements injection of key events. The **inputEventClient** module implements injection of key events.
> **NOTE** > **NOTE**
>
> - The initial APIs of this module are supported since API version 8. Newly added APIs will be marked with a superscript to indicate their earliest API version. > - The initial APIs of this module are supported since API version 8. Newly added APIs will be marked with a superscript to indicate their earliest API version.
>
> - The APIs provided by this module are system APIs. > - The APIs provided by this module are system APIs.
## Modules to Import ## Modules to Import
```js ```js
import inputEventClient from '@ohos.multimodalInput.inputEventClient'; import inputEventClient from '@ohos.multimodalInput.inputEventClient';
``` ```
## inputEventClient.injectEvent ## inputEventClient.injectEvent
injectEvent({KeyEvent: KeyEvent}): void injectEvent({KeyEvent: KeyEvent}): void
Injects a key event. Currently, key injection is supported only for the **Back** key (key value 2). Injects a key event. Currently, this API applies only to the **/KEYCODE_BACK** key (key value 2).
**System capability**: SystemCapability.MultimodalInput.Input.InputSimulator **System capability**: SystemCapability.MultimodalInput.Input.InputSimulator
...@@ -53,7 +52,6 @@ try { ...@@ -53,7 +52,6 @@ try {
} }
``` ```
## KeyEvent ## KeyEvent
Represents information about the key event to inject. Represents information about the key event to inject.
...@@ -62,7 +60,7 @@ Represents information about the key event to inject. ...@@ -62,7 +60,7 @@ Represents information about the key event to inject.
| Name | Type | Readable | Writable | Description | | Name | Type | Readable | Writable | Description |
| --------- | ------ | ---- | ---- | ------- | | --------- | ------ | ---- | ---- | ------- |
| isPressed | boolean | Yes | No| Whether the key is pressed. | | isPressed | boolean | Yes | No| Whether the key is pressed.<br>The value **true** indicates that the key is pressed, and the value **false** indicates the opposite. |
| keyCode | number | Yes | No| Key value. Currently, only the **Back** key is supported.| | keyCode | number | Yes | No| Keycode value. Currently, only the **KEYCODE_BACK** key is supported.|
| keyDownDuration | number | Yes | No| Duration within which the key is pressed. | | keyDownDuration | number | Yes | No| Duration for pressing a key, in μs. |
| isIntercepted | boolean | Yes | No| Whether the key can be intercepted. | | isIntercepted | boolean | Yes | No| Whether the key event can be intercepted.<br>The value **true** indicates that the key event can be intercepted, and the value **false** indicates the opposite.|
# @ohos.multimodalInput.inputMonitor (Input Monitor) # @ohos.multimodalInput.inputMonitor (Input Monitor)
The **inputMonitor** module implements listening for events of input devices (namely, touchscreen and mouse). The **inputMonitor** module implements listening for events of input devices, including the touchscreen, mouse, touchpad, etc.
> **NOTE** >**NOTE**
> >
> - The initial APIs of this module are supported since API version 7. Newly added APIs will be marked with a superscript to indicate their earliest API version. >- The initial APIs of this module are supported since API version 7. Newly added APIs will be marked with a superscript to indicate their earliest API version.
> - The APIs provided by this module are system APIs. >
>- The APIs provided by this module are system APIs.
>
>- In this document, **global** indicates the entire touchscreen or touchpad. For example, listening for global touch events means to listen for touch events of the entire touchpad when a user touches at any position on the touchpad.
## Modules to Import ## Modules to Import
```js ```js
import inputMonitor from '@ohos.multimodalInput.inputMonitor'; import inputMonitor from '@ohos.multimodalInput.inputMonitor';
``` ```
## inputMonitor.on('touch')
## inputMonitor.on on(type: 'touch', receiver: TouchEventReceiver): void
on(type: "touch", receiver: TouchEventReceiver): void
Enables listening for global touch events. Enables listening for global touch (touchscreen) events.
**Required permissions**: ohos.permission.INPUT_MONITORING **Required permissions**: ohos.permission.INPUT_MONITORING
...@@ -30,14 +30,14 @@ Enables listening for global touch events. ...@@ -30,14 +30,14 @@ Enables listening for global touch events.
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| -------- | ---------------------------------------- | ---- | ------------------- | | -------- | ---------------------------------------- | ---- | ------------------- |
| type | string | Yes | Type of the input device event. The value is **touch**.| | type | string | Yes | Event type. This field has a fixed value of **touch**.|
| receiver | [TouchEventReceiver](#toucheventreceiver) | Yes | Callback used to return the touch event.| | receiver | [TouchEventReceiver](#toucheventreceiver) | Yes | Callback used to return the touch event asynchronously.|
**Example** **Example**
```js ```js
try { try {
inputMonitor.on("touch", (touchEvent: TouchEvent) => { inputMonitor.on('touch', (touchEvent) => {
console.log(`Monitor on success ${JSON.stringify(touchEvent)}`); console.log(`Monitor on success ${JSON.stringify(touchEvent)}`);
return false; return false;
}); });
...@@ -46,9 +46,9 @@ try { ...@@ -46,9 +46,9 @@ try {
} }
``` ```
## inputMonitor.on<sup>9+</sup> ## inputMonitor.on('mouse')<sup>9+</sup>
on(type: "mouse", receiver: Callback&lt;MouseEvent&gt;): void on(type: 'mouse', receiver: Callback&lt;MouseEvent&gt;): void
Enables listening for global mouse events. Enables listening for global mouse events.
...@@ -60,14 +60,14 @@ Enables listening for global mouse events. ...@@ -60,14 +60,14 @@ Enables listening for global mouse events.
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| -------- | -------------------------- | ---- | ------------------- | | -------- | -------------------------- | ---- | ------------------- |
| type | string | Yes | Type of the input device event. The value is **mouse**.| | type | string | Yes | Event type. This field has a fixed value of **mouse**.|
| receiver | Callback&lt;MouseEvent&gt; | Yes | Callback used to return the mouse event. | | receiver | Callback&lt;MouseEvent&gt; | Yes | Callback used to return the mouse event asynchronously. |
**Example** **Example**
```js ```js
try { try {
inputMonitor.on("mouse", (mouseEvent) => { inputMonitor.on('mouse', (mouseEvent) => {
console.log(`Monitor on success ${JSON.stringify(mouseEvent)}`); console.log(`Monitor on success ${JSON.stringify(mouseEvent)}`);
return false; return false;
}); });
...@@ -76,13 +76,11 @@ try { ...@@ -76,13 +76,11 @@ try {
} }
``` ```
## inputMonitor.off('touch')
off(type: 'touch', receiver?: TouchEventReceiver): void
## inputMonitor.off Disables listening for global touch (touchscreen) events.
off(type: "touch", receiver?: TouchEventReceiver): void
Disables listening for global touch events.
**Required permissions**: ohos.permission.INPUT_MONITORING **Required permissions**: ohos.permission.INPUT_MONITORING
...@@ -92,20 +90,20 @@ Disables listening for global touch events. ...@@ -92,20 +90,20 @@ Disables listening for global touch events.
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| -------- | ---------------------------------------- | ---- | ------------------- | | -------- | ---------------------------------------- | ---- | ------------------- |
| type | string | Yes | Type of the input device event. The value is **touch**.| | type | string | Yes | Event type. This field has a fixed value of **touch**.|
| receiver | [TouchEventReceiver](#toucheventreceiver) | No | Callback for which listening is disabled. If this parameter is not specified, listening will be disabled for all callbacks registered by the current application. | | receiver | [TouchEventReceiver](#toucheventreceiver) | No | Callback for which listening is disabled. If this parameter is not specified, listening will be disabled for all callbacks registered by the current application. |
**Example** **Example**
```js ```js
// Disable listening for a single callback function. // Disable listening for a single callback.
let callback = (touchEvent: touchEvent) => { function callback(touchEvent) {
console.log(`Monitor on success ${JSON.stringify(touchEvent)}`); console.log(`Monitor on success ${JSON.stringify(touchEvent)}`);
return false; return false;
}; };
try { try {
inputMonitor.on("touch", callback); inputMonitor.on('touch', callback);
inputMonitor.off("touch", callback); inputMonitor.off('touch', callback);
console.log(`Monitor off success`); console.log(`Monitor off success`);
} catch (error) { } catch (error) {
console.log(`Monitor execute failed, error: ${JSON.stringify(error, [`code`, `message`])}`); console.log(`Monitor execute failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
...@@ -113,25 +111,25 @@ try { ...@@ -113,25 +111,25 @@ try {
``` ```
```js ```js
// Cancel listening for all callback functions. // Cancel listening for all callbacks.
let callback = (touchEvent: touchEvent) => { function callback(touchEvent) {
console.log(`Monitor on success ${JSON.stringify(touchEvent)}`); console.log(`Monitor on success ${JSON.stringify(touchEvent)}`);
return false; return false;
}; };
try { try {
inputMonitor.on("touch", callback); inputMonitor.on('touch', callback);
inputMonitor.off("touch"); inputMonitor.off('touch');
console.log(`Monitor off success`); console.log(`Monitor off success`);
} catch (error) { } catch (error) {
console.log(`Monitor execute failed, error: ${JSON.stringify(error, [`code`, `message`])}`); console.log(`Monitor execute failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
} }
``` ```
## inputMonitor.off<sup>9+</sup> ## inputMonitor.off('mouse')<sup>9+</sup>
off(type: "mouse", receiver?: Callback&lt;MouseEvent&gt;): void off(type: 'mouse', receiver?: Callback&lt;MouseEvent&gt;): void
Stops listening for global mouse events. Disables listening for global mouse events.
**Required permissions**: ohos.permission.INPUT_MONITORING **Required permissions**: ohos.permission.INPUT_MONITORING
...@@ -141,7 +139,7 @@ Stops listening for global mouse events. ...@@ -141,7 +139,7 @@ Stops listening for global mouse events.
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| -------- | -------------------------- | ---- | ------------------- | | -------- | -------------------------- | ---- | ------------------- |
| type | string | Yes | Type of the input device event. The value is **mouse**.| | type | string | Yes | Event type. This field has a fixed value of **mouse**.|
| receiver | Callback&lt;MouseEvent&gt; | No | Callback for which listening is disabled. If this parameter is not specified, listening will be disabled for all callbacks registered by the current application.| | receiver | Callback&lt;MouseEvent&gt; | No | Callback for which listening is disabled. If this parameter is not specified, listening will be disabled for all callbacks registered by the current application.|
**Example** **Example**
...@@ -153,8 +151,8 @@ let callback = (mouseEvent: MouseEvent) => { ...@@ -153,8 +151,8 @@ let callback = (mouseEvent: MouseEvent) => {
return false; return false;
}; };
try { try {
inputMonitor.on("mouse", callback); inputMonitor.on('mouse', callback);
inputMonitor.off("mouse", callback); inputMonitor.off('mouse', callback);
console.log(`Monitor off success`); console.log(`Monitor off success`);
} catch (error) { } catch (error) {
console.log(`Monitor execute failed, error: ${JSON.stringify(error, [`code`, `message`])}`); console.log(`Monitor execute failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
...@@ -162,14 +160,14 @@ try { ...@@ -162,14 +160,14 @@ try {
``` ```
```js ```js
// Disable listening for all callback functions. // Disable listening for all callbacks.
let callback = (mouseEvent: MouseEvent) => { function callback(mouseEvent) {
console.log(`Monitor on success ${JSON.stringify(mouseEvent)}`); console.log(`Monitor on success ${JSON.stringify(mouseEvent)}`);
return false; return false;
}; };
try { try {
inputMonitor.on("mouse", callback); inputMonitor.on('mouse', callback);
inputMonitor.off("mouse"); inputMonitor.off('mouse');
console.log(`Monitor off success`); console.log(`Monitor off success`);
} catch (error) { } catch (error) {
console.log(`Monitor execute failed, error: ${JSON.stringify(error, [`code`, `message`])}`); console.log(`Monitor execute failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
...@@ -178,7 +176,7 @@ try { ...@@ -178,7 +176,7 @@ try {
## TouchEventReceiver ## TouchEventReceiver
Represents the callback used to return the touch event. Defines the callback for touch (touchscreen) events.
**Required permissions**: ohos.permission.INPUT_MONITORING **Required permissions**: ohos.permission.INPUT_MONITORING
...@@ -200,7 +198,7 @@ Represents the callback used to return the touch event. ...@@ -200,7 +198,7 @@ Represents the callback used to return the touch event.
```js ```js
try { try {
inputMonitor.on("touch", touchEvent => { inputMonitor.on('touch', touchEvent => {
if (touchEvent.touches.length == 3) {// Three fingers are pressed. if (touchEvent.touches.length == 3) {// Three fingers are pressed.
return true; return true;
} }
...@@ -210,3 +208,240 @@ try { ...@@ -210,3 +208,240 @@ try {
console.log(`Monitor on failed, error: ${JSON.stringify(error, [`code`, `message`])}`); console.log(`Monitor on failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
} }
``` ```
## inputMonitor.on('pinch')<sup>10+</sup>
on(type: 'pinch', receiver: Callback&lt;[Pinch](js-apis-multimodalinput-gestureevent.md#pinch)&gt;): void
Enables listening for global touchpad pinch events.
**Required permissions**: ohos.permission.INPUT_MONITORING
**System capability**: SystemCapability.MultimodalInput.Input.InputMonitor
**Parameters**
| Name | Type | Mandatory | Description |
| -------- | -------------------------- | ---- | ------------------- |
| type | string | Yes | Event type. This field has a fixed value of **pinch**.|
| receiver | Callback&lt;[Pinch](js-apis-multimodalinput-gestureevent.md#pinch)&gt; | Yes | Callback used to return the pinch event asynchronously. |
**Example**
```js
try {
inputMonitor.on('pinch', (pinchEvent) => {
console.log(`Monitor on success ${JSON.stringify(pinchEvent)}`);
return false;
});
} catch (error) {
console.log(`Monitor on failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
}
```
## inputMonitor.off('pinch')<sup>10+</sup>
off(type: 'pinch', receiver?: Callback&lt;[Pinch](js-apis-multimodalinput-gestureevent.md#pinch)&gt;): void
Disables listening for global touchpad pinch events.
**Required permissions**: ohos.permission.INPUT_MONITORING
**System capability**: SystemCapability.MultimodalInput.Input.InputMonitor
**Parameters**
| Name | Type | Mandatory | Description |
| -------- | -------------------------- | ---- | ------------------- |
| type | string | Yes | Event type. This field has a fixed value of **pinch**.|
| receiver | Callback&lt;[Pinch](js-apis-multimodalinput-gestureevent.md#pinch)&gt; | No | Callback for which listening is disabled. If this parameter is not specified, listening will be disabled for all callbacks registered by the current application.|
**Example**
```js
// Disable listening for a single callback.
function callback(pinchEvent) {
console.log(`Monitor on success ${JSON.stringify(pinchEvent)}`);
return false;
};
try {
inputMonitor.on('pinch', callback);
inputMonitor.off('pinch', callback);
console.log(`Monitor off success`);
} catch (error) {
console.log(`Monitor execute failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
}
```
```js
// Cancel listening for all callbacks.
function callback(pinchEvent) {
console.log(`Monitor on success ${JSON.stringify(pinchEvent)}`);
return false;
};
try {
inputMonitor.on('pinch', callback);
inputMonitor.off('pinch');
console.log(`Monitor off success`);
} catch (error) {
console.log(`Monitor execute failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
}
```
## inputMonitor.on('threeFingersSwipe')<sup>10+</sup>
on(type: 'threeFingersSwipe', receiver: Callback&lt;[ThreeFingersSwipe](js-apis-multimodalinput-gestureevent.md#threefingersswipe)&gt;): void
Enables listening for three-finger swipe events.
**Required permissions**: ohos.permission.INPUT_MONITORING
**System capability**: SystemCapability.MultimodalInput.Input.InputMonitor
**Parameters**
| Name | Type | Mandatory | Description |
| -------- | -------------------------- | ---- | ------------------- |
| type | string | Yes | Event type. This field has a fixed value of **threeFingersSwipe**.|
| receiver | Callback&lt;[ThreeFingersSwipe](js-apis-multimodalinput-gestureevent.md#threefingersswipe)&gt; | Yes | Callback used to return the three-finger swipe event asynchronously. |
**Example**
```js
try {
inputMonitor.on('threeFingersSwipe', (threeFingersSwipe) => {
console.log(`Monitor on success ${JSON.stringify(threeFingersSwipe)}`);
return false;
});
} catch (error) {
console.log(`Monitor on failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
}
```
## inputMonitor.off('threeFingersSwipe')<sup>10+</sup>
off(type: 'threeFingersSwipe', receiver?: Callback&lt;[ThreeFingersSwipe](js-apis-multimodalinput-gestureevent.md#threefingersswipe)&gt;): void
Disables listening for three-finger swipe events.
**Required permissions**: ohos.permission.INPUT_MONITORING
**System capability**: SystemCapability.MultimodalInput.Input.InputMonitor
**Parameters**
| Name | Type | Mandatory | Description |
| -------- | -------------------------- | ---- | ------------------- |
| type | string | Yes | Event type. This field has a fixed value of **threeFingersSwipe**.|
| receiver | Callback&lt;[ThreeFingersSwipe](js-apis-multimodalinput-gestureevent.md#threefingersswipe)&gt; | No | Callback for which listening is disabled. If this parameter is not specified, listening will be disabled for all callbacks registered by the current application.|
**Example**
```js
// Disable listening for a single callback.
function callback(threeFingersSwipe) {
console.log(`Monitor on success ${JSON.stringify(threeFingersSwipe)}`);
return false;
};
try {
inputMonitor.on('threeFingersSwipe', callback);
inputMonitor.off("threeFingersSwipe", callback);
console.log(`Monitor off success`);
} catch (error) {
console.log(`Monitor execute failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
}
```
```js
// Cancel listening for all callbacks.
function callback(threeFingersSwipe) {
console.log(`Monitor on success ${JSON.stringify(threeFingersSwipe)}`);
return false;
};
try {
inputMonitor.on("threeFingersSwipe", callback);
inputMonitor.off("threeFingersSwipe");
console.log(`Monitor off success`);
} catch (error) {
console.log(`Monitor execute failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
}
```
## inputMonitor.on('fourFingersSwipe')<sup>10+</sup>
on(type: 'fourFingersSwipe', receiver: Callback&lt;[FourFingersSwipe](js-apis-multimodalinput-gestureevent.md#fourfingersswipe)&gt;): void
Enables listening for four-finger swipe events.
**Required permissions**: ohos.permission.INPUT_MONITORING
**System capability**: SystemCapability.MultimodalInput.Input.InputMonitor
**Parameters**
| Name | Type | Mandatory | Description |
| -------- | -------------------------- | ---- | ------------------- |
| type | string | Yes | Event type. This field has a fixed value of **fourFingersSwipe**.|
| receiver | Callback&lt;[FourFingersSwipe](js-apis-multimodalinput-gestureevent.md#fourfingersswipe)&gt; | Yes | Callback used to return the four-finger swipe event asynchronously. |
**Example**
```js
try {
inputMonitor.on('fourFingersSwipe', (fourFingersSwipe) => {
console.log(`Monitor on success ${JSON.stringify(fourFingersSwipe)}`);
return false;
});
} catch (error) {
console.log(`Monitor on failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
}
```
## inputMonitor.off('fourFingersSwipe')<sup>10+</sup>
off(type: 'fourFingersSwipe', receiver?: Callback&lt;[FourFingersSwipe](js-apis-multimodalinput-gestureevent.md#fourfingersswipe)&gt;): void
Disables listening for four-finger swipe events.
**Required permissions**: ohos.permission.INPUT_MONITORING
**System capability**: SystemCapability.MultimodalInput.Input.InputMonitor
**Parameters**
| Name | Type | Mandatory | Description |
| -------- | -------------------------- | ---- | ------------------- |
| type | string | Yes | Event type. This field has a fixed value of **fourFingersSwipe**.|
| receiver | Callback&lt;[FourFingersSwipe](js-apis-multimodalinput-gestureevent.md#fourfingersswipe)&gt; | No | Callback for which listening is disabled. If this parameter is not specified, listening will be disabled for all callbacks registered by the current application.|
**Example**
```js
// Disable listening for a single callback.
function callback(fourFingersSwipe) {
console.log(`Monitor on success ${JSON.stringify(fourFingersSwipe)}`);
return false;
};
try {
inputMonitor.on('fourFingersSwipe', callback);
inputMonitor.off('fourFingersSwipe', callback);
console.log(`Monitor off success`);
} catch (error) {
console.log(`Monitor execute failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
}
```
```js
// Cancel listening for all callbacks.
function callback(fourFingersSwipe) {
console.log(`Monitor on success ${JSON.stringify(fourFingersSwipe)}`);
return false;
};
try {
inputMonitor.on('fourFingersSwipe', callback);
inputMonitor.off('fourFingersSwipe');
console.log(`Monitor off success`);
} catch (error) {
console.log(`Monitor execute failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
}
```
# @ohos.multimodalInput.keyCode (Key Code) # @ohos.multimodalInput.keyCode (Keycode)
The **keyCode** module provides keycodes for a key device. The **keyCode** module provides keycode values for key devices, such as the keyboard, power key, camera key, and the like.
> **NOTE** > **NOTE**
> >
...@@ -14,14 +14,14 @@ import {KeyCode} from '@ohos.multimodalInput.keyCode'; ...@@ -14,14 +14,14 @@ import {KeyCode} from '@ohos.multimodalInput.keyCode';
## KeyCode ## KeyCode
Enumerates keycodes. Keycode value.
**System capability**: SystemCapability.MultimodalInput.Input.Core **System capability**: SystemCapability.MultimodalInput.Input.Core
| Name | Value | Description | | Name | Value | Description |
| -------------------------------- | ------ | --------------------------- | | -------------------------------- | ------ | --------------------------- |
| KEYCODE_FN | 0 | Function (Fn) key | | KEYCODE_FN | 0 | Function (Fn) key |
| KEYCODE_UNKNOWN | -1 | Unknown key | | KEYCODE_UNKNOWN | -1 | Unknown key |
| KEYCODE_HOME | 1 | Function (Home) key | | KEYCODE_HOME | 1 | Function (Home) key |
| KEYCODE_BACK | 2 | Back key | | KEYCODE_BACK | 2 | Back key |
| KEYCODE_MEDIA_PLAY_PAUSE | 10 | Play/Pause key | | KEYCODE_MEDIA_PLAY_PAUSE | 10 | Play/Pause key |
...@@ -50,8 +50,8 @@ Enumerates keycodes. ...@@ -50,8 +50,8 @@ Enumerates keycodes.
| KEYCODE_9 | 2009 | Key 9 | | KEYCODE_9 | 2009 | Key 9 |
| KEYCODE_STAR | 2010 | Key * | | KEYCODE_STAR | 2010 | Key * |
| KEYCODE_POUND | 2011 | Key # | | KEYCODE_POUND | 2011 | Key # |
| KEYCODE_DPAD_UP | 2012 | Up key on D-pad | | KEYCODE_DPAD_UP | 2012 | Up key on D-pad |
| KEYCODE_DPAD_DOWN | 2013 | Down key on D-pad | | KEYCODE_DPAD_DOWN | 2013 | Down key on D-pad |
| KEYCODE_DPAD_LEFT | 2014 | Left key on D-pad | | KEYCODE_DPAD_LEFT | 2014 | Left key on D-pad |
| KEYCODE_DPAD_RIGHT | 2015 | Right key on D-pad | | KEYCODE_DPAD_RIGHT | 2015 | Right key on D-pad |
| KEYCODE_DPAD_CENTER | 2016 | Center key on D-pad | | KEYCODE_DPAD_CENTER | 2016 | Center key on D-pad |
...@@ -90,8 +90,8 @@ Enumerates keycodes. ...@@ -90,8 +90,8 @@ Enumerates keycodes.
| KEYCODE_TAB | 2049 | Tab key | | KEYCODE_TAB | 2049 | Tab key |
| KEYCODE_SPACE | 2050 | Space key | | KEYCODE_SPACE | 2050 | Space key |
| KEYCODE_SYM | 2051 | Symbol key | | KEYCODE_SYM | 2051 | Symbol key |
| KEYCODE_EXPLORER | 2052 | Explorer key, which is used to start the explorer application | | KEYCODE_EXPLORER | 2052 | Explorer key, used to start the explorer application |
| KEYCODE_ENVELOPE | 2053 | Email key, which is used to start the email application | | KEYCODE_ENVELOPE | 2053 | Email key, used to start the email application |
| KEYCODE_ENTER | 2054 | Enter key | | KEYCODE_ENTER | 2054 | Enter key |
| KEYCODE_DEL | 2055 | Delete key | | KEYCODE_DEL | 2055 | Delete key |
| KEYCODE_GRAVE | 2056 | Key ` | | KEYCODE_GRAVE | 2056 | Key ` |
...@@ -106,7 +106,7 @@ Enumerates keycodes. ...@@ -106,7 +106,7 @@ Enumerates keycodes.
| KEYCODE_AT | 2065 | Key @ | | KEYCODE_AT | 2065 | Key @ |
| KEYCODE_PLUS | 2066 | Key + | | KEYCODE_PLUS | 2066 | Key + |
| KEYCODE_MENU | 2067 | Menu key | | KEYCODE_MENU | 2067 | Menu key |
| KEYCODE_PAGE_UP | 2068 | Page Up key | | KEYCODE_PAGE_UP | 2068 | Page Up key |
| KEYCODE_PAGE_DOWN | 2069 | Page Down key | | KEYCODE_PAGE_DOWN | 2069 | Page Down key |
| KEYCODE_ESCAPE | 2070 | ESC key | | KEYCODE_ESCAPE | 2070 | ESC key |
| KEYCODE_FORWARD_DEL | 2071 | Delete key | | KEYCODE_FORWARD_DEL | 2071 | Delete key |
...@@ -188,7 +188,7 @@ Enumerates keycodes. ...@@ -188,7 +188,7 @@ Enumerates keycodes.
| KEYCODE_FIND | 2623 | Find key | | KEYCODE_FIND | 2623 | Find key |
| KEYCODE_CUT | 2624 | Cut key | | KEYCODE_CUT | 2624 | Cut key |
| KEYCODE_HELP | 2625 | Help key | | KEYCODE_HELP | 2625 | Help key |
| KEYCODE_CALC | 2626 | Calc key, which is used to start the calculator application | | KEYCODE_CALC | 2626 | Calc key, used to start the calculator application |
| KEYCODE_FILE | 2627 | File key | | KEYCODE_FILE | 2627 | File key |
| KEYCODE_BOOKMARKS | 2628 | Bookmarks key | | KEYCODE_BOOKMARKS | 2628 | Bookmarks key |
| KEYCODE_NEXT | 2629 | Next key | | KEYCODE_NEXT | 2629 | Next key |
...@@ -274,7 +274,7 @@ Enumerates keycodes. ...@@ -274,7 +274,7 @@ Enumerates keycodes.
| KEYCODE_MESSENGER | 2710 | Messenger key | | KEYCODE_MESSENGER | 2710 | Messenger key |
| KEYCODE_BRIGHTNESS_TOGGLE | 2711 | Brightness Toggle key | | KEYCODE_BRIGHTNESS_TOGGLE | 2711 | Brightness Toggle key |
| KEYCODE_SPELLCHECK | 2712 | Spell Check key | | KEYCODE_SPELLCHECK | 2712 | Spell Check key |
| KEYCODE_COFFEE | 2713 | Coffee key, which is used to launch screen lock or screen saver | | KEYCODE_COFFEE | 2713 | Coffee key, used to launch screen lock or screen saver |
| KEYCODE_MEDIA_REPEAT | 2714 | Media Repeat key | | KEYCODE_MEDIA_REPEAT | 2714 | Media Repeat key |
| KEYCODE_IMAGES | 2715 | Images key | | KEYCODE_IMAGES | 2715 | Images key |
| KEYCODE_BUTTONCONFIG | 2716 | Button Configuration key | | KEYCODE_BUTTONCONFIG | 2716 | Button Configuration key |
...@@ -293,12 +293,12 @@ Enumerates keycodes. ...@@ -293,12 +293,12 @@ Enumerates keycodes.
| KEYCODE_KBDINPUTASSIST_NEXTGROUP | 2729 | Keyboard Input-assisted Next Group key | | KEYCODE_KBDINPUTASSIST_NEXTGROUP | 2729 | Keyboard Input-assisted Next Group key |
| KEYCODE_KBDINPUTASSIST_ACCEPT | 2730 | Keyboard Input-assisted Accept key | | KEYCODE_KBDINPUTASSIST_ACCEPT | 2730 | Keyboard Input-assisted Accept key |
| KEYCODE_KBDINPUTASSIST_CANCEL | 2731 | Keyboard Input-assisted Cancel key | | KEYCODE_KBDINPUTASSIST_CANCEL | 2731 | Keyboard Input-assisted Cancel key |
| KEYCODE_FRONT | 2800 | Front key, which is used to launch the windshield defogger | | KEYCODE_FRONT | 2800 | Front key, used to launch the windshield defogger |
| KEYCODE_SETUP | 2801 | Setup key | | KEYCODE_SETUP | 2801 | Setup key |
| KEYCODE_WAKEUP | 2802 | Wakeup key | | KEYCODE_WAKEUP | 2802 | Wakeup key |
| KEYCODE_SENDFILE | 2803 | Send File key | | KEYCODE_SENDFILE | 2803 | Send File key |
| KEYCODE_DELETEFILE | 2804 | Delete File key | | KEYCODE_DELETEFILE | 2804 | Delete File key |
| KEYCODE_XFER | 2805 | XFER key, which is used to start file transfer | | KEYCODE_XFER | 2805 | XFER key, used to start file transfer |
| KEYCODE_PROG1 | 2806 | Program key 1 | | KEYCODE_PROG1 | 2806 | Program key 1 |
| KEYCODE_PROG2 | 2807 | Program key 2 | | KEYCODE_PROG2 | 2807 | Program key 2 |
| KEYCODE_MSDOS | 2808 | MS-DOS key | | KEYCODE_MSDOS | 2808 | MS-DOS key |
......
# @ohos.multimodalInput.keyEvent (Key Event) # @ohos.multimodalInput.keyEvent (Key Event)
The **keyEvent** module provides key events reported by an input device. The **keyEvent** module provides key events reported by input devices.
> **NOTE**<br> > **NOTE**
>
> The initial APIs of this module are supported since API version 9. Newly added APIs will be marked with a superscript to indicate their earliest API version. > The initial APIs of this module are supported since API version 9. Newly added APIs will be marked with a superscript to indicate their earliest API version.
## Modules to Import ## Modules to Import
...@@ -13,13 +14,13 @@ import {Action, Key, KeyEvent} from '@ohos.multimodalInput.keyEvent'; ...@@ -13,13 +14,13 @@ import {Action, Key, KeyEvent} from '@ohos.multimodalInput.keyEvent';
## Action ## Action
Defines a key action. Key event type.
**System capability**: SystemCapability.MultimodalInput.Input.Core **System capability**: SystemCapability.MultimodalInput.Input.Core
| Name | Value | Description | | Name | Value | Description |
| ------ | ------- | -------- | | ------ | ------- | -------- |
| CANCEL | 0 | Cancellation of a key action.| | CANCEL | 0 | Cancellation of a key action.|
| DOWN | 1 | Pressing of a key.| | DOWN | 1 | Pressing of a key.|
| UP | 2 | Release of a key.| | UP | 2 | Release of a key.|
...@@ -32,26 +33,26 @@ Defines a key. ...@@ -32,26 +33,26 @@ Defines a key.
| Name | Type| Readable| Writable| Description | | Name | Type| Readable| Writable| Description |
| ----------- | -------- | ---- | ---- | -------------- | | ----------- | -------- | ---- | ---- | -------------- |
| code | KeyCode | Yes | No | Keycode. | | code | KeyCode | Yes | No | Keycode. |
| pressedTime | number | Yes | No | Time when the key is pressed.| | pressedTime | number | Yes | No | Duration for pressing a key, in μs.|
| deviceId | number | Yes | No | ID of the device to which the key belongs. | | deviceId | number | Yes | No | ID of the device to which the key belongs. |
## KeyEvent ## KeyEvent
Defines a key event. Key event.
**System capability**: SystemCapability.MultimodalInput.Input.Core **System capability**: SystemCapability.MultimodalInput.Input.Core
| Name | Type| Readable| Writable| Description | | Name | Type| Readable| Writable| Description |
| ----------- | -------- | ---- | ---- | ------------------------------ | | ----------- | -------- | ---- | ---- | ------------------------------ |
| action | Action | Yes | No | Key action. | | action | [Action](#action) | Yes | No | Key action. |
| key | Key | Yes | No | Key for which the event is reported. | | key | [Key](#key) | Yes | No | Key for which the event is reported. |
| unicodeChar | number | Yes | No | Unicode character corresponding to the key. | | unicodeChar | number | Yes | No | Unicode character corresponding to the key. |
| keys | Key[] | Yes | No | List of pressed keys. | | keys | Key[] | Yes | No | List of pressed keys. |
| ctrlKey | boolean | Yes | No | Whether ctrlKey is being pressed. | | ctrlKey | boolean | Yes | No | Whether ctrlKey is being pressed.<br>The value **true** indicates that the key is pressed, and the value **false** indicates the opposite.|
| altKey | boolean | Yes | No | Whether altKey is being pressed. | | altKey | boolean | Yes | No | Whether altKey is being pressed. |
| shiftKey | boolean | Yes | No | Whether shiftKey is being pressed. | | shiftKey | boolean | Yes | No | Whether shiftKey is being pressed. |
| logoKey | boolean | Yes | No | Whether logoKey is being pressed. | | logoKey | boolean | Yes | No | Whether logoKey is being pressed. |
| fnKey | boolean | Yes | No | Whether fnKey is being pressed. | | fnKey | boolean | Yes | No | Whether fnKey is being pressed. |
| capsLock | boolean | Yes | No | Whether capsLock is active. | | capsLock | boolean | Yes | No | Whether capsLock is active.<br>The value **true** indicates that capsLock is active, and the value **false** indicates the opposite. |
| numLock | boolean | Yes | No | Whether numLock is active. | | numLock | boolean | Yes | No | Whether numLock is active. |
| scrollLock | boolean | Yes | No | Whether scrollLock is active.| | scrollLock | boolean | Yes | No | Whether scrollLock is active.|
...@@ -2,7 +2,8 @@ ...@@ -2,7 +2,8 @@
The **mouseEvent** module provides mouse events reported by an input device. The **mouseEvent** module provides mouse events reported by an input device.
> **NOTE**<br> > **NOTE**
>
> The initial APIs of this module are supported since API version 9. Newly added APIs will be marked with a superscript to indicate their earliest API version. > The initial APIs of this module are supported since API version 9. Newly added APIs will be marked with a superscript to indicate their earliest API version.
## Modules to Import ## Modules to Import
...@@ -13,7 +14,7 @@ import { Action, Button, Axis, AxisValue, MouseEvent } from '@ohos.multimodalInp ...@@ -13,7 +14,7 @@ import { Action, Button, Axis, AxisValue, MouseEvent } from '@ohos.multimodalInp
## Action ## Action
Defines a mouse action. Enumerates mouse event types.
**System capability**: SystemCapability.MultimodalInput.Input.Core **System capability**: SystemCapability.MultimodalInput.Input.Core
...@@ -27,10 +28,9 @@ Defines a mouse action. ...@@ -27,10 +28,9 @@ Defines a mouse action.
| AXIS_UPDATE | 5 | Updating of the axis event associated with the mouse.| | AXIS_UPDATE | 5 | Updating of the axis event associated with the mouse.|
| AXIS_END | 6 | Ending of the axis event associated with the mouse.| | AXIS_END | 6 | Ending of the axis event associated with the mouse.|
## Button ## Button
Enumerates mouse actions. Enumerates mouse buttons.
**System capability**: SystemCapability.MultimodalInput.Input.Core **System capability**: SystemCapability.MultimodalInput.Input.Core
...@@ -60,7 +60,7 @@ Enumerates mouse axis types. ...@@ -60,7 +60,7 @@ Enumerates mouse axis types.
## AxisValue ## AxisValue
Defines a mouse axis type and value. Defines the mouse axis type and axis value.
**System capability**: SystemCapability.MultimodalInput.Input.Core **System capability**: SystemCapability.MultimodalInput.Input.Core
...@@ -72,28 +72,28 @@ Defines a mouse axis type and value. ...@@ -72,28 +72,28 @@ Defines a mouse axis type and value.
## MouseEvent ## MouseEvent
Defines a mouse event. Defines the mouse event.
**System capability**: SystemCapability.MultimodalInput.Input.Core **System capability**: SystemCapability.MultimodalInput.Input.Core
| Name | Type | Readable | Writable | Description | | Name | Type | Readable | Writable | Description |
| -------------- | ----------- | ---- | ---- | ---------------------------------------- | | -------------- | ----------- | ---- | ---- | ---------------------------------------- |
| action | Action | Yes | No | Mouse event action. | | action | [Action](#action) | Yes | No | Mouse event action. |
| screenX | number | Yes | No | Horizontal coordinate of the mouse pointer on the screen. | | screenX | number | Yes | No | Horizontal coordinate of the mouse pointer on the screen. |
| screenY | number | Yes | No | Vertical coordinate of the mouse pointer on the screen. | | screenY | number | Yes | No | Vertical coordinate of the mouse pointer on the screen. |
| windowX | number | Yes | No | Horizontal coordinate of the mouse pointer in the window. | | windowX | number | Yes | No | Horizontal coordinate of the mouse pointer in the window. |
| windowY | number | Yes | No | Vertical coordinate of the mouse pointer in the window. | | windowY | number | Yes | No | Vertical coordinate of the mouse pointer in the window. |
| rawDeltaX | number | Yes | No | Horizontal coordinate offset relative to the previous reported mouse pointer position.| | rawDeltaX | number | Yes | No | Horizontal coordinate offset relative to the previous reported mouse pointer position.|
| rawDeltaY | number | Yes | No | Vertical coordinate offset relative to the previous reported mouse pointer position. | | rawDeltaY | number | Yes | No | Vertical coordinate offset relative to the previous reported mouse pointer position. |
| button | Button | Yes | No | Mouse button | button | [Button](#button) | Yes | No | Mouse button
| pressedButtons | Button[] | Yes | No | Button being pressed. | | pressedButtons | Button[] | Yes | No | Button being pressed. |
| axes | AxisValue[] | Yes | No | All axis data contained in the event. | | axes | AxisValue[] | Yes | No | All axis data contained in the event. |
| pressedKeys | KeyCode[] | Yes | No | List of pressed keys. | | pressedKeys | KeyCode[] | Yes | No | List of pressed keys. |
| ctrlKey | boolean | Yes | No | Whether ctrlKey is being pressed. | | ctrlKey | boolean | Yes | No | Whether ctrlKey is being pressed.<br>The value **true** indicates that the key is pressed, and the value **false** indicates the opposite. |
| altKey | boolean | Yes | No | Whether altKey is being pressed. | | altKey | boolean | Yes | No | Whether altKey is being pressed. |
| shiftKey | boolean | Yes | No | Whether shiftKey is being pressed. | | shiftKey | boolean | Yes | No | Whether shiftKey is being pressed. |
| logoKey | boolean | Yes | No | Whether logoKey is being pressed. | | logoKey | boolean | Yes | No | Whether logoKey is being pressed. |
| fnKey | boolean | Yes | No | Whether fnKey is being pressed. | | fnKey | boolean | Yes | No | Whether fnKey is being pressed. |
| capsLock | boolean | Yes | No | Whether capsLock is active. | | capsLock | boolean | Yes | No | Whether capsLock is active.<br>The value **true** indicates that capsLock is active, and the value **false** indicates the opposite. |
| numLock | boolean | Yes | No | Whether numLock is active. | | numLock | boolean | Yes | No | Whether numLock is active. |
| scrollLock | boolean | Yes | No | Whether scrollLock is active. | | scrollLock | boolean | Yes | No | Whether scrollLock is active. |
...@@ -20,9 +20,10 @@ For details about how to reference context in the stage model, see [Context in t ...@@ -20,9 +20,10 @@ For details about how to reference context in the stage model, see [Context in t
```ts ```ts
import UIAbility from '@ohos.app.ability.UIAbility'; import UIAbility from '@ohos.app.ability.UIAbility';
import window from '@ohos.window';
export default class EntryAbility extends UIAbility { export default class EntryAbility extends UIAbility {
onWindowStageCreate(windowStage) { onWindowStageCreate(windowStage: window.WindowStage) {
let context = this.context; let context = this.context;
let resourceManager = context.resourceManager; let resourceManager = context.resourceManager;
} }
...@@ -191,7 +192,9 @@ import { BusinessError } from '@ohos.base'; ...@@ -191,7 +192,9 @@ import { BusinessError } from '@ohos.base';
console.log("systemResourceManager getStringValue promise error is " + error); console.log("systemResourceManager getStringValue promise error is " + error);
}); });
} catch (error) { } catch (error) {
console.error(`systemResourceManager getStringValue failed, error code: ${error.code}, message: ${error.message}.`); let code = (error as BusinessError).code;
let message = (error as BusinessError).message;
console.error(`systemResourceManager getStringValue failed, error code: ${code}, message: ${message}.`);
} }
``` ```
...@@ -339,10 +342,14 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco ...@@ -339,10 +342,14 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco
**Example** **Example**
```ts ```ts
import { BusinessError } from '@ohos.base';
try { try {
this.context.resourceManager.getStringSync($r('app.string.test').id); this.context.resourceManager.getStringSync($r('app.string.test').id);
} catch (error) { } catch (error) {
console.error(`getStringSync failed, error code: ${error.code}, message: ${error.message}.`); let code = (error as BusinessError).code;
let message = (error as BusinessError).message;
console.error(`getStringSync failed, error code: ${code}, message: ${message}.`);
} }
``` ```
...@@ -380,10 +387,14 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco ...@@ -380,10 +387,14 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco
**Example** **Example**
```ts ```ts
import { BusinessError } from '@ohos.base';
try { try {
this.context.resourceManager.getStringSync($r('app.string.test').id, "format string", 10, 98.78); this.context.resourceManager.getStringSync($r('app.string.test').id, "format string", 10, 98.78);
} catch (error) { } catch (error) {
console.error(`getStringSync failed, error code: ${error.code}, message: ${error.message}.`); let code = (error as BusinessError).code;
let message = (error as BusinessError).message;
console.error(`getStringSync failed, error code: ${code}, message: ${message}.`);
} }
``` ```
...@@ -422,6 +433,7 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco ...@@ -422,6 +433,7 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco
**Example** **Example**
```ts ```ts
import resourceManager from '@ohos.resourceManager'; import resourceManager from '@ohos.resourceManager';
import { BusinessError } from '@ohos.base';
let resource: resourceManager.Resource = { let resource: resourceManager.Resource = {
bundleName: "com.example.myapplication", bundleName: "com.example.myapplication",
...@@ -431,7 +443,9 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco ...@@ -431,7 +443,9 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco
try { try {
this.context.resourceManager.getStringSync(resource); this.context.resourceManager.getStringSync(resource);
} catch (error) { } catch (error) {
console.error(`getStringSync failed, error code: ${error.code}, message: ${error.message}.`); let code = (error as BusinessError).code;
let message = (error as BusinessError).message;
console.error(`getStringSync failed, error code: ${code}, message: ${message}.`);
} }
``` ```
...@@ -472,6 +486,7 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco ...@@ -472,6 +486,7 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco
**Example** **Example**
```ts ```ts
import resourceManager from '@ohos.resourceManager'; import resourceManager from '@ohos.resourceManager';
import { BusinessError } from '@ohos.base';
let resource: resourceManager.Resource = { let resource: resourceManager.Resource = {
bundleName: "com.example.myapplication", bundleName: "com.example.myapplication",
...@@ -481,7 +496,9 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco ...@@ -481,7 +496,9 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco
try { try {
this.context.resourceManager.getStringSync(resource, "format string", 10, 98.78); this.context.resourceManager.getStringSync(resource, "format string", 10, 98.78);
} catch (error) { } catch (error) {
console.error(`getStringSync failed, error code: ${error.code}, message: ${error.message}.`); let code = (error as BusinessError).code;
let message = (error as BusinessError).message;
console.error(`getStringSync failed, error code: ${code}, message: ${message}.`);
} }
``` ```
...@@ -517,10 +534,14 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco ...@@ -517,10 +534,14 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco
**Example** **Example**
```ts ```ts
import { BusinessError } from '@ohos.base';
try { try {
this.context.resourceManager.getStringByNameSync("test"); this.context.resourceManager.getStringByNameSync("test");
} catch (error) { } catch (error) {
console.error(`getStringByNameSync failed, error code: ${error.code}, message: ${error.message}.`); let code = (error as BusinessError).code;
let message = (error as BusinessError).message;
console.error(`getStringByNameSync failed, error code: ${code}, message: ${message}.`);
} }
``` ```
...@@ -558,10 +579,14 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco ...@@ -558,10 +579,14 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco
**Example** **Example**
```ts ```ts
import { BusinessError } from '@ohos.base';
try { try {
this.context.resourceManager.getStringByNameSync("test", "format string", 10, 98.78); this.context.resourceManager.getStringByNameSync("test", "format string", 10, 98.78);
} catch (error) { } catch (error) {
console.error(`getStringByNameSync failed, error code: ${error.code}, message: ${error.message}.`); let code = (error as BusinessError).code;
let message = (error as BusinessError).message;
console.error(`getStringByNameSync failed, error code: ${code}, message: ${message}.`);
} }
``` ```
...@@ -592,6 +617,8 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco ...@@ -592,6 +617,8 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco
**Example (stage)** **Example (stage)**
```ts ```ts
import { BusinessError } from '@ohos.base';
try { try {
this.context.resourceManager.getStringValue($r('app.string.test').id, (error, value) => { this.context.resourceManager.getStringValue($r('app.string.test').id, (error, value) => {
if (error != null) { if (error != null) {
...@@ -601,7 +628,9 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco ...@@ -601,7 +628,9 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco
} }
}); });
} catch (error) { } catch (error) {
console.error(`callback getStringValue failed, error code: ${error.code}, message: ${error.message}.`); let code = (error as BusinessError).code;
let message = (error as BusinessError).message;
console.error(`callback getStringValue failed, error code: ${code}, message: ${message}.`);
} }
``` ```
...@@ -646,7 +675,9 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco ...@@ -646,7 +675,9 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco
console.log("getStringValue promise error is " + error); console.log("getStringValue promise error is " + error);
}); });
} catch (error) { } catch (error) {
console.error(`promise getStringValue failed, error code: ${error.code}, message: ${error.message}.`); let code = (error as BusinessError).code;
let message = (error as BusinessError).message;
console.error(`promise getStringValue failed, error code: ${code}, message: ${message}.`);
} }
``` ```
...@@ -680,6 +711,7 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco ...@@ -680,6 +711,7 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco
**Example** **Example**
```ts ```ts
import resourceManager from '@ohos.resourceManager'; import resourceManager from '@ohos.resourceManager';
import { BusinessError } from '@ohos.base';
let resource: resourceManager.Resource = { let resource: resourceManager.Resource = {
bundleName: "com.example.myapplication", bundleName: "com.example.myapplication",
...@@ -695,7 +727,9 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco ...@@ -695,7 +727,9 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco
} }
}); });
} catch (error) { } catch (error) {
console.error(`callback getStringValue failed, error code: ${error.code}, message: ${error.message}.`); let code = (error as BusinessError).code;
let message = (error as BusinessError).message;
console.error(`callback getStringValue failed, error code: ${code}, message: ${message}.`);
} }
``` ```
...@@ -748,7 +782,9 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco ...@@ -748,7 +782,9 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco
console.log("getStringValue promise error is " + error); console.log("getStringValue promise error is " + error);
}); });
} catch (error) { } catch (error) {
console.error(`promise getStringValue failed, error code: ${error.code}, message: ${error.message}.`); let code = (error as BusinessError).code;
let message = (error as BusinessError).message;
console.error(`promise getStringValue failed, error code: ${code}, message: ${message}.`);
} }
``` ```
...@@ -779,6 +815,8 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco ...@@ -779,6 +815,8 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco
**Example** **Example**
```ts ```ts
import { BusinessError } from '@ohos.base';
try { try {
this.context.resourceManager.getStringByName("test", (error, value) => { this.context.resourceManager.getStringByName("test", (error, value) => {
if (error != null) { if (error != null) {
...@@ -788,7 +826,9 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco ...@@ -788,7 +826,9 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco
} }
}); });
} catch (error) { } catch (error) {
console.error(`callback getStringByName failed, error code: ${error.code}, message: ${error.message}.`); let code = (error as BusinessError).code;
let message = (error as BusinessError).message;
console.error(`callback getStringByName failed, error code: ${code}, message: ${message}.`);
} }
``` ```
...@@ -833,7 +873,9 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco ...@@ -833,7 +873,9 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco
console.log("getStringByName promise error is " + error); console.log("getStringByName promise error is " + error);
}); });
} catch (error) { } catch (error) {
console.error(`promise getStringByName failed, error code: ${error.code}, message: ${error.message}.`); let code = (error as BusinessError).code;
let message = (error as BusinessError).message;
console.error(`promise getStringByName failed, error code: ${code}, message: ${message}.`);
} }
``` ```
...@@ -869,10 +911,14 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco ...@@ -869,10 +911,14 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco
**Example** **Example**
```ts ```ts
import { BusinessError } from '@ohos.base';
try { try {
this.context.resourceManager.getStringArrayValueSync($r('app.strarray.test').id); this.context.resourceManager.getStringArrayValueSync($r('app.strarray.test').id);
} catch (error) { } catch (error) {
console.error(`getStringArrayValueSync failed, error code: ${error.code}, message: ${error.message}.`); let code = (error as BusinessError).code;
let message = (error as BusinessError).message;
console.error(`getStringArrayValueSync failed, error code: ${code}, message: ${message}.`);
} }
``` ```
...@@ -911,6 +957,7 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco ...@@ -911,6 +957,7 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco
**Example** **Example**
```ts ```ts
import resourceManager from '@ohos.resourceManager'; import resourceManager from '@ohos.resourceManager';
import { BusinessError } from '@ohos.base';
let resource: resourceManager.Resource = { let resource: resourceManager.Resource = {
bundleName: "com.example.myapplication", bundleName: "com.example.myapplication",
...@@ -920,7 +967,9 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco ...@@ -920,7 +967,9 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco
try { try {
this.context.resourceManager.getStringArrayValueSync(resource); this.context.resourceManager.getStringArrayValueSync(resource);
} catch (error) { } catch (error) {
console.error(`getStringArrayValueSync failed, error code: ${error.code}, message: ${error.message}.`); let code = (error as BusinessError).code;
let message = (error as BusinessError).message;
console.error(`getStringArrayValueSync failed, error code: ${code}, message: ${message}.`);
} }
``` ```
...@@ -959,7 +1008,9 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco ...@@ -959,7 +1008,9 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco
try { try {
this.context.resourceManager.getStringArrayByNameSync("test"); this.context.resourceManager.getStringArrayByNameSync("test");
} catch (error) { } catch (error) {
console.error(`getStringArrayByNameSync failed, error code: ${error.code}, message: ${error.message}.`); let code = (error as BusinessError).code;
let message = (error as BusinessError).message;
console.error(`getStringArrayByNameSync failed, error code: ${code}, message: ${message}.`);
} }
``` ```
...@@ -990,6 +1041,8 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco ...@@ -990,6 +1041,8 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco
**Example** **Example**
```ts ```ts
import { BusinessError } from '@ohos.base';
try { try {
this.context.resourceManager.getStringArrayValue($r('app.strarray.test').id, (error, value) => { this.context.resourceManager.getStringArrayValue($r('app.strarray.test').id, (error, value) => {
if (error != null) { if (error != null) {
...@@ -999,7 +1052,9 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco ...@@ -999,7 +1052,9 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco
} }
}); });
} catch (error) { } catch (error) {
console.error(`callback getStringArrayValue failed, error code: ${error.code}, message: ${error.message}.`); let code = (error as BusinessError).code;
let message = (error as BusinessError).message;
console.error(`callback getStringArrayValue failed, error code: ${code}, message: ${message}.`);
} }
``` ```
...@@ -1044,7 +1099,9 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco ...@@ -1044,7 +1099,9 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco
console.log("getStringArrayValue promise error is " + error); console.log("getStringArrayValue promise error is " + error);
}); });
} catch (error) { } catch (error) {
console.error(`promise getStringArrayValue failed, error code: ${error.code}, message: ${error.message}.`); let code = (error as BusinessError).code;
let message = (error as BusinessError).message;
console.error(`promise getStringArrayValue failed, error code: ${code}, message: ${message}.`);
} }
``` ```
...@@ -1078,6 +1135,7 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco ...@@ -1078,6 +1135,7 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco
**Example** **Example**
```ts ```ts
import resourceManager from '@ohos.resourceManager'; import resourceManager from '@ohos.resourceManager';
import { BusinessError } from '@ohos.base';
let resource: resourceManager.Resource = { let resource: resourceManager.Resource = {
bundleName: "com.example.myapplication", bundleName: "com.example.myapplication",
...@@ -1093,7 +1151,9 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco ...@@ -1093,7 +1151,9 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco
} }
}); });
} catch (error) { } catch (error) {
console.error(`callback getStringArrayValue failed, error code: ${error.code}, message: ${error.message}.`); let code = (error as BusinessError).code;
let message = (error as BusinessError).message;
console.error(`callback getStringArrayValue failed, error code: ${code}, message: ${message}.`);
} }
``` ```
...@@ -1146,7 +1206,9 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco ...@@ -1146,7 +1206,9 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco
console.log("getStringArray promise error is " + error); console.log("getStringArray promise error is " + error);
}); });
} catch (error) { } catch (error) {
console.error(`promise getStringArrayValue failed, error code: ${error.code}, message: ${error.message}.`); let code = (error as BusinessError).code;
let message = (error as BusinessError).message;
console.error(`promise getStringArrayValue failed, error code: ${code}, message: ${message}.`);
} }
``` ```
...@@ -1177,6 +1239,8 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco ...@@ -1177,6 +1239,8 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco
**Example** **Example**
```ts ```ts
import { BusinessError } from '@ohos.base';
try { try {
this.context.resourceManager.getStringArrayByName("test", (error, value) => { this.context.resourceManager.getStringArrayByName("test", (error, value) => {
if (error != null) { if (error != null) {
...@@ -1186,7 +1250,9 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco ...@@ -1186,7 +1250,9 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco
} }
}); });
} catch (error) { } catch (error) {
console.error(`callback getStringArrayByName failed, error code: ${error.code}, message: ${error.message}.`); let code = (error as BusinessError).code;
let message = (error as BusinessError).message;
console.error(`callback getStringArrayByName failed, error code: ${code}, message: ${message}.`);
} }
``` ```
...@@ -1231,7 +1297,9 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco ...@@ -1231,7 +1297,9 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco
console.log("getStringArrayByName promise error is " + error); console.log("getStringArrayByName promise error is " + error);
}); });
} catch (error) { } catch (error) {
console.error(`promise getStringArrayByName failed, error code: ${error.code}, message: ${error.message}.`); let code = (error as BusinessError).code;
let message = (error as BusinessError).message;
console.error(`promise getStringArrayByName failed, error code: ${code}, message: ${message}.`);
} }
``` ```
...@@ -1268,10 +1336,14 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco ...@@ -1268,10 +1336,14 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco
**Example** **Example**
```ts ```ts
import { BusinessError } from '@ohos.base';
try { try {
this.context.resourceManager.getPluralStringValueSync($r('app.plural.test').id, 1); this.context.resourceManager.getPluralStringValueSync($r('app.plural.test').id, 1);
} catch (error) { } catch (error) {
console.error(`getPluralStringValueSync failed, error code: ${error.code}, message: ${error.message}.`); let code = (error as BusinessError).code;
let message = (error as BusinessError).message;
console.error(`getPluralStringValueSync failed, error code: ${code}, message: ${message}.`);
} }
``` ```
...@@ -1311,6 +1383,7 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco ...@@ -1311,6 +1383,7 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco
**Example** **Example**
```ts ```ts
import resourceManager from '@ohos.resourceManager'; import resourceManager from '@ohos.resourceManager';
import { BusinessError } from '@ohos.base';
let resource: resourceManager.Resource = { let resource: resourceManager.Resource = {
bundleName: "com.example.myapplication", bundleName: "com.example.myapplication",
...@@ -1320,7 +1393,9 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco ...@@ -1320,7 +1393,9 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco
try { try {
this.context.resourceManager.getPluralStringValueSync(resource, 1); this.context.resourceManager.getPluralStringValueSync(resource, 1);
} catch (error) { } catch (error) {
console.error(`getPluralStringValueSync failed, error code: ${error.code}, message: ${error.message}.`); let code = (error as BusinessError).code;
let message = (error as BusinessError).message;
console.error(`getPluralStringValueSync failed, error code: ${code}, message: ${message}.`);
} }
``` ```
...@@ -1357,10 +1432,14 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco ...@@ -1357,10 +1432,14 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco
**Example** **Example**
```ts ```ts
import { BusinessError } from '@ohos.base';
try { try {
this.context.resourceManager.getPluralStringByNameSync("test", 1); this.context.resourceManager.getPluralStringByNameSync("test", 1);
} catch (error) { } catch (error) {
console.error(`getPluralStringByNameSync failed, error code: ${error.code}, message: ${error.message}.`); let code = (error as BusinessError).code;
let message = (error as BusinessError).message;
console.error(`getPluralStringByNameSync failed, error code: ${code}, message: ${message}.`);
} }
``` ```
...@@ -1392,6 +1471,8 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco ...@@ -1392,6 +1471,8 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco
**Example** **Example**
```ts ```ts
import { BusinessError } from '@ohos.base';
try { try {
this.context.resourceManager.getPluralStringValue($r("app.plural.test").id, 1, (error, value) => { this.context.resourceManager.getPluralStringValue($r("app.plural.test").id, 1, (error, value) => {
if (error != null) { if (error != null) {
...@@ -1401,7 +1482,9 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco ...@@ -1401,7 +1482,9 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco
} }
}); });
} catch (error) { } catch (error) {
console.error(`callback getPluralStringValue failed, error code: ${error.code}, message: ${error.message}.`); let code = (error as BusinessError).code;
let message = (error as BusinessError).message;
console.error(`callback getPluralStringValue failed, error code: ${code}, message: ${message}.`);
} }
``` ```
...@@ -1447,7 +1530,9 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco ...@@ -1447,7 +1530,9 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco
console.log("getPluralStringValue promise error is " + error); console.log("getPluralStringValue promise error is " + error);
}); });
} catch (error) { } catch (error) {
console.error(`promise getPluralStringValue failed, error code: ${error.code}, message: ${error.message}.`); let code = (error as BusinessError).code;
let message = (error as BusinessError).message;
console.error(`promise getPluralStringValue failed, error code: ${code}, message: ${message}.`);
} }
``` ```
...@@ -1482,6 +1567,7 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco ...@@ -1482,6 +1567,7 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco
**Example** **Example**
```ts ```ts
import resourceManager from '@ohos.resourceManager'; import resourceManager from '@ohos.resourceManager';
import { BusinessError } from '@ohos.base';
let resource: resourceManager.Resource = { let resource: resourceManager.Resource = {
bundleName: "com.example.myapplication", bundleName: "com.example.myapplication",
...@@ -1497,7 +1583,9 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco ...@@ -1497,7 +1583,9 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco
} }
}); });
} catch (error) { } catch (error) {
console.error(`callback getPluralStringValue failed, error code: ${error.code}, message: ${error.message}.`); let code = (error as BusinessError).code;
let message = (error as BusinessError).message;
console.error(`callback getPluralStringValue failed, error code: ${code}, message: ${message}.`);
} }
``` ```
...@@ -1551,7 +1639,9 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco ...@@ -1551,7 +1639,9 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco
console.log("getPluralStringValue promise error is " + error); console.log("getPluralStringValue promise error is " + error);
}); });
} catch (error) { } catch (error) {
console.error(`promise getPluralStringValue failed, error code: ${error.code}, message: ${error.message}.`); let code = (error as BusinessError).code;
let message = (error as BusinessError).message;
console.error(`promise getPluralStringValue failed, error code: ${code}, message: ${message}.`);
} }
``` ```
...@@ -1583,6 +1673,8 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco ...@@ -1583,6 +1673,8 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco
**Example** **Example**
```ts ```ts
import { BusinessError } from '@ohos.base';
try { try {
this.context.resourceManager.getPluralStringByName("test", 1, (error, value) => { this.context.resourceManager.getPluralStringByName("test", 1, (error, value) => {
if (error != null) { if (error != null) {
...@@ -1592,7 +1684,9 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco ...@@ -1592,7 +1684,9 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco
} }
}); });
} catch (error) { } catch (error) {
console.error(`callback getPluralStringByName failed, error code: ${error.code}, message: ${error.message}.`); let code = (error as BusinessError).code;
let message = (error as BusinessError).message;
console.error(`callback getPluralStringByName failed, error code: ${code}, message: ${message}.`);
} }
``` ```
...@@ -1638,7 +1732,9 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco ...@@ -1638,7 +1732,9 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco
console.log("getPluralStringByName promise error is " + error); console.log("getPluralStringByName promise error is " + error);
}); });
} catch (error) { } catch (error) {
console.error(`promise getPluralStringByName failed, error code: ${error.code}, message: ${error.message}.`); let code = (error as BusinessError).code;
let message = (error as BusinessError).message;
console.error(`promise getPluralStringByName failed, error code: ${code}, message: ${message}.`);
} }
``` ```
...@@ -1674,16 +1770,22 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco ...@@ -1674,16 +1770,22 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco
**Example** **Example**
```ts ```ts
import { BusinessError } from '@ohos.base';
try { try {
this.context.resourceManager.getMediaContentSync($r('app.media.test').id); // Default screen density this.context.resourceManager.getMediaContentSync($r('app.media.test').id); // Default screen density
} catch (error) { } catch (error) {
console.error(`getMediaContentSync failed, error code: ${error.code}, message: ${error.message}.`); let code = (error as BusinessError).code;
let message = (error as BusinessError).message;
console.error(`getMediaContentSync failed, error code: ${code}, message: ${message}.`);
} }
try { try {
this.context.resourceManager.getMediaContentSync($r('app.media.test').id, 120); // Specified screen density this.context.resourceManager.getMediaContentSync($r('app.media.test').id, 120); // Specified screen density
} catch (error) { } catch (error) {
console.error(`getMediaContentSync failed, error code: ${error.code}, message: ${error.message}.`); let code = (error as BusinessError).code;
let message = (error as BusinessError).message;
console.error(`getMediaContentSync failed, error code: ${code}, message: ${message}.`);
} }
``` ```
...@@ -1722,6 +1824,7 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco ...@@ -1722,6 +1824,7 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco
**Example** **Example**
```ts ```ts
import resourceManager from '@ohos.resourceManager'; import resourceManager from '@ohos.resourceManager';
import { BusinessError } from '@ohos.base';
let resource: resourceManager.Resource = { let resource: resourceManager.Resource = {
bundleName: "com.example.myapplication", bundleName: "com.example.myapplication",
...@@ -1731,13 +1834,17 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco ...@@ -1731,13 +1834,17 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco
try { try {
this.context.resourceManager.getMediaContentSync(resource); // Default screen density this.context.resourceManager.getMediaContentSync(resource); // Default screen density
} catch (error) { } catch (error) {
console.error(`getMediaContentSync failed, error code: ${error.code}, message: ${error.message}.`); let code = (error as BusinessError).code;
let message = (error as BusinessError).message;
console.error(`getMediaContentSync failed, error code: ${code}, message: ${message}.`);
} }
try { try {
this.context.resourceManager.getMediaContentSync(resource, 120); // Specified screen density this.context.resourceManager.getMediaContentSync(resource, 120); // Specified screen density
} catch (error) { } catch (error) {
console.error(`getMediaContentSync failed, error code: ${error.code}, message: ${error.message}.`); let code = (error as BusinessError).code;
let message = (error as BusinessError).message;
console.error(`getMediaContentSync failed, error code: ${code}, message: ${message}.`);
} }
``` ```
...@@ -1773,16 +1880,22 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco ...@@ -1773,16 +1880,22 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco
**Example** **Example**
```ts ```ts
import { BusinessError } from '@ohos.base';
try { try {
this.context.resourceManager.getMediaByNameSync("test"); // Default screen density this.context.resourceManager.getMediaByNameSync("test"); // Default screen density
} catch (error) { } catch (error) {
console.error(`getMediaByNameSync failed, error code: ${error.code}, message: ${error.message}.`); let code = (error as BusinessError).code;
let message = (error as BusinessError).message;
console.error(`getMediaByNameSync failed, error code: ${code}, message: ${message}.`);
} }
try { try {
this.context.resourceManager.getMediaByNameSync("test", 120); // Specified screen density this.context.resourceManager.getMediaByNameSync("test", 120); // Specified screen density
} catch (error) { } catch (error) {
console.error(`getMediaByNameSync failed, error code: ${error.code}, message: ${error.message}.`); let code = (error as BusinessError).code;
let message = (error as BusinessError).message;
console.error(`getMediaByNameSync failed, error code: ${code}, message: ${message}.`);
} }
``` ```
...@@ -1812,6 +1925,8 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco ...@@ -1812,6 +1925,8 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco
**Example** **Example**
```ts ```ts
import { BusinessError } from '@ohos.base';
try { try {
this.context.resourceManager.getMediaContent($r('app.media.test').id, (error, value) => { this.context.resourceManager.getMediaContent($r('app.media.test').id, (error, value) => {
if (error != null) { if (error != null) {
...@@ -1821,7 +1936,9 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco ...@@ -1821,7 +1936,9 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco
} }
}); });
} catch (error) { } catch (error) {
console.error(`callback getMediaContent failed, error code: ${error.code}, message: ${error.message}.`); let code = (error as BusinessError).code;
let message = (error as BusinessError).message;
console.error(`callback getMediaContent failed, error code: ${code}, message: ${message}.`);
} }
``` ```
...@@ -1852,6 +1969,8 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco ...@@ -1852,6 +1969,8 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco
**Example** **Example**
```ts ```ts
import { BusinessError } from '@ohos.base';
try { try {
this.context.resourceManager.getMediaContent($r('app.media.test').id, 120, (error, value) => { this.context.resourceManager.getMediaContent($r('app.media.test').id, 120, (error, value) => {
if (error != null) { if (error != null) {
...@@ -1861,7 +1980,9 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco ...@@ -1861,7 +1980,9 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco
} }
}); });
} catch (error) { } catch (error) {
console.error(`callback getMediaContent failed, error code: ${error.code}, message: ${error.message}.`); let code = (error as BusinessError).code;
let message = (error as BusinessError).message;
console.error(`callback getMediaContent failed, error code: ${code}, message: ${message}.`);
} }
``` ```
...@@ -1905,7 +2026,9 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco ...@@ -1905,7 +2026,9 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco
console.log("getMediaContent promise error is " + error); console.log("getMediaContent promise error is " + error);
}); });
} catch (error) { } catch (error) {
console.error(`promise getMediaContent failed, error code: ${error.code}, message: ${error.message}.`); let code = (error as BusinessError).code;
let message = (error as BusinessError).message;
console.error(`promise getMediaContent failed, error code: ${code}, message: ${message}.`);
} }
``` ```
...@@ -1950,7 +2073,9 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco ...@@ -1950,7 +2073,9 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco
console.error(`promise getMediaContent failed, error code: ${error.code}, message: ${error.message}.`); console.error(`promise getMediaContent failed, error code: ${error.code}, message: ${error.message}.`);
}); });
} catch (error) { } catch (error) {
console.error(`promise getMediaContent failed, error code: ${error.code}, message: ${error.message}.`); let code = (error as BusinessError).code;
let message = (error as BusinessError).message;
console.error(`promise getMediaContent failed, error code: ${code}, message: ${message}.`);
} }
``` ```
...@@ -1983,6 +2108,7 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco ...@@ -1983,6 +2108,7 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco
**Example** **Example**
```ts ```ts
import resourceManager from '@ohos.resourceManager'; import resourceManager from '@ohos.resourceManager';
import { BusinessError } from '@ohos.base';
let resource: resourceManager.Resource = { let resource: resourceManager.Resource = {
bundleName: "com.example.myapplication", bundleName: "com.example.myapplication",
...@@ -1998,7 +2124,9 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco ...@@ -1998,7 +2124,9 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco
} }
}); });
} catch (error) { } catch (error) {
console.error(`callback getMediaContent failed, error code: ${error.code}, message: ${error.message}.`); let code = (error as BusinessError).code;
let message = (error as BusinessError).message;
console.error(`callback getMediaContent failed, error code: ${code}, message: ${message}.`);
} }
``` ```
...@@ -2032,6 +2160,7 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco ...@@ -2032,6 +2160,7 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco
**Example** **Example**
```ts ```ts
import resourceManager from '@ohos.resourceManager'; import resourceManager from '@ohos.resourceManager';
import { BusinessError } from '@ohos.base';
let resource: resourceManager.Resource = { let resource: resourceManager.Resource = {
bundleName: "com.example.myapplication", bundleName: "com.example.myapplication",
...@@ -2047,7 +2176,9 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco ...@@ -2047,7 +2176,9 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco
} }
}); });
} catch (error) { } catch (error) {
console.error(`callback getMediaContent failed, error code: ${error.code}, message: ${error.message}.`); let code = (error as BusinessError).code;
let message = (error as BusinessError).message;
console.error(`callback getMediaContent failed, error code: ${code}, message: ${message}.`);
} }
``` ```
...@@ -2099,7 +2230,9 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco ...@@ -2099,7 +2230,9 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco
console.log("getMediaContent promise error is " + error); console.log("getMediaContent promise error is " + error);
}); });
} catch (error) { } catch (error) {
console.error(`promise getMediaContent failed, error code: ${error.code}, message: ${error.message}.`); let code = (error as BusinessError).code;
let message = (error as BusinessError).message;
console.error(`promise getMediaContent failed, error code: ${code}, message: ${message}.`);
} }
``` ```
...@@ -2152,7 +2285,9 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco ...@@ -2152,7 +2285,9 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco
console.error(`promise getMediaContent failed, error code: ${error.code}, message: ${error.message}.`); console.error(`promise getMediaContent failed, error code: ${error.code}, message: ${error.message}.`);
}); });
} catch (error) { } catch (error) {
console.error(`promise getMediaContent failed, error code: ${error.code}, message: ${error.message}.`); let code = (error as BusinessError).code;
let message = (error as BusinessError).message;
console.error(`promise getMediaContent failed, error code: ${code}, message: ${message}.`);
} }
``` ```
...@@ -2182,6 +2317,8 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco ...@@ -2182,6 +2317,8 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco
**Example** **Example**
```ts ```ts
import { BusinessError } from '@ohos.base';
try { try {
this.context.resourceManager.getMediaByName("test", (error, value) => { this.context.resourceManager.getMediaByName("test", (error, value) => {
if (error != null) { if (error != null) {
...@@ -2191,7 +2328,9 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco ...@@ -2191,7 +2328,9 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco
} }
}); });
} catch (error) { } catch (error) {
console.error(`callback getMediaByName failed, error code: ${error.code}, message: ${error.message}.`); let code = (error as BusinessError).code;
let message = (error as BusinessError).message;
console.error(`callback getMediaByName failed, error code: ${code}, message: ${message}.`);
} }
``` ```
...@@ -2222,6 +2361,8 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco ...@@ -2222,6 +2361,8 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco
**Example** **Example**
```ts ```ts
import { BusinessError } from '@ohos.base';
try { try {
this.context.resourceManager.getMediaByName("test", 120, (error, value) => { this.context.resourceManager.getMediaByName("test", 120, (error, value) => {
if (error != null) { if (error != null) {
...@@ -2231,7 +2372,9 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco ...@@ -2231,7 +2372,9 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco
} }
}); });
} catch (error) { } catch (error) {
console.error(`callback getMediaByName failed, error code: ${error.code}, message: ${error.message}.`); let code = (error as BusinessError).code;
let message = (error as BusinessError).message;
console.error(`callback getMediaByName failed, error code: ${code}, message: ${message}.`);
} }
``` ```
...@@ -2275,7 +2418,9 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco ...@@ -2275,7 +2418,9 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco
console.log("getMediaByName promise error is " + error); console.log("getMediaByName promise error is " + error);
}); });
} catch (error) { } catch (error) {
console.error(`promise getMediaByName failed, error code: ${error.code}, message: ${error.message}.`) let code = (error as BusinessError).code;
let message = (error as BusinessError).message;
console.error(`promise getMediaByName failed, error code: ${code}, message: ${message}.`);
} }
``` ```
...@@ -2320,7 +2465,9 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco ...@@ -2320,7 +2465,9 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco
console.error(`promise getMediaByName failed, error code: ${error.code}, message: ${error.message}.`); console.error(`promise getMediaByName failed, error code: ${error.code}, message: ${error.message}.`);
}); });
} catch (error) { } catch (error) {
console.error(`promise getMediaByName failed, error code: ${error.code}, message: ${error.message}.`); let code = (error as BusinessError).code;
let message = (error as BusinessError).message;
console.error(`promise getMediaByName failed, error code: ${code}, message: ${message}.`);
} }
``` ```
...@@ -2356,16 +2503,22 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco ...@@ -2356,16 +2503,22 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco
**Example** **Example**
```ts ```ts
import { BusinessError } from '@ohos.base';
try { try {
this.context.resourceManager.getMediaContentBase64Sync($r('app.media.test').id); // Default screen density this.context.resourceManager.getMediaContentBase64Sync($r('app.media.test').id); // Default screen density
} catch (error) { } catch (error) {
console.error(`getMediaContentBase64Sync failed, error code: ${error.code}, message: ${error.message}.`); let code = (error as BusinessError).code;
let message = (error as BusinessError).message;
console.error(`getMediaContentBase64Sync failed, error code: ${code}, message: ${message}.`);
} }
try { try {
this.context.resourceManager.getMediaContentBase64Sync($r('app.media.test').id, 120); // Specified screen density this.context.resourceManager.getMediaContentBase64Sync($r('app.media.test').id, 120); // Specified screen density
} catch (error) { } catch (error) {
console.error(`getMediaContentBase64Sync failed, error code: ${error.code}, message: ${error.message}.`); let code = (error as BusinessError).code;
let message = (error as BusinessError).message;
console.error(`getMediaContentBase64Sync failed, error code: ${code}, message: ${message}.`);
} }
``` ```
...@@ -2404,6 +2557,7 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco ...@@ -2404,6 +2557,7 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco
**Example** **Example**
```ts ```ts
import resourceManager from '@ohos.resourceManager'; import resourceManager from '@ohos.resourceManager';
import { BusinessError } from '@ohos.base';
let resource: resourceManager.Resource = { let resource: resourceManager.Resource = {
bundleName: "com.example.myapplication", bundleName: "com.example.myapplication",
...@@ -2413,13 +2567,17 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco ...@@ -2413,13 +2567,17 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco
try { try {
this.context.resourceManager.getMediaContentBase64Sync(resource); // Default screen density this.context.resourceManager.getMediaContentBase64Sync(resource); // Default screen density
} catch (error) { } catch (error) {
console.error(`getMediaContentBase64Sync failed, error code: ${error.code}, message: ${error.message}.`); let code = (error as BusinessError).code;
let message = (error as BusinessError).message;
console.error(`getMediaContentBase64Sync failed, error code: ${code}, message: ${message}.`);
} }
try { try {
this.context.resourceManager.getMediaContentBase64Sync(resource, 120); // Specified screen density this.context.resourceManager.getMediaContentBase64Sync(resource, 120); // Specified screen density
} catch (error) { } catch (error) {
console.error(`getMediaContentBase64Sync failed, error code: ${error.code}, message: ${error.message}.`); let code = (error as BusinessError).code;
let message = (error as BusinessError).message;
console.error(`getMediaContentBase64Sync failed, error code: ${code}, message: ${message}.`);
} }
``` ```
...@@ -2455,16 +2613,22 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco ...@@ -2455,16 +2613,22 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco
**Example** **Example**
```ts ```ts
import { BusinessError } from '@ohos.base';
try { try {
this.context.resourceManager.getMediaBase64ByNameSync("test"); // Default screen density this.context.resourceManager.getMediaBase64ByNameSync("test"); // Default screen density
} catch (error) { } catch (error) {
console.error(`getMediaBase64ByNameSync failed, error code: ${error.code}, message: ${error.message}.`); let code = (error as BusinessError).code;
let message = (error as BusinessError).message;
console.error(`getMediaBase64ByNameSync failed, error code: ${code}, message: ${message}.`);
} }
try { try {
this.context.resourceManager.getMediaBase64ByNameSync("test", 120); // Specified screen density this.context.resourceManager.getMediaBase64ByNameSync("test", 120); // Specified screen density
} catch (error) { } catch (error) {
console.error(`getMediaBase64ByNameSync failed, error code: ${error.code}, message: ${error.message}.`); let code = (error as BusinessError).code;
let message = (error as BusinessError).message;
console.error(`getMediaBase64ByNameSync failed, error code: ${code}, message: ${message}.`);
} }
``` ```
...@@ -2494,6 +2658,8 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco ...@@ -2494,6 +2658,8 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco
**Example** **Example**
```ts ```ts
import { BusinessError } from '@ohos.base';
try { try {
this.context.resourceManager.getMediaContentBase64($r('app.media.test').id, (error, value) => { this.context.resourceManager.getMediaContentBase64($r('app.media.test').id, (error, value) => {
if (error != null) { if (error != null) {
...@@ -2503,7 +2669,9 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco ...@@ -2503,7 +2669,9 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco
} }
}); });
} catch (error) { } catch (error) {
console.error(`callback getMediaContentBase64 failed, error code: ${error.code}, message: ${error.message}.`); let code = (error as BusinessError).code;
let message = (error as BusinessError).message;
console.error(`callback getMediaContentBase64 failed, error code: ${code}, message: ${message}.`);
} }
``` ```
...@@ -2534,6 +2702,8 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco ...@@ -2534,6 +2702,8 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco
**Example** **Example**
```ts ```ts
import { BusinessError } from '@ohos.base';
try { try {
this.context.resourceManager.getMediaContentBase64($r('app.media.test').id, 120, (error, value) => { this.context.resourceManager.getMediaContentBase64($r('app.media.test').id, 120, (error, value) => {
if (error != null) { if (error != null) {
...@@ -2543,7 +2713,9 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco ...@@ -2543,7 +2713,9 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco
} }
}); });
} catch (error) { } catch (error) {
console.error(`callback getMediaContentBase64 failed, error code: ${error.code}, message: ${error.message}.`); let code = (error as BusinessError).code;
let message = (error as BusinessError).message;
console.error(`callback getMediaContentBase64 failed, error code: ${code}, message: ${message}.`);
} }
``` ```
...@@ -2587,7 +2759,9 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco ...@@ -2587,7 +2759,9 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco
console.log("getMediaContentBase64 promise error is " + error); console.log("getMediaContentBase64 promise error is " + error);
}); });
} catch (error) { } catch (error) {
console.error(`promise getMediaContentBase64 failed, error code: ${error.code}, message: ${error.message}.`); let code = (error as BusinessError).code;
let message = (error as BusinessError).message;
console.error(`promise getMediaContentBase64 failed, error code: ${code}, message: ${message}.`);
} }
``` ```
...@@ -2632,7 +2806,9 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco ...@@ -2632,7 +2806,9 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco
console.error(`promise getMediaContentBase64 failed, error code: ${error.code}, message: ${error.message}.`); console.error(`promise getMediaContentBase64 failed, error code: ${error.code}, message: ${error.message}.`);
}); });
} catch (error) { } catch (error) {
console.error(`promise getMediaContentBase64 failed, error code: ${error.code}, message: ${error.message}.`); let code = (error as BusinessError).code;
let message = (error as BusinessError).message;
console.error(`promise getMediaContentBase64 failed, error code: ${code}, message: ${message}.`);
} }
``` ```
...@@ -2665,6 +2841,7 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco ...@@ -2665,6 +2841,7 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco
**Example** **Example**
```ts ```ts
import resourceManager from '@ohos.resourceManager'; import resourceManager from '@ohos.resourceManager';
import { BusinessError } from '@ohos.base';
let resource: resourceManager.Resource = { let resource: resourceManager.Resource = {
bundleName: "com.example.myapplication", bundleName: "com.example.myapplication",
...@@ -2680,7 +2857,9 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco ...@@ -2680,7 +2857,9 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco
} }
}); });
} catch (error) { } catch (error) {
console.error(`callback getMediaContentBase64 failed, error code: ${error.code}, message: ${error.message}.`); let code = (error as BusinessError).code;
let message = (error as BusinessError).message;
console.error(`callback getMediaContentBase64 failed, error code: ${code}, message: ${message}.`);
} }
``` ```
...@@ -2714,6 +2893,7 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco ...@@ -2714,6 +2893,7 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco
**Example** **Example**
```ts ```ts
import resourceManager from '@ohos.resourceManager'; import resourceManager from '@ohos.resourceManager';
import { BusinessError } from '@ohos.base';
let resource: resourceManager.Resource = { let resource: resourceManager.Resource = {
bundleName: "com.example.myapplication", bundleName: "com.example.myapplication",
...@@ -2729,7 +2909,9 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco ...@@ -2729,7 +2909,9 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco
} }
}); });
} catch (error) { } catch (error) {
console.error(`callback getMediaContentBase64 failed, error code: ${error.code}, message: ${error.message}.`); let code = (error as BusinessError).code;
let message = (error as BusinessError).message;
console.error(`callback getMediaContentBase64 failed, error code: ${code}, message: ${message}.`);
} }
``` ```
...@@ -2781,7 +2963,9 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco ...@@ -2781,7 +2963,9 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco
console.log("getMediaContentBase64 promise error is " + error); console.log("getMediaContentBase64 promise error is " + error);
}); });
} catch (error) { } catch (error) {
console.error(`promise getMediaContentBase64 failed, error code: ${error.code}, message: ${error.message}.`); let code = (error as BusinessError).code;
let message = (error as BusinessError).message;
console.error(`promise getMediaContentBase64 failed, error code: ${code}, message: ${message}.`);
} }
``` ```
...@@ -2834,7 +3018,9 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco ...@@ -2834,7 +3018,9 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco
console.error(`promise getMediaContentBase64 failed, error code: ${error.code}, message: ${error.message}.`); console.error(`promise getMediaContentBase64 failed, error code: ${error.code}, message: ${error.message}.`);
}); });
} catch (error) { } catch (error) {
console.error(`promise getMediaContentBase64 failed, error code: ${error.code}, message: ${error.message}.`); let code = (error as BusinessError).code;
let message = (error as BusinessError).message;
console.error(`promise getMediaContentBase64 failed, error code: ${code}, message: ${message}.`);
} }
``` ```
...@@ -2864,6 +3050,8 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco ...@@ -2864,6 +3050,8 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco
**Example** **Example**
```ts ```ts
import { BusinessError } from '@ohos.base';
try { try {
this.context.resourceManager.getMediaBase64ByName("test", (error, value) => { this.context.resourceManager.getMediaBase64ByName("test", (error, value) => {
if (error != null) { if (error != null) {
...@@ -2873,7 +3061,9 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco ...@@ -2873,7 +3061,9 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco
} }
}); });
} catch (error) { } catch (error) {
console.error(`callback getMediaBase64ByName failed, error code: ${error.code}, message: ${error.message}.`); let code = (error as BusinessError).code;
let message = (error as BusinessError).message;
console.error(`callback getMediaBase64ByName failed, error code: ${code}, message: ${message}.`);
} }
``` ```
...@@ -2904,6 +3094,8 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco ...@@ -2904,6 +3094,8 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco
**Example** **Example**
```ts ```ts
import { BusinessError } from '@ohos.base';
try { try {
this.context.resourceManager.getMediaBase64ByName("test", 120, (error, value) => { this.context.resourceManager.getMediaBase64ByName("test", 120, (error, value) => {
if (error != null) { if (error != null) {
...@@ -2913,7 +3105,9 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco ...@@ -2913,7 +3105,9 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco
} }
}); });
} catch (error) { } catch (error) {
console.error(`callback getMediaBase64ByName failed, error code: ${error.code}, message: ${error.message}.`); let code = (error as BusinessError).code;
let message = (error as BusinessError).message;
console.error(`callback getMediaBase64ByName failed, error code: ${code}, message: ${message}.`);
} }
``` ```
...@@ -2957,7 +3151,9 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco ...@@ -2957,7 +3151,9 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco
console.log("getMediaBase64ByName promise error is " + error); console.log("getMediaBase64ByName promise error is " + error);
}); });
} catch (error) { } catch (error) {
console.error(`promise getMediaBase64ByName failed, error code: ${error.code}, message: ${error.message}.`); let code = (error as BusinessError).code;
let message = (error as BusinessError).message;
console.error(`promise getMediaBase64ByName failed, error code: ${code}, message: ${message}.`);
} }
``` ```
...@@ -3002,7 +3198,9 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco ...@@ -3002,7 +3198,9 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco
console.error(`promise getMediaBase64ByName failed, error code: ${error.code}, message: ${error.message}.`); console.error(`promise getMediaBase64ByName failed, error code: ${error.code}, message: ${error.message}.`);
}); });
} catch (error) { } catch (error) {
console.error(`promise getMediaBase64ByName failed, error code: ${error.code}, message: ${error.message}.`); let code = (error as BusinessError).code;
let message = (error as BusinessError).message;
console.error(`promise getMediaBase64ByName failed, error code: ${code}, message: ${message}.`);
} }
``` ```
...@@ -3038,15 +3236,21 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco ...@@ -3038,15 +3236,21 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco
**Example** **Example**
```ts ```ts
import { BusinessError } from '@ohos.base';
try { try {
this.context.resourceManager.getDrawableDescriptor($r('app.media.icon').id); this.context.resourceManager.getDrawableDescriptor($r('app.media.icon').id);
} catch (error) { } catch (error) {
console.error(`getDrawableDescriptor failed, error code: ${error.code}, message: ${error.message}.`); let code = (error as BusinessError).code;
let message = (error as BusinessError).message;
console.error(`getDrawableDescriptor failed, error code: ${code}, message: ${message}.`);
} }
try { try {
this.context.resourceManager.getDrawableDescriptor($r('app.media.icon').id, 120); this.context.resourceManager.getDrawableDescriptor($r('app.media.icon').id, 120);
} catch (error) { } catch (error) {
console.error(`getDrawableDescriptor failed, error code: ${error.code}, message: ${error.message}.`); let code = (error as BusinessError).code;
let message = (error as BusinessError).message;
console.error(`getDrawableDescriptor failed, error code: ${code}, message: ${message}.`);
} }
``` ```
...@@ -3085,6 +3289,7 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco ...@@ -3085,6 +3289,7 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco
**Example** **Example**
```ts ```ts
import resourceManager from '@ohos.resourceManager'; import resourceManager from '@ohos.resourceManager';
import { BusinessError } from '@ohos.base';
let resource: resourceManager.Resource = { let resource: resourceManager.Resource = {
bundleName: "com.example.myapplication", bundleName: "com.example.myapplication",
...@@ -3094,12 +3299,16 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco ...@@ -3094,12 +3299,16 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco
try { try {
this.context.resourceManager.getDrawableDescriptor(resource); this.context.resourceManager.getDrawableDescriptor(resource);
} catch (error) { } catch (error) {
console.error(`getDrawableDescriptor failed, error code: ${error.code}, message: ${error.message}.`); let code = (error as BusinessError).code;
let message = (error as BusinessError).message;
console.error(`getDrawableDescriptor failed, error code: ${code}, message: ${message}.`);
} }
try { try {
this.context.resourceManager.getDrawableDescriptor(resource, 120); this.context.resourceManager.getDrawableDescriptor(resource, 120);
} catch (error) { } catch (error) {
console.error(`getDrawableDescriptor failed, error code: ${error.code}, message: ${error.message}.`); let code = (error as BusinessError).code;
let message = (error as BusinessError).message;
console.error(`getDrawableDescriptor failed, error code: ${code}, message: ${message}.`);
} }
``` ```
...@@ -3135,15 +3344,21 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco ...@@ -3135,15 +3344,21 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco
**Example** **Example**
```ts ```ts
import { BusinessError } from '@ohos.base';
try { try {
this.context.resourceManager.getDrawableDescriptorByName('icon'); this.context.resourceManager.getDrawableDescriptorByName('icon');
} catch (error) { } catch (error) {
console.error(`getDrawableDescriptorByName failed, error code: ${error.code}, message: ${error.message}.`); let code = (error as BusinessError).code;
let message = (error as BusinessError).message;
console.error(`getDrawableDescriptorByName failed, error code: ${code}, message: ${message}.`);
} }
try { try {
this.context.resourceManager.getDrawableDescriptorByName('icon', 120); this.context.resourceManager.getDrawableDescriptorByName('icon', 120);
} catch (error) { } catch (error) {
console.error(`getDrawableDescriptorByName failed, error code: ${error.code}, message: ${error.message}.`); let code = (error as BusinessError).code;
let message = (error as BusinessError).message;
console.error(`getDrawableDescriptorByName failed, error code: ${code}, message: ${message}.`);
} }
``` ```
...@@ -3179,10 +3394,14 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco ...@@ -3179,10 +3394,14 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco
**Example** **Example**
```ts ```ts
import { BusinessError } from '@ohos.base';
try { try {
this.context.resourceManager.getBoolean($r('app.boolean.boolean_test').id); this.context.resourceManager.getBoolean($r('app.boolean.boolean_test').id);
} catch (error) { } catch (error) {
console.error(`getBoolean failed, error code: ${error.code}, message: ${error.message}.`); let code = (error as BusinessError).code;
let message = (error as BusinessError).message;
console.error(`getBoolean failed, error code: ${code}, message: ${message}.`);
} }
``` ```
### getBoolean<sup>9+</sup> ### getBoolean<sup>9+</sup>
...@@ -3220,6 +3439,7 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco ...@@ -3220,6 +3439,7 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco
**Example** **Example**
```ts ```ts
import resourceManager from '@ohos.resourceManager'; import resourceManager from '@ohos.resourceManager';
import { BusinessError } from '@ohos.base';
let resource: resourceManager.Resource = { let resource: resourceManager.Resource = {
bundleName: "com.example.myapplication", bundleName: "com.example.myapplication",
...@@ -3229,7 +3449,9 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco ...@@ -3229,7 +3449,9 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco
try { try {
this.context.resourceManager.getBoolean(resource); this.context.resourceManager.getBoolean(resource);
} catch (error) { } catch (error) {
console.error(`getBoolean failed, error code: ${error.code}, message: ${error.message}.`); let code = (error as BusinessError).code;
let message = (error as BusinessError).message;
console.error(`getBoolean failed, error code: ${code}, message: ${message}.`);
} }
``` ```
...@@ -3265,10 +3487,14 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco ...@@ -3265,10 +3487,14 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco
**Example** **Example**
```ts ```ts
import { BusinessError } from '@ohos.base';
try { try {
this.context.resourceManager.getBooleanByName("boolean_test"); this.context.resourceManager.getBooleanByName("boolean_test");
} catch (error) { } catch (error) {
console.error(`getBooleanByName failed, error code: ${error.code}, message: ${error.message}.`); let code = (error as BusinessError).code;
let message = (error as BusinessError).message;
console.error(`getBooleanByName failed, error code: ${code}, message: ${message}.`);
} }
``` ```
...@@ -3304,16 +3530,22 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco ...@@ -3304,16 +3530,22 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco
**Example** **Example**
```ts ```ts
import { BusinessError } from '@ohos.base';
try { try {
this.context.resourceManager.getNumber($r('app.integer.integer_test').id); // integer refers to the original value. this.context.resourceManager.getNumber($r('app.integer.integer_test').id); // integer refers to the original value.
} catch (error) { } catch (error) {
console.error(`getNumber failed, error code: ${error.code}, message: ${error.message}.`); let code = (error as BusinessError).code;
let message = (error as BusinessError).message;
console.error(`getNumber failed, error code: ${code}, message: ${message}.`);
} }
try { try {
this.context.resourceManager.getNumber($r('app.float.float_test').id); // float refers to the actual pixel value. this.context.resourceManager.getNumber($r('app.float.float_test').id); // float refers to the actual pixel value.
} catch (error) { } catch (error) {
console.error(`getNumber failed, error code: ${error.code}, message: ${error.message}.`); let code = (error as BusinessError).code;
let message = (error as BusinessError).message;
console.error(`getNumber failed, error code: ${code}, message: ${message}.`);
} }
``` ```
...@@ -3352,6 +3584,7 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco ...@@ -3352,6 +3584,7 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco
**Example** **Example**
```ts ```ts
import resourceManager from '@ohos.resourceManager'; import resourceManager from '@ohos.resourceManager';
import { BusinessError } from '@ohos.base';
let resource: resourceManager.Resource = { let resource: resourceManager.Resource = {
bundleName: "com.example.myapplication", bundleName: "com.example.myapplication",
...@@ -3361,7 +3594,9 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco ...@@ -3361,7 +3594,9 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco
try { try {
this.context.resourceManager.getNumber(resource);// integer refers to the original value; float refers to the actual pixel value. this.context.resourceManager.getNumber(resource);// integer refers to the original value; float refers to the actual pixel value.
} catch (error) { } catch (error) {
console.error(`getNumber failed, error code: ${error.code}, message: ${error.message}.`); let code = (error as BusinessError).code;
let message = (error as BusinessError).message;
console.error(`getNumber failed, error code: ${code}, message: ${message}.`);
} }
``` ```
...@@ -3397,16 +3632,22 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco ...@@ -3397,16 +3632,22 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco
**Example** **Example**
```ts ```ts
import { BusinessError } from '@ohos.base';
try { try {
this.context.resourceManager.getNumberByName("integer_test"); this.context.resourceManager.getNumberByName("integer_test");
} catch (error) { } catch (error) {
console.error(`getNumberByName failed, error code: ${error.code}, message: ${error.message}.`); let code = (error as BusinessError).code;
let message = (error as BusinessError).message;
console.error(`getNumberByName failed, error code: ${code}, message: ${message}.`);
} }
try { try {
this.context.resourceManager.getNumberByName("float_test"); this.context.resourceManager.getNumberByName("float_test");
} catch (error) { } catch (error) {
console.error(`getNumberByName failed, error code: ${error.code}, message: ${error.message}.`); let code = (error as BusinessError).code;
let message = (error as BusinessError).message;
console.error(`getNumberByName failed, error code: ${code}, message: ${message}.`);
} }
``` ```
...@@ -3442,10 +3683,14 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco ...@@ -3442,10 +3683,14 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco
**Example** **Example**
```ts ```ts
import { BusinessError } from '@ohos.base';
try { try {
this.context.resourceManager.getColorSync($r('app.color.test').id); this.context.resourceManager.getColorSync($r('app.color.test').id);
} catch (error) { } catch (error) {
console.error(`getColorSync failed, error code: ${error.code}, message: ${error.message}.`); let code = (error as BusinessError).code;
let message = (error as BusinessError).message;
console.error(`getColorSync failed, error code: ${code}, message: ${message}.`);
} }
``` ```
...@@ -3484,6 +3729,7 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco ...@@ -3484,6 +3729,7 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco
**Example** **Example**
```ts ```ts
import resourceManager from '@ohos.resourceManager'; import resourceManager from '@ohos.resourceManager';
import { BusinessError } from '@ohos.base';
let resource: resourceManager.Resource = { let resource: resourceManager.Resource = {
bundleName: "com.example.myapplication", bundleName: "com.example.myapplication",
...@@ -3493,7 +3739,9 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco ...@@ -3493,7 +3739,9 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco
try { try {
this.context.resourceManager.getColorSync(resource); this.context.resourceManager.getColorSync(resource);
} catch (error) { } catch (error) {
console.error(`getColorSync failed, error code: ${error.code}, message: ${error.message}.`); let code = (error as BusinessError).code;
let message = (error as BusinessError).message;
console.error(`getColorSync failed, error code: ${code}, message: ${message}.`);
} }
``` ```
...@@ -3529,10 +3777,14 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco ...@@ -3529,10 +3777,14 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco
**Example** **Example**
```ts ```ts
import { BusinessError } from '@ohos.base';
try { try {
this.context.resourceManager.getColorByNameSync("test"); this.context.resourceManager.getColorByNameSync("test");
} catch (error) { } catch (error) {
console.error(`getColorByNameSync failed, error code: ${error.code}, message: ${error.message}.`); let code = (error as BusinessError).code;
let message = (error as BusinessError).message;
console.error(`getColorByNameSync failed, error code: ${code}, message: ${message}.`);
} }
``` ```
...@@ -3563,6 +3815,8 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco ...@@ -3563,6 +3815,8 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco
**Example (stage)** **Example (stage)**
```ts ```ts
import { BusinessError } from '@ohos.base';
try { try {
this.context.resourceManager.getColor($r('app.color.test').id, (error, value) => { this.context.resourceManager.getColor($r('app.color.test').id, (error, value) => {
if (error != null) { if (error != null) {
...@@ -3572,7 +3826,9 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco ...@@ -3572,7 +3826,9 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco
} }
}); });
} catch (error) { } catch (error) {
console.error(`callback getColor failed, error code: ${error.code}, message: ${error.message}.`); let code = (error as BusinessError).code;
let message = (error as BusinessError).message;
console.error(`callback getColor failed, error code: ${code}, message: ${message}.`);
} }
``` ```
...@@ -3617,7 +3873,9 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco ...@@ -3617,7 +3873,9 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco
console.log("getColor promise error is " + error); console.log("getColor promise error is " + error);
}); });
} catch (error) { } catch (error) {
console.error(`promise getColor failed, error code: ${error.code}, message: ${error.message}.`); let code = (error as BusinessError).code;
let message = (error as BusinessError).message;
console.error(`promise getColor failed, error code: ${code}, message: ${message}.`);
} }
``` ```
...@@ -3651,6 +3909,7 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco ...@@ -3651,6 +3909,7 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco
**Example** **Example**
```ts ```ts
import resourceManager from '@ohos.resourceManager'; import resourceManager from '@ohos.resourceManager';
import { BusinessError } from '@ohos.base';
let resource: resourceManager.Resource = { let resource: resourceManager.Resource = {
bundleName: "com.example.myapplication", bundleName: "com.example.myapplication",
...@@ -3666,7 +3925,9 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco ...@@ -3666,7 +3925,9 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco
} }
}); });
} catch (error) { } catch (error) {
console.error(`callback getColor failed, error code: ${error.code}, message: ${error.message}.`); let code = (error as BusinessError).code;
let message = (error as BusinessError).message;
console.error(`callback getColor failed, error code: ${code}, message: ${message}.`);
} }
``` ```
...@@ -3719,7 +3980,9 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco ...@@ -3719,7 +3980,9 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco
console.log("getColor promise error is " + error); console.log("getColor promise error is " + error);
}); });
} catch (error) { } catch (error) {
console.error(`promise getColor failed, error code: ${error.code}, message: ${error.message}.`); let code = (error as BusinessError).code;
let message = (error as BusinessError).message;
console.error(`promise getColor failed, error code: ${code}, message: ${message}.`);
} }
``` ```
...@@ -3750,6 +4013,8 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco ...@@ -3750,6 +4013,8 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco
**Example** **Example**
```ts ```ts
import { BusinessError } from '@ohos.base';
try { try {
this.context.resourceManager.getColorByName("test", (error, value) => { this.context.resourceManager.getColorByName("test", (error, value) => {
if (error != null) { if (error != null) {
...@@ -3759,7 +4024,9 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco ...@@ -3759,7 +4024,9 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco
} }
}); });
} catch (error) { } catch (error) {
console.error(`callback getColorByName failed, error code: ${error.code}, message: ${error.message}.`); let code = (error as BusinessError).code;
let message = (error as BusinessError).message;
console.error(`callback getColorByName failed, error code: ${code}, message: ${message}.`);
} }
``` ```
...@@ -3804,7 +4071,9 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco ...@@ -3804,7 +4071,9 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco
console.log("getColorByName promise error is " + error); console.log("getColorByName promise error is " + error);
}); });
} catch (error) { } catch (error) {
console.error(`promise getColorByName failed, error code: ${error.code}, message: ${error.message}.`); let code = (error as BusinessError).code;
let message = (error as BusinessError).message;
console.error(`promise getColorByName failed, error code: ${code}, message: ${message}.`);
} }
``` ```
...@@ -3838,10 +4107,14 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco ...@@ -3838,10 +4107,14 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco
**Example** **Example**
```ts ```ts
import { BusinessError } from '@ohos.base';
try { try {
this.context.resourceManager.getRawFileContentSync("test.txt"); this.context.resourceManager.getRawFileContentSync("test.txt");
} catch (error) { } catch (error) {
console.error(`getRawFileContentSync failed, error code: ${error.code}, message: ${error.message}.`); let code = (error as BusinessError).code;
let message = (error as BusinessError).message;
console.error(`getRawFileContentSync failed, error code: ${code}, message: ${message}.`);
} }
``` ```
...@@ -3870,6 +4143,8 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco ...@@ -3870,6 +4143,8 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco
**Example** **Example**
```ts ```ts
import { BusinessError } from '@ohos.base';
try { try {
this.context.resourceManager.getRawFileContent("test.txt", (error, value) => { this.context.resourceManager.getRawFileContent("test.txt", (error, value) => {
if (error != null) { if (error != null) {
...@@ -3879,7 +4154,9 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco ...@@ -3879,7 +4154,9 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco
} }
}); });
} catch (error) { } catch (error) {
console.error(`callback getRawFileContent failed, error code: ${error.code}, message: ${error.message}.`); let code = (error as BusinessError).code;
let message = (error as BusinessError).message;
console.error(`callback getRawFileContent failed, error code: ${code}, message: ${message}.`);
} }
``` ```
...@@ -3922,7 +4199,9 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco ...@@ -3922,7 +4199,9 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco
console.log("getRawFileContent promise error is " + error); console.log("getRawFileContent promise error is " + error);
}); });
} catch (error) { } catch (error) {
console.error(`promise getRawFileContent failed, error code: ${error.code}, message: ${error.message}.`); let code = (error as BusinessError).code;
let message = (error as BusinessError).message;
console.error(`promise getRawFileContent failed, error code: ${code}, message: ${message}.`);
} }
``` ```
...@@ -3956,10 +4235,14 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco ...@@ -3956,10 +4235,14 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco
**Example** **Example**
```ts ```ts
import { BusinessError } from '@ohos.base';
try { // Passing "" means to obtain the list of files in the root directory of the raw file. try { // Passing "" means to obtain the list of files in the root directory of the raw file.
this.context.resourceManager.getRawFileListSync("") this.context.resourceManager.getRawFileListSync("")
} catch (error) { } catch (error) {
console.error(`getRawFileListSync failed, error code: ${error.code}, message: ${error.message}.`); let code = (error as BusinessError).code;
let message = (error as BusinessError).message;
console.error(`getRawFileListSync failed, error code: ${code}, message: ${message}.`);
} }
``` ```
...@@ -3988,6 +4271,8 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco ...@@ -3988,6 +4271,8 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco
**Example** **Example**
```ts ```ts
import { BusinessError } from '@ohos.base';
try { // Passing "" means to obtain the list of files in the root directory of the raw file. try { // Passing "" means to obtain the list of files in the root directory of the raw file.
this.context.resourceManager.getRawFileList("", (error, value) => { this.context.resourceManager.getRawFileList("", (error, value) => {
if (error != null) { if (error != null) {
...@@ -3997,7 +4282,9 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco ...@@ -3997,7 +4282,9 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco
} }
}); });
} catch (error) { } catch (error) {
console.error(`callback getRawFileList failed, error code: ${error.code}, message: ${error.message}.`); let code = (error as BusinessError).code;
let message = (error as BusinessError).message;
console.error(`callback getRawFileList failed, error code: ${code}, message: ${message}.`);
} }
``` ```
...@@ -4040,7 +4327,9 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco ...@@ -4040,7 +4327,9 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco
console.error(`promise getRawFileList failed, error code: ${error.code}, message: ${error.message}.`); console.error(`promise getRawFileList failed, error code: ${error.code}, message: ${error.message}.`);
}); });
} catch (error) { } catch (error) {
console.error(`promise getRawFileList failed, error code: ${error.code}, message: ${error.message}.`); let code = (error as BusinessError).code;
let message = (error as BusinessError).message;
console.error(`promise getRawFileList failed, error code: ${code}, message: ${message}.`);
} }
``` ```
...@@ -4074,10 +4363,14 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco ...@@ -4074,10 +4363,14 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco
**Example** **Example**
```ts ```ts
import { BusinessError } from '@ohos.base';
try { try {
this.context.resourceManager.getRawFdSync("test.txt"); this.context.resourceManager.getRawFdSync("test.txt");
} catch (error) { } catch (error) {
console.error(`getRawFdSync failed, error code: ${error.code}, message: ${error.message}.`); let code = (error as BusinessError).code;
let message = (error as BusinessError).message;
console.error(`getRawFdSync failed, error code: ${code}, message: ${message}.`);
} }
``` ```
...@@ -4106,6 +4399,8 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco ...@@ -4106,6 +4399,8 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco
**Example** **Example**
```ts ```ts
import { BusinessError } from '@ohos.base';
try { try {
this.context.resourceManager.getRawFd("test.txt", (error, value) => { this.context.resourceManager.getRawFd("test.txt", (error, value) => {
if (error != null) { if (error != null) {
...@@ -4117,7 +4412,9 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco ...@@ -4117,7 +4412,9 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco
} }
}); });
} catch (error) { } catch (error) {
console.error(`callback getRawFd failed, error code: ${error.code}, message: ${error.message}.`); let code = (error as BusinessError).code;
let message = (error as BusinessError).message;
console.error(`callback getRawFd failed, error code: ${code}, message: ${message}.`);
} }
``` ```
...@@ -4162,7 +4459,9 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco ...@@ -4162,7 +4459,9 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco
console.log(`promise getRawFd error error code: ${error.code}, message: ${error.message}.`); console.log(`promise getRawFd error error code: ${error.code}, message: ${error.message}.`);
}); });
} catch (error) { } catch (error) {
console.error(`promise getRawFd failed, error code: ${error.code}, message: ${error.message}.`); let code = (error as BusinessError).code;
let message = (error as BusinessError).message;
console.error(`promise getRawFd failed, error code: ${code}, message: ${message}.`);
} }
``` ```
...@@ -4190,10 +4489,14 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco ...@@ -4190,10 +4489,14 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco
**Example** **Example**
```ts ```ts
import { BusinessError } from '@ohos.base';
try { try {
this.context.resourceManager.closeRawFdSync("test.txt"); this.context.resourceManager.closeRawFdSync("test.txt");
} catch (error) { } catch (error) {
console.error(`closeRawFd failed, error code: ${error.code}, message: ${error.message}.`); let code = (error as BusinessError).code;
let message = (error as BusinessError).message;
console.error(`closeRawFd failed, error code: ${code}, message: ${message}.`);
} }
``` ```
...@@ -4222,6 +4525,8 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco ...@@ -4222,6 +4525,8 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco
**Example** **Example**
```ts ```ts
import { BusinessError } from '@ohos.base';
try { try {
this.context.resourceManager.closeRawFd("test.txt", (error, value) => { this.context.resourceManager.closeRawFd("test.txt", (error, value) => {
if (error != null) { if (error != null) {
...@@ -4229,7 +4534,9 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco ...@@ -4229,7 +4534,9 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco
} }
}); });
} catch (error) { } catch (error) {
console.error(`callback closeRawFd failed, error code: ${error.code}, message: ${error.message}.`); let code = (error as BusinessError).code;
let message = (error as BusinessError).message;
console.error(`callback closeRawFd failed, error code: ${code}, message: ${message}.`);
} }
``` ```
...@@ -4263,10 +4570,14 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco ...@@ -4263,10 +4570,14 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco
**Example** **Example**
```ts ```ts
import { BusinessError } from '@ohos.base';
try { try {
this.context.resourceManager.closeRawFd("test.txt"); this.context.resourceManager.closeRawFd("test.txt");
} catch (error) { } catch (error) {
console.error(`promise closeRawFd failed, error code: ${error.code}, message: ${error.message}.`); let code = (error as BusinessError).code;
let message = (error as BusinessError).message;
console.error(`promise closeRawFd failed, error code: ${code}, message: ${message}.`);
} }
``` ```
...@@ -4481,11 +4792,15 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco ...@@ -4481,11 +4792,15 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco
**Example** **Example**
```ts ```ts
import { BusinessError } from '@ohos.base';
let path = getContext().bundleCodeDir + "/library1-default-signed.hsp"; let path = getContext().bundleCodeDir + "/library1-default-signed.hsp";
try { try {
this.context.resourceManager.addResource(path); this.context.resourceManager.addResource(path);
} catch (error) { } catch (error) {
console.error(`addResource failed, error code: ${error.code}, message: ${error.message}.`); let code = (error as BusinessError).code;
let message = (error as BusinessError).message;
console.error(`addResource failed, error code: ${code}, message: ${message}.`);
} }
``` ```
...@@ -4513,11 +4828,15 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco ...@@ -4513,11 +4828,15 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco
**Example** **Example**
```ts ```ts
import { BusinessError } from '@ohos.base';
let path = getContext().bundleCodeDir + "/library1-default-signed.hsp"; let path = getContext().bundleCodeDir + "/library1-default-signed.hsp";
try { try {
this.context.resourceManager.removeResource(path); this.context.resourceManager.removeResource(path);
} catch (error) { } catch (error) {
console.error(`removeResource failed, error code: ${error.code}, message: ${error.message}.`); let code = (error as BusinessError).code;
let message = (error as BusinessError).message;
console.error(`removeResource failed, error code: ${code}, message: ${message}.`);
} }
``` ```
......
...@@ -5,6 +5,7 @@ The **shortKey** module provides APIs to set the delay for starting an ability u ...@@ -5,6 +5,7 @@ The **shortKey** module provides APIs to set the delay for starting an ability u
> **NOTE** > **NOTE**
> >
> - The initial APIs of this module are supported since API version 10. Newly added APIs will be marked with a superscript to indicate their earliest API version. > - The initial APIs of this module are supported since API version 10. Newly added APIs will be marked with a superscript to indicate their earliest API version.
>
> - The APIs provided by this module are system APIs. > - The APIs provided by this module are system APIs.
## Modules to Import ## Modules to Import
...@@ -17,7 +18,7 @@ import shortKey from '@ohos.multimodalInput.shortKey'; ...@@ -17,7 +18,7 @@ import shortKey from '@ohos.multimodalInput.shortKey';
setKeyDownDuration(businessKey: string, delay: number, callback: AsyncCallback&lt;void&gt;): void setKeyDownDuration(businessKey: string, delay: number, callback: AsyncCallback&lt;void&gt;): void
Sets the delay for starting an ability using the shortcut key. This API uses an asynchronous callback to return the result. Sets the delay for starting an ability using shortcut keys. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.MultimodalInput.Input.ShortKey **System capability**: SystemCapability.MultimodalInput.Input.ShortKey
...@@ -26,8 +27,8 @@ Sets the delay for starting an ability using the shortcut key. This API uses an ...@@ -26,8 +27,8 @@ Sets the delay for starting an ability using the shortcut key. This API uses an
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| ---------- | ------------------- | ---- | ------------------------------------------------------------ | | ---------- | ------------------- | ---- | ------------------------------------------------------------ |
| businessKey| string | Yes | Unique service ID registered on the multimodal side. It corresponds to **businessId** in the **ability_launch_config.json** file.| | businessKey| string | Yes | Unique service ID registered on the multimodal side. It corresponds to **businessId** in the **ability_launch_config.json** file.|
| delay | number | Yes | Delay for starting an ability using the shortcut key, in ms.| | delay | number | Yes | Delay for starting an ability using shortcut keys, in milliseconds. This field is invalid only when shortcut keys are used.|
| callback | AsyncCallback&lt;void&gt; | Yes | Callback used to return the result. | | callback | AsyncCallback&lt;void&gt; | Yes | Callback used to return the result. If the operation is successful, **err** is **undefined**. Otherwise, **err** is an error object. |
**Example** **Example**
...@@ -45,13 +46,11 @@ try { ...@@ -45,13 +46,11 @@ try {
} }
``` ```
## shortKey.setKeyDownDuration ## shortKey.setKeyDownDuration
setKeyDownDuration(businessKey: string, delay: number): Promise&lt;void&gt; setKeyDownDuration(businessKey: string, delay: number): Promise&lt;void&gt;
Sets the delay for starting an ability using the shortcut key. This API uses a promise to return the result. Sets the delay for starting an ability using shortcut keys. This API uses a promise to return the result.
**System capability**: SystemCapability.MultimodalInput.Input.ShortKey **System capability**: SystemCapability.MultimodalInput.Input.ShortKey
...@@ -60,13 +59,13 @@ Sets the delay for starting an ability using the shortcut key. This API uses a p ...@@ -60,13 +59,13 @@ Sets the delay for starting an ability using the shortcut key. This API uses a p
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| ---------- | ------ | ---- | ------------------------------------------------------------ | | ---------- | ------ | ---- | ------------------------------------------------------------ |
| businessKey| string | Yes | Unique service ID registered on the multimodal side. It corresponds to **businessId** in the **ability_launch_config.json** file.| | businessKey| string | Yes | Unique service ID registered on the multimodal side. It corresponds to **businessId** in the **ability_launch_config.json** file.|
| delay | number | Yes | Delay for starting an ability using the shortcut key, in ms.| | delay | number | Yes | Delay for starting an ability using shortcut keys, in milliseconds. This field is invalid only when shortcut keys are used.|
**Return value** **Return value**
| Parameters | Description | | Parameters | Description |
| ------------- | ------------- | | ------------- | ------------- |
| Promise&lt;void&gt; | Promise used to return the result.| | Promise&lt;void&gt; | Promise that returns no value.|
**Example** **Example**
......
...@@ -1262,7 +1262,7 @@ Obtains the file descriptor of the **TCPSocket** object. This API uses an asynch ...@@ -1262,7 +1262,7 @@ Obtains the file descriptor of the **TCPSocket** object. This API uses an asynch
```js ```js
import socket from "@ohos.net.socket"; import socket from "@ohos.net.socket";
var tcp = socket.constructTCPSocketInstance(); let tcp = socket.constructTCPSocketInstance();
let tunnelfd = 0 let tunnelfd = 0
tcp.bind({ tcp.bind({
address: "0.0.0.0", address: "0.0.0.0",
...@@ -1302,7 +1302,7 @@ Obtains the file descriptor of the **TCPSocket** object. This API uses a promise ...@@ -1302,7 +1302,7 @@ Obtains the file descriptor of the **TCPSocket** object. This API uses a promise
```js ```js
import socket from "@ohos.net.socket"; import socket from "@ohos.net.socket";
var tcp = socket.constructTCPSocketInstance(); let tcp = socket.constructTCPSocketInstance();
let tunnelfd = 0 let tunnelfd = 0
tcp.bind({ tcp.bind({
address: "0.0.0.0", address: "0.0.0.0",
...@@ -1715,7 +1715,7 @@ Binds the IP address and port number. The port number can be specified or random ...@@ -1715,7 +1715,7 @@ Binds the IP address and port number. The port number can be specified or random
| 2303109 | Bad file number. | | 2303109 | Bad file number. |
| 2303111 | Resource temporarily unavailable try again. | | 2303111 | Resource temporarily unavailable try again. |
| 2303198 | Address already in use. | | 2303198 | Address already in use. |
| 2303199 | Cannot assign requested address. | | 2303199 | Address not available. |
**Example** **Example**
...@@ -1765,7 +1765,7 @@ Binds the IP address and port number. The port number can be specified or random ...@@ -1765,7 +1765,7 @@ Binds the IP address and port number. The port number can be specified or random
| 2303109 | Bad file number. | | 2303109 | Bad file number. |
| 2303111 | Resource temporarily unavailable try again. | | 2303111 | Resource temporarily unavailable try again. |
| 2303198 | Address already in use. | | 2303198 | Address already in use. |
| 2303199 | Cannot assign requested address. | | 2303199 | Address not available. |
**Example** **Example**
...@@ -1805,7 +1805,7 @@ Obtains the status of the TCPSocketServer connection. This API uses an asynchron ...@@ -1805,7 +1805,7 @@ Obtains the status of the TCPSocketServer connection. This API uses an asynchron
| 401 | Parameter error. | | 401 | Parameter error. |
| 201 | Permission denied. | | 201 | Permission denied. |
| 2300002 | System internal error. | | 2300002 | System internal error. |
| 2303188 | Socket operation on non-socket. | | 2303188 | Not a socket. |
**Example** **Example**
...@@ -1852,7 +1852,7 @@ Obtains the status of the TCPSocketServer connection. This API uses a promise to ...@@ -1852,7 +1852,7 @@ Obtains the status of the TCPSocketServer connection. This API uses a promise to
| -------- | ------------------------------- | | -------- | ------------------------------- |
| 201 | Permission denied. | | 201 | Permission denied. |
| 2300002 | System internal error. | | 2300002 | System internal error. |
| 2303188 | Socket operation on non-socket. | | 2303188 | Not a socket. |
**Example** **Example**
...@@ -1899,7 +1899,7 @@ Sets other properties of the TCPSocketServer connection. This API uses an asynch ...@@ -1899,7 +1899,7 @@ Sets other properties of the TCPSocketServer connection. This API uses an asynch
| 401 | Parameter error. | | 401 | Parameter error. |
| 201 | Permission denied. | | 201 | Permission denied. |
| 2300002 | System internal error. | | 2300002 | System internal error. |
| 2303188 | Socket operation on non-socket. | | 2303188 | Not a socket. |
**Example** **Example**
...@@ -1962,7 +1962,7 @@ Sets other properties of the TCPSocketServer connection. This API uses a promise ...@@ -1962,7 +1962,7 @@ Sets other properties of the TCPSocketServer connection. This API uses a promise
| 401 | Parameter error. | | 401 | Parameter error. |
| 201 | Permission denied. | | 201 | Permission denied. |
| 2300002 | System internal error. | | 2300002 | System internal error. |
| 2303188 | Socket operation on non-socket. | | 2303188 | Not a socket. |
**Example** **Example**
...@@ -2338,7 +2338,7 @@ Obtains the remote address of a socket connection. This API uses an asynchronous ...@@ -2338,7 +2338,7 @@ Obtains the remote address of a socket connection. This API uses an asynchronous
| 401 | Parameter error. | | 401 | Parameter error. |
| 201 | Permission denied. | | 201 | Permission denied. |
| 2300002 | System internal error. | | 2300002 | System internal error. |
| 2303188 | Socket operation on non-socket. | | 2303188 | Not a socket. |
**Example** **Example**
...@@ -2380,7 +2380,7 @@ Obtains the remote address of a socket connection. This API uses a promise to re ...@@ -2380,7 +2380,7 @@ Obtains the remote address of a socket connection. This API uses a promise to re
| -------- | ------------------------------- | | -------- | ------------------------------- |
| 201 | Permission denied. | | 201 | Permission denied. |
| 2300002 | System internal error. | | 2300002 | System internal error. |
| 2303188 | Socket operation on non-socket. | | 2303188 | Not a socket. |
**Example** **Example**
...@@ -2751,7 +2751,7 @@ Obtains the status of the TLS socket connection. This API uses an asynchronous c ...@@ -2751,7 +2751,7 @@ Obtains the status of the TLS socket connection. This API uses an asynchronous c
| ID| Error Message | | ID| Error Message |
| ------- | ------------------------------ | | ------- | ------------------------------ |
| 2303188 | Socket operation on non-socket.| | 2303188 | Not a socket.|
| 2300002 | System internal error. | | 2300002 | System internal error. |
**Example** **Example**
...@@ -2791,7 +2791,7 @@ Obtains the status of the TLS socket connection. This API uses a promise to retu ...@@ -2791,7 +2791,7 @@ Obtains the status of the TLS socket connection. This API uses a promise to retu
| ID| Error Message | | ID| Error Message |
| ------- | ------------------------------ | | ------- | ------------------------------ |
| 2303188 | Socket operation on non-socket.| | 2303188 | Not a socket.|
| 2300002 | System internal error. | | 2300002 | System internal error. |
**Example** **Example**
...@@ -2831,7 +2831,7 @@ Sets other properties of the TCP socket connection after **bind** is successfull ...@@ -2831,7 +2831,7 @@ Sets other properties of the TCP socket connection after **bind** is successfull
| ID| Error Message | | ID| Error Message |
| ------- | ----------------------------- | | ------- | ----------------------------- |
| 401 | Parameter error. | | 401 | Parameter error. |
| 2303188 | Socket operation on non-socket.| | 2303188 | Not a socket.|
| 2300002 | System internal error. | | 2300002 | System internal error. |
**Example** **Example**
...@@ -2888,7 +2888,7 @@ Sets other properties of the TCP socket connection after **bind** is successfull ...@@ -2888,7 +2888,7 @@ Sets other properties of the TCP socket connection after **bind** is successfull
| ID| Error Message | | ID| Error Message |
| ------- | ------------------------------ | | ------- | ------------------------------ |
| 401 | Parameter error. | | 401 | Parameter error. |
| 2303188 | Socket operation on non-socket.| | 2303188 | Not a socket.|
| 2300002 | System internal error. | | 2300002 | System internal error. |
**Example** **Example**
...@@ -2936,6 +2936,7 @@ Subscribes to **message** events of the TLS socket connection. This API uses an ...@@ -2936,6 +2936,7 @@ Subscribes to **message** events of the TLS socket connection. This API uses an
**Example** **Example**
```js ```js
import socket from '@ohos.net.socket';
let tls = socket.constructTLSSocketInstance(); let tls = socket.constructTLSSocketInstance();
let messageView = ''; let messageView = '';
tls.on('message', value => { tls.on('message', value => {
...@@ -2970,6 +2971,7 @@ Unsubscribes from **message** events of the TLS socket connection. This API uses ...@@ -2970,6 +2971,7 @@ Unsubscribes from **message** events of the TLS socket connection. This API uses
**Example** **Example**
```js ```js
import socket from '@ohos.net.socket';
let tls = socket.constructTLSSocketInstance(); let tls = socket.constructTLSSocketInstance();
let messageView = ''; let messageView = '';
let callback = value => { let callback = value => {
...@@ -3003,6 +3005,7 @@ Subscribes to **connect** or **close** events of the TLS socket connection. This ...@@ -3003,6 +3005,7 @@ Subscribes to **connect** or **close** events of the TLS socket connection. This
**Example** **Example**
```js ```js
import socket from '@ohos.net.socket';
let tls = socket.constructTLSSocketInstance(); let tls = socket.constructTLSSocketInstance();
tls.on('connect', () => { tls.on('connect', () => {
console.log("on connect success") console.log("on connect success")
...@@ -3033,6 +3036,7 @@ Unsubscribes from **connect** or **close** events of the TLS socket connection. ...@@ -3033,6 +3036,7 @@ Unsubscribes from **connect** or **close** events of the TLS socket connection.
**Example** **Example**
```js ```js
import socket from '@ohos.net.socket';
let tls = socket.constructTLSSocketInstance(); let tls = socket.constructTLSSocketInstance();
let callback1 = () => { let callback1 = () => {
console.log("on connect success"); console.log("on connect success");
...@@ -3067,6 +3071,7 @@ Subscribes to **error** events of the TLS socket connection. This API uses an as ...@@ -3067,6 +3071,7 @@ Subscribes to **error** events of the TLS socket connection. This API uses an as
**Example** **Example**
```js ```js
import socket from '@ohos.net.socket';
let tls = socket.constructTLSSocketInstance(); let tls = socket.constructTLSSocketInstance();
tls.on('error', err => { tls.on('error', err => {
console.log("on error, err:" + JSON.stringify(err)) console.log("on error, err:" + JSON.stringify(err))
...@@ -3094,6 +3099,7 @@ Unsubscribes from **error** events of the TLS socket connection. This API uses a ...@@ -3094,6 +3099,7 @@ Unsubscribes from **error** events of the TLS socket connection. This API uses a
**Example** **Example**
```js ```js
import socket from '@ohos.net.socket';
let tls = socket.constructTLSSocketInstance(); let tls = socket.constructTLSSocketInstance();
let callback = err => { let callback = err => {
console.log("on error, err:" + JSON.stringify(err)); console.log("on error, err:" + JSON.stringify(err));
...@@ -3126,10 +3132,10 @@ Sets up a TLS socket connection, and creates and initializes a TLS session after ...@@ -3126,10 +3132,10 @@ Sets up a TLS socket connection, and creates and initializes a TLS session after
| 2303104 | Interrupted system call. | | 2303104 | Interrupted system call. |
| 2303109 | Bad file number. | | 2303109 | Bad file number. |
| 2303111 | Resource temporarily unavailable try again. | | 2303111 | Resource temporarily unavailable try again. |
| 2303188 | Socket operation on non-socket. | | 2303188 | Not a socket. |
| 2303191 | Protocol wrong type for socket. | | 2303191 | Protocol wrong type for socket. |
| 2303198 | Address already in use. | | 2303198 | Address already in use. |
| 2303199 | Cannot assign requested address. | | 2303199 | Address not available. |
| 2303210 | Connection timed out. | | 2303210 | Connection timed out. |
| 2303501 | SSL is null. | | 2303501 | SSL is null. |
| 2303502 | Error in tls reading. | | 2303502 | Error in tls reading. |
...@@ -3225,10 +3231,10 @@ Sets up a TLS socket connection, and creates and initializes a TLS session after ...@@ -3225,10 +3231,10 @@ Sets up a TLS socket connection, and creates and initializes a TLS session after
| 2303104 | Interrupted system call. | | 2303104 | Interrupted system call. |
| 2303109 | Bad file number. | | 2303109 | Bad file number. |
| 2303111 | Resource temporarily unavailable try again. | | 2303111 | Resource temporarily unavailable try again. |
| 2303188 | Socket operation on non-socket. | | 2303188 | Not a socket. |
| 2303191 | Protocol wrong type for socket. | | 2303191 | Protocol wrong type for socket. |
| 2303198 | Address already in use. | | 2303198 | Address already in use. |
| 2303199 | Cannot assign requested address. | | 2303199 | Address not available. |
| 2303210 | Connection timed out. | | 2303210 | Connection timed out. |
| 2303501 | SSL is null. | | 2303501 | SSL is null. |
| 2303502 | Error in tls reading. | | 2303502 | Error in tls reading. |
...@@ -3316,7 +3322,7 @@ Obtains the remote address of a TLS socket connection. This API uses an asynchro ...@@ -3316,7 +3322,7 @@ Obtains the remote address of a TLS socket connection. This API uses an asynchro
| ID| Error Message | | ID| Error Message |
| ------- | ----------------------------- | | ------- | ----------------------------- |
| 2303188 | Socket operation on non-socket.| | 2303188 | Not a socket.|
| 2300002 | System internal error. | | 2300002 | System internal error. |
**Example** **Example**
...@@ -3349,7 +3355,7 @@ Obtains the remote address of a TLS socket connection. This API uses a promise t ...@@ -3349,7 +3355,7 @@ Obtains the remote address of a TLS socket connection. This API uses a promise t
| ID| Error Message | | ID| Error Message |
| ------- | ------------------------------ | | ------- | ------------------------------ |
| 2303188 | Socket operation on non-socket.| | 2303188 | Not a socket.|
| 2300002 | System internal error. | | 2300002 | System internal error. |
**Example** **Example**
...@@ -3937,7 +3943,7 @@ Listens to client connections after **bind** is successfully called. This API us ...@@ -3937,7 +3943,7 @@ Listens to client connections after **bind** is successfully called. This API us
| 2303109 | Bad file number. | | 2303109 | Bad file number. |
| 2303111 | Resource temporarily unavailable try again. | | 2303111 | Resource temporarily unavailable try again. |
| 2303198 | Address already in use. | | 2303198 | Address already in use. |
| 2303199 | Cannot assign requested address. | | 2303199 | Address not available. |
| 2303501 | SSL is null. | | 2303501 | SSL is null. |
| 2303502 | Error in tls reading. | | 2303502 | Error in tls reading. |
| 2303503 | Error in tls writing | | 2303503 | Error in tls writing |
...@@ -4003,7 +4009,7 @@ Listens to client connections after **bind** is successfully called. This API us ...@@ -4003,7 +4009,7 @@ Listens to client connections after **bind** is successfully called. This API us
| 2303109 | Bad file number. | | 2303109 | Bad file number. |
| 2303111 | Resource temporarily unavailable try again. | | 2303111 | Resource temporarily unavailable try again. |
| 2303198 | Address already in use. | | 2303198 | Address already in use. |
| 2303199 | Cannot assign requested address. | | 2303199 | Address not available. |
| 2303501 | SSL is null. | | 2303501 | SSL is null. |
| 2303502 | Error in tls reading. | | 2303502 | Error in tls reading. |
| 2303503 | Error in tls writing | | 2303503 | Error in tls writing |
...@@ -4061,7 +4067,7 @@ Obtains the status of the TLS socket server connection upon successful listening ...@@ -4061,7 +4067,7 @@ Obtains the status of the TLS socket server connection upon successful listening
| ID| Error Message | | ID| Error Message |
| -------- | ------------------------------- | | -------- | ------------------------------- |
| 401 | Parameter error. | | 401 | Parameter error. |
| 2303188 | Socket operation on non-socket. | | 2303188 | Not a socket. |
| 2300002 | System internal error. | | 2300002 | System internal error. |
**Example** **Example**
...@@ -4121,7 +4127,7 @@ Obtains the status of the TLS socket server connection upon successful listening ...@@ -4121,7 +4127,7 @@ Obtains the status of the TLS socket server connection upon successful listening
| ID| Error Message | | ID| Error Message |
| -------- | ------------------------------- | | -------- | ------------------------------- |
| 2303188 | Socket operation on non-socket. | | 2303188 | Not a socket. |
| 2300002 | System internal error. | | 2300002 | System internal error. |
**Example** **Example**
...@@ -4183,7 +4189,7 @@ Sets other properties of the TLS socket server connection upon successful listen ...@@ -4183,7 +4189,7 @@ Sets other properties of the TLS socket server connection upon successful listen
| ID| Error Message | | ID| Error Message |
| -------- | ------------------------------- | | -------- | ------------------------------- |
| 401 | Parameter error. | | 401 | Parameter error. |
| 2303188 | Socket operation on non-socket. | | 2303188 | Not a socket. |
| 2300002 | System internal error. | | 2300002 | System internal error. |
**Example** **Example**
...@@ -4258,7 +4264,7 @@ Sets other properties of the TLS socket server connection upon successful listen ...@@ -4258,7 +4264,7 @@ Sets other properties of the TLS socket server connection upon successful listen
| ID| Error Message | | ID| Error Message |
| -------- | ------------------------------- | | -------- | ------------------------------- |
| 401 | Parameter error. | | 401 | Parameter error. |
| 2303188 | Socket operation on non-socket. | | 2303188 | Not a socket. |
| 2300002 | System internal error. | | 2300002 | System internal error. |
**Example** **Example**
...@@ -4870,7 +4876,7 @@ Sends a message to the server after a TLS socket server connection is establishe ...@@ -4870,7 +4876,7 @@ Sends a message to the server after a TLS socket server connection is establishe
| Name| Type | Mandatory| Description | | Name| Type | Mandatory| Description |
| ------ | ------ | ---- | ------------------------------------- | | ------ | ------ | ---- | ------------------------------------- |
| data | string | Yes | Parameters required for the TLS socket server connection.| | data | string | Yes | Parameters for sending data over the TLS socket server connection.|
**Return value** **Return value**
...@@ -5068,7 +5074,7 @@ Obtains the remote address of a TLS socket server connection. This API uses an a ...@@ -5068,7 +5074,7 @@ Obtains the remote address of a TLS socket server connection. This API uses an a
| ID| Error Message | | ID| Error Message |
| -------- | ------------------------------- | | -------- | ------------------------------- |
| 401 | Parameter error. | | 401 | Parameter error. |
| 2303188 | Socket operation on non-socket. | | 2303188 | Not a socket. |
| 2300002 | System internal error. | | 2300002 | System internal error. |
**Example** **Example**
...@@ -5126,7 +5132,7 @@ Obtains the remote address of a TLS socket server connection. This API uses a pr ...@@ -5126,7 +5132,7 @@ Obtains the remote address of a TLS socket server connection. This API uses a pr
| ID| Error Message | | ID| Error Message |
| -------- | ------------------------------- | | -------- | ------------------------------- |
| 2303188 | Socket operation on non-socket. | | 2303188 | Not a socket. |
| 2300002 | System internal error. | | 2300002 | System internal error. |
**Example** **Example**
......
# @ohos.multimodalInput.touchEvent (Touch Event) # @ohos.multimodalInput.touchEvent (Touch Event)
The **touchEvent** module provides touch events reported by an input device. The **touchEvent** module provides touch (touchscreen) events reported by an input device.
> **NOTE**<br> > **NOTE**
>
> The initial APIs of this module are supported since API version 9. Newly added APIs will be marked with a superscript to indicate their earliest API version. > The initial APIs of this module are supported since API version 9. Newly added APIs will be marked with a superscript to indicate their earliest API version.
## Modules to Import ## Modules to Import
...@@ -13,72 +14,72 @@ import {Action,ToolType,SourceType,Touch,TouchEvent} from '@ohos.multimodalInput ...@@ -13,72 +14,72 @@ import {Action,ToolType,SourceType,Touch,TouchEvent} from '@ohos.multimodalInput
## Action ## Action
Enumerates touch actions. Enumerates touch event types.
**System capability**: SystemCapability.MultimodalInput.Input.Core **System capability**: SystemCapability.MultimodalInput.Input.Core
| Name | Value | Description | | Name | Value | Description |
| ------ | ----- | ----------- | | ------ | ------ | ---- |
| CANCEL | 0 | Cancellation of the touch action.| | CANCEL | 0 | Cancellation of touch.|
| DOWN | 1 | Pressing of touch. | | DOWN | 1 | Pressing of touch.|
| MOVE | 2 | Moving of touch. | | MOVE | 2 | Moving of touch.|
| UP | 3 | Lifting of touch. | | UP | 3 | Lifting of touch.|
## ToolType ## ToolType
Enumerates tool types. Enumerates touch tool types.
**System capability**: SystemCapability.MultimodalInput.Input.Core **System capability**: SystemCapability.MultimodalInput.Input.Core
| Name | Value | Description | | Name | Value | Description |
| ---- | ----- | ----------- | | -------- | ------ | ---- |
| FINGER | 0 | Finger| | FINGER | 0 | Finger |
| PEN | 1 | Pen| | PEN | 1 | Stylus |
| RUBBER | 2 | Eraser| | RUBBER | 2 | Eraser |
| BRUSH | 3 | Brush| | BRUSH | 3 | Brush |
| PENCIL | 4 | Pencil| | PENCIL | 4 | Pencil |
| AIRBRUSH | 5 | Air brush| | AIRBRUSH | 5 | Air brush |
| MOUSE | 6 | Mouse| | MOUSE | 6 | Mouse |
| LENS | 7 | Lens| | LENS | 7 | Lens |
## SourceType ## SourceType
Enumerates source types. Enumerates touch source types.
**System capability**: SystemCapability.MultimodalInput.Input.Core **System capability**: SystemCapability.MultimodalInput.Input.Core
| Name | Value | Description | | Name | Value | Description |
| ---- | ----- | ----------- | | ------------ | ------ | ---- |
| TOUCH_SCREEN | 0 | Touchscreen| | TOUCH_SCREEN | 0 | Touchscreen |
| PEN | 1 | Stylus | | PEN | 1 | Stylus |
| TOUCH_PAD | 2 | Touchpad | | TOUCH_PAD | 2 | Touchpad |
## Touch ## Touch
Defines a touch action. Defines the touch point information.
**System capability**: SystemCapability.MultimodalInput.Input.Core **System capability**: SystemCapability.MultimodalInput.Input.Core
| Name| Type| Readable| Writable| Description| | Name | Type | Readable | Writable | Description |
| -------- | -------- | -------- | -------- | -------- | | ----------- | ------ | ---- | ---- | ----------------------------------- |
| id | number | Yes| No| Pointer ID.| | id | number | Yes | No | Touch event ID. |
| pressedTime | number | Yes| No| Time stamp when touch is pressed.| | pressedTime | number | Yes | No | Press timestamp, in μs. |
| screenX | number | Yes| No| X coordinate of the touch position on the screen.| | screenX | number | Yes | No | X coordinate of the touch position on the screen. |
| screenY | number | Yes| No| Y coordinate of the touch position on the screen.| | screenY | number | Yes | No | Y coordinate of the touch position on the screen. |
| windowX | number | Yes| No| X coordinate of the touch position in the window.| | windowX | number | Yes | No | X coordinate of the touch position in the window. |
| windowY | number | Yes| No| Y coordinate of the touch position in the window.| | windowY | number | Yes | No | Y coordinate of the touch position in the window. |
| pressure | number | Yes| No| Pressure value. The value range is [0.0, 1.0]. The value 0.0 indicates that the pressure is not supported.| | pressure | number | Yes | No | Pressure value. The value range is [0.0, 1.0]. The value 0.0 indicates that the pressure is not supported. |
| width | number | Yes| No| Width of the contact area where touch is pressed.| | width | number | Yes | No | Width of the touch area. |
| height | number | Yes| No| Height of the contact area where touch is pressed.| | height | number | Yes | No | Height of the touch area. |
| tiltX | number | Yes| No| Angle relative to the YZ plane. The value range is [-90, 90]. A positive value indicates a rightward tilt.| | tiltX | number | Yes | No | Angle relative to the YZ plane. The value range is [-90, 90]. A positive value indicates a rightward tilt.|
| tiltY | number | Yes| No| Angle relative to the XZ plane. The value range is [-90, 90]. A positive value indicates a downward tilt.| | tiltY | number | Yes | No | Angle relative to the XZ plane. The value range is [-90, 90]. A positive value indicates a downward tilt.|
| toolX | number | Yes| No| Center point X of the tool area.| | toolX | number | Yes | No | X coordinate of the center point of the tool area. |
| toolY | number | Yes| No| Center point Y of the tool area.| | toolY | number | Yes | No | Y coordinate of the center point of the tool area. |
| toolWidth | number | Yes| No| Width of the tool area.| | toolWidth | number | Yes | No | Width of the tool area. |
| toolHeight | number | Yes| No| Height of the tool area.| | toolHeight | number | Yes | No | Height of the tool area. |
| rawX | number | Yes| No| X coordinate of the input device.| | rawX | number | Yes | No | X coordinate of the input device. |
| rawY | number | Yes| No| Y coordinate of the input device.| | rawY | number | Yes | No | Y coordinate of the input device. |
| toolType | ToolType | Yes| No| Tool type.| | toolType | [ToolType](#tooltype) | Yes | No | Tool type. |
## TouchEvent ## TouchEvent
...@@ -86,9 +87,9 @@ Defines a touch event. ...@@ -86,9 +87,9 @@ Defines a touch event.
**System capability**: SystemCapability.MultimodalInput.Input.Core **System capability**: SystemCapability.MultimodalInput.Input.Core
| Name| Type| Readable| Writable| Description| | Name | Type | Readable | Writable | Description |
| -------- | -------- | -------- | -------- | -------- | | ---------- | ---------- | ---- | ---- | --------- |
| action | Action | Yes| No| Touch action.| | action | [Action](#action) | Yes | No | Touch event type. |
| touch | Touch | Yes| No| Current touch point.| | touch | [Touch](#touch) | Yes | No | Current touch point. |
| touches | Touch[] | Yes| No| All touch points.| | touches | Touch[] | Yes | No | All touch points. |
| sourceType | SourceType | Yes| No| Device type of the touch source.| | sourceType | [SourceType](#sourcetype) | Yes | No | Touch source type.|
...@@ -43,7 +43,7 @@ The specified event domain name does not comply with the following rules: ...@@ -43,7 +43,7 @@ The specified event domain name does not comply with the following rules:
- The event domain name contains only digits, lowercase letters, and underscores (\_). - The event domain name contains only digits, lowercase letters, and underscores (\_).
- The event domain name starts with a lowercase letter and does not end with an underscore (\_). - The event domain name starts with a lowercase letter and does not end with an underscore (\_).
- The event domain name is not empty and contains a maximum of 32 characters. - The event domain name is not empty and contains a maximum of 16 characters.
**Solution** **Solution**
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册