From 193ee6084d035eea4ce92605c98b915015c35873 Mon Sep 17 00:00:00 2001 From: shawn_he Date: Thu, 24 Aug 2023 15:26:15 +0800 Subject: [PATCH] update doc Signed-off-by: shawn_he --- .../connectivity/http-request.md | 30 +- .../connectivity/net-connection-manager.md | 1 + .../connectivity/net-ethernet.md | 1 + .../connectivity/net-sharing.md | 1 + .../connectivity/net-statistics.md | 1 + en/application-dev/connectivity/net-vpn.md | 1 + .../connectivity/websocket-connection.md | 2 +- en/application-dev/dfx/Readme-EN.md | 1 - .../dfx/appfreeze-guidelines.md | 2 +- .../dfx/apprecovery-guidelines.md | 2 +- en/application-dev/dfx/cppcrash-guidelines.md | 2 +- .../dfx/errormanager-guidelines.md | 2 +- .../dfx/hiappevent-guidelines.md | 2 +- en/application-dev/dfx/hilog-guidelines.md | 2 +- .../dfx/hitracechain-guidelines.md | 2 +- .../dfx/hitracemeter-guidelines.md | 62 +- .../dfx/hitracemeter-native-guidelines.md | 2 +- .../napi/neural-network-runtime-guidelines.md | 8 +- .../apis/js-apis-devicestatus-cooperate.md | 42 +- .../reference/apis/js-apis-hiappevent.md | 12 +- .../apis/js-apis-hiviewdfx-hiappevent.md | 8 +- .../reference/apis/js-apis-http.md | 50 +- .../reference/apis/js-apis-net-connection.md | 14 +- .../reference/apis/js-apis-net-ethernet.md | 2 +- .../reference/apis/js-apis-pointer.md | 356 +- .../apis/js-apis-resource-manager.md | 2967 ++++++++++------- .../reference/apis/js-apis-sim.md | 4 +- .../reference/apis/js-apis-socket.md | 4 +- .../errorcodes/errorcode-hiappevent.md | 16 +- .../subsys-dfx-hisysevent-listening.md | 423 ++- .../subsys-dfx-hisysevent-logging-config.md | 7 +- .../subsystems/subsys-dfx-hisysevent-query.md | 540 +-- .../changelogs-netstack.md | 43 + .../OpenHarmony_4.0.10.3/changelogs-dfx.md | 22 + .../changelogs-telephoy.md | 122 + 35 files changed, 2954 insertions(+), 1802 deletions(-) create mode 100644 en/release-notes/changelogs/OpenHarmony_4.0.10.2/changelogs-netstack.md create mode 100644 en/release-notes/changelogs/OpenHarmony_4.0.10.3/changelogs-dfx.md create mode 100644 en/release-notes/changelogs/OpenHarmony_4.0.7.2/changelogs-telephoy.md diff --git a/en/application-dev/connectivity/http-request.md b/en/application-dev/connectivity/http-request.md index 1bb784cf96..ef77a42f6b 100644 --- a/en/application-dev/connectivity/http-request.md +++ b/en/application-dev/connectivity/http-request.md @@ -18,7 +18,7 @@ The following table provides only a simple description of the related APIs. For | ----------------------------------------- | ----------------------------------- | | createHttp() | Creates an HTTP request. | | request() | Initiates an HTTP request to a given URL. | -| request2()10+ | Initiates an HTTP network request based on the URL and returns a streaming response.| +| requestInStream()10+ | Initiates an HTTP network request to a given URL and returns a streaming response.| | destroy() | Destroys an HTTP request. | | on(type: 'headersReceive') | Registers an observer for HTTP Response Header events. | | off(type: 'headersReceive') | Unregisters the observer for HTTP Response Header events.| @@ -27,8 +27,8 @@ The following table provides only a simple description of the related APIs. For | off\('dataReceive'\)10+ | Unregisters the observer for events indicating receiving of HTTP streaming responses. | | on\('dataEnd'\)10+ | Registers an observer for events indicating completion of receiving HTTP streaming responses. | | off\('dataEnd'\)10+ | Unregisters the observer for events indicating completion of receiving HTTP streaming responses.| -| on\('dataProgress'\)10+ | Registers an observer for events indicating progress of receiving HTTP streaming responses. | -| off\('dataProgress'\)10+ | Unregisters the observer for events indicating progress of receiving HTTP streaming responses.| +| on\('dataReceiveProgress'\)10+ | Registers an observer for events indicating progress of receiving HTTP streaming responses. | +| off\('dataReceiveProgress'\)10+ | Unregisters the observer for events indicating progress of receiving HTTP streaming responses.| ## How to Develop request APIs @@ -53,6 +53,7 @@ httpRequest.on('headersReceive', (header) => { }); httpRequest.request( // Customize EXAMPLE_URL in extraData on your own. It is up to you whether to add parameters to the URL. + "EXAMPLE_URL", { method: http.RequestMethod.POST, // Optional. The default value is http.RequestMethod.GET. // You can add header fields based on service requirements. @@ -81,7 +82,7 @@ httpRequest.request( // Call the destroy() method to release resources after HttpRequest is complete. httpRequest.destroy(); } else { - console.info('error:' + JSON.stringify(err)); + console.error('error:' + JSON.stringify(err)); // Unsubscribe from HTTP Response Header events. httpRequest.off('headersReceive'); // Call the destroy() method to release resources after HttpRequest is complete. @@ -91,12 +92,12 @@ httpRequest.request( ); ``` -## How to Develop request2 APIs +## How to Develop requestInStream APIs 1. Import the **http** namespace from **@ohos.net.http.d.ts**. 2. Call **createHttp()** to create an **HttpRequest** object. 3. Depending on your need, call **on()** of the **HttpRequest** object to subscribe to HTTP response header events as well as events indicating receiving of HTTP streaming responses, progress of receiving HTTP streaming responses, and completion of receiving HTTP streaming responses. -4. Call **request2()** to initiate a network request. You need to pass in the URL and optional parameters of the HTTP request. +4. Call **requestInStream()** to initiate a network request. You need to pass in the URL and optional parameters of the HTTP request. 5. Parse the returned response code as needed. 6. Call **off()** of the **HttpRequest** object to unsubscribe from the related events. 7. Call **httpRequest.destroy()** to release resources after the request is processed. @@ -122,11 +123,11 @@ httpRequest.on('dataEnd', () => { console.info('No more data in response, data receive end'); }); // Subscribe to events indicating progress of receiving HTTP streaming responses. -httpRequest.on('dataProgress', (data) => { - console.log("dataProgress receiveSize:" + data.receiveSize + ", totalSize:" + data.totalSize); +httpRequest.on('dataReceiveProgress', (data) => { + console.log("dataReceiveProgress receiveSize:" + data.receiveSize + ", totalSize:" + data.totalSize); }); -httpRequest.request2( +httpRequest.requestInStream( // Customize EXAMPLE_URL in extraData on your own. It is up to you whether to add parameters to the URL. "EXAMPLE_URL", { @@ -146,14 +147,14 @@ httpRequest.request2( readTimeout: 60000, // Optional. The default value is 60000, in ms. If a large amount of data needs to be transmitted, you are advised to set this parameter to a larger value to ensure normal data transmission. usingProtocol: http.HttpProtocol.HTTP1_1, // Optional. The default protocol type is automatically specified by the system. }, (err, data) => { - console.info('error:' + JSON.stringify(err)); + console.error('error:' + JSON.stringify(err)); console.info('ResponseCode :' + JSON.stringify(data)); // Unsubscribe from HTTP Response Header events. httpRequest.off('headersReceive'); // Unregister the observer for events indicating receiving of HTTP streaming responses. httpRequest.off('dataReceive'); // Unregister the observer for events indicating progress of receiving HTTP streaming responses. - httpRequest.off('dataProgress'); + httpRequest.off('dataReceiveProgress'); // Unregister the observer for events indicating completion of receiving HTTP streaming responses. httpRequest.off('dataEnd'); // Call the destroy() method to release resources after HttpRequest is complete. @@ -161,10 +162,3 @@ httpRequest.request2( } ); ``` - -## Samples - -The following sample is provided to help you better understand how to develop the HTTP data request feature: - -- [`Http`: Data Request (ArkTS) (API9)](https://gitee.com/openharmony/applications_app_samples/tree/master/code/BasicFeature/Connectivity/Http) -- [HTTP Communication (ArkTS) (API9)](https://gitee.com/openharmony/codelabs/tree/master/NetworkManagement/SmartChatEtsOH) diff --git a/en/application-dev/connectivity/net-connection-manager.md b/en/application-dev/connectivity/net-connection-manager.md index fba108e73c..20f6660d77 100644 --- a/en/application-dev/connectivity/net-connection-manager.md +++ b/en/application-dev/connectivity/net-connection-manager.md @@ -5,6 +5,7 @@ The Network Connection Management module provides basic network management capabilities, including management of Wi-Fi/cellular/Ethernet connection priorities, network quality evaluation, subscription to network connection status changes, query of network connection information, and DNS resolution. > **NOTE** +> > To maximize the application running efficiency, most API calls are called asynchronously in callback or promise mode. The following code examples use the callback mode. For details about the APIs, see [sms API Reference](../reference/apis/js-apis-net-connection.md). ## Basic Concepts diff --git a/en/application-dev/connectivity/net-ethernet.md b/en/application-dev/connectivity/net-ethernet.md index 18f20a7fd7..698894e604 100644 --- a/en/application-dev/connectivity/net-ethernet.md +++ b/en/application-dev/connectivity/net-ethernet.md @@ -5,6 +5,7 @@ The Ethernet Connection module allows a device to access the Internet through a network cable. After a device is connected to the Ethernet through a network cable, the device can obtain a series of network attributes, such as the dynamically allocated IP address, subnet mask, gateway, and DNS. You can manually configure and obtain the network attributes of the device in static mode. > **NOTE** +> > To maximize the application running efficiency, most API calls are called asynchronously in callback or promise mode. The following code examples use the callback mode. For details about the APIs, see [sms API Reference](../reference/apis/js-apis-net-ethernet.md). ## **Constraints** diff --git a/en/application-dev/connectivity/net-sharing.md b/en/application-dev/connectivity/net-sharing.md index 4072217d9c..6ab131906c 100644 --- a/en/application-dev/connectivity/net-sharing.md +++ b/en/application-dev/connectivity/net-sharing.md @@ -5,6 +5,7 @@ The Network Sharing module allows you to share your device's Internet connection with other connected devices by means of Wi-Fi hotspot, Bluetooth, and USB sharing. It also allows you to query the network sharing state and shared mobile data volume. > **NOTE** +> > To maximize the application running efficiency, most API calls are called asynchronously in callback or promise mode. The following code examples use the callback mode. For details about the APIs, see [sms API Reference](../reference/apis/js-apis-net-sharing.md). ## Basic Concepts diff --git a/en/application-dev/connectivity/net-statistics.md b/en/application-dev/connectivity/net-statistics.md index 47ec62ff15..2ed2d23f37 100644 --- a/en/application-dev/connectivity/net-statistics.md +++ b/en/application-dev/connectivity/net-statistics.md @@ -11,6 +11,7 @@ Its functions include: - Subscribing to traffic change events by NIC or UID > **NOTE** +> > To maximize the application running efficiency, most API calls are called asynchronously in callback or promise mode. The following code examples use the callback mode. For details about the APIs, see [Traffic Management](../reference/apis/js-apis-net-statistics.md). The following describes the development procedure specific to each application scenario. diff --git a/en/application-dev/connectivity/net-vpn.md b/en/application-dev/connectivity/net-vpn.md index adf38f9676..a93b00b932 100644 --- a/en/application-dev/connectivity/net-vpn.md +++ b/en/application-dev/connectivity/net-vpn.md @@ -5,6 +5,7 @@ A virtual private network (VPN) is a dedicated network established on a public network. On a VPN, the connection between any two nodes does not have an end-to-end physical link required by the traditional private network. Instead, user data is transmitted over a logical link because a VPN is a logical network deployed over the network platform (such as the Internet) provided by the public network service provider. > **NOTE** +> > To maximize the application running efficiency, most API calls are called asynchronously in callback or promise mode. The following code examples use the callback mode. For details about the APIs, see [Traffic Management](../reference/apis/js-apis-net-vpn.md). The following describes the development procedure specific to each application scenario. diff --git a/en/application-dev/connectivity/websocket-connection.md b/en/application-dev/connectivity/websocket-connection.md index 4c373011c4..b6ac11ae0a 100644 --- a/en/application-dev/connectivity/websocket-connection.md +++ b/en/application-dev/connectivity/websocket-connection.md @@ -1,6 +1,6 @@ # WebSocket Connection -## When to Use +## Introduction You can use WebSocket to establish a bidirectional connection between a server and a client. Before doing this, you need to use the **createWebSocket()** API to create a **WebSocket** object and then use the **connect()** API to connect to the server. If the connection is successful, the client will receive a callback of the **open** event. Then, the client can communicate with the server using the **send()** API. When the server sends a message to the client, the client will receive a callback of the **message** event. If the client no longer needs this connection, it can call the **close()** API to disconnect from the server. Then, the client will receive a callback of the **close** event. diff --git a/en/application-dev/dfx/Readme-EN.md b/en/application-dev/dfx/Readme-EN.md index 5a1b6326ba..c40f752d8f 100644 --- a/en/application-dev/dfx/Readme-EN.md +++ b/en/application-dev/dfx/Readme-EN.md @@ -1,7 +1,6 @@ # DFX - [Development of Application Event Logging](hiappevent-guidelines.md) -- [Development of Performance Tracing](hitracemeter-guidelines.md) - [Development of Distributed Call Chain Tracing](hitracechain-guidelines.md) - [HiLog Development (Native)](hilog-guidelines.md) - Performance Tracing diff --git a/en/application-dev/dfx/appfreeze-guidelines.md b/en/application-dev/dfx/appfreeze-guidelines.md index 05b52c4d80..4984c95e21 100644 --- a/en/application-dev/dfx/appfreeze-guidelines.md +++ b/en/application-dev/dfx/appfreeze-guidelines.md @@ -1,6 +1,6 @@ # Application Freeze (appfreeze) Log Analysis -## Introduction +## Overview Application freeze (appfreeze) means that an application does not respond to user operations (for example, clicking) within a given period of time. OpenHarmony provides a mechanism for detecting appfreeze faults and generates appfreeze logs for fault analysis. diff --git a/en/application-dev/dfx/apprecovery-guidelines.md b/en/application-dev/dfx/apprecovery-guidelines.md index 284de5ca6d..e8c1b81975 100644 --- a/en/application-dev/dfx/apprecovery-guidelines.md +++ b/en/application-dev/dfx/apprecovery-guidelines.md @@ -1,6 +1,6 @@ # Application Recovery Development -## When to Use +## Overview During application running, some unexpected behaviors are inevitable. For example, unprocessed exceptions and errors are thrown, and the call or running constraints of the recovery framework are violated. diff --git a/en/application-dev/dfx/cppcrash-guidelines.md b/en/application-dev/dfx/cppcrash-guidelines.md index c3ca07a4dc..1513651878 100644 --- a/en/application-dev/dfx/cppcrash-guidelines.md +++ b/en/application-dev/dfx/cppcrash-guidelines.md @@ -1,6 +1,6 @@ # Process Crash (cppcrash) Log Analysis -## Introduction +## Overview A process crash refers to a C/C++ runtime crash. The FaultLogger module of OpenHarmony provides capabilities such as process crash detection, log collection, log storage, and log reporting, helping you to locate faults more effectively. diff --git a/en/application-dev/dfx/errormanager-guidelines.md b/en/application-dev/dfx/errormanager-guidelines.md index 4679cfcfc7..14d7735d73 100644 --- a/en/application-dev/dfx/errormanager-guidelines.md +++ b/en/application-dev/dfx/errormanager-guidelines.md @@ -1,6 +1,6 @@ # Development of Error Manager -## When to Use +## Overview If coding specification issues or errors exist in the code of an application, the application may encounter unexpected errors, for example, uncaught exceptions or application lifecycle timeouts, while it is running. In such a case, the application may exit unexpectedly. Error logs, however, are usually stored on users' local storage, making it inconvenient to locate faults. With the APIs provided by the **errorManager** module, your application will be able to report related errors and logs to your service platform for fault locating before it exits. diff --git a/en/application-dev/dfx/hiappevent-guidelines.md b/en/application-dev/dfx/hiappevent-guidelines.md index d21d4e3fa9..6b0f4dd1cb 100644 --- a/en/application-dev/dfx/hiappevent-guidelines.md +++ b/en/application-dev/dfx/hiappevent-guidelines.md @@ -1,6 +1,6 @@ # Development of Application Event Logging -## Introduction +## Overview A traditional log system aggregates log information generated by all applications running on the entire device, making it difficult to identify key information in the log. Therefore, an effective logging mechanism is needed to evaluate mission-critical information, for example, number of visits, number of daily active users, user operation habits, and key factors that affect application usage. diff --git a/en/application-dev/dfx/hilog-guidelines.md b/en/application-dev/dfx/hilog-guidelines.md index 25b4a7f9cc..45d46c01fb 100644 --- a/en/application-dev/dfx/hilog-guidelines.md +++ b/en/application-dev/dfx/hilog-guidelines.md @@ -1,6 +1,6 @@ # HiLog Development (Native) -## Introduction +## Overview HiLog is the log system of OpenHarmony that provides logging for the system framework, services, and applications to record information on user operations and system running status. diff --git a/en/application-dev/dfx/hitracechain-guidelines.md b/en/application-dev/dfx/hitracechain-guidelines.md index affd260b05..44e2da92df 100644 --- a/en/application-dev/dfx/hitracechain-guidelines.md +++ b/en/application-dev/dfx/hitracechain-guidelines.md @@ -1,6 +1,6 @@ # Development of Distributed Call Chain Tracing -## Introduction +## Overview The hiTraceChain module provides APIs to implement call chain tracing throughout a service process. This can help you quickly obtain the run log for the call chain of a specified service process and locate faults in inter-device, inter-process, or inter-thread communications. diff --git a/en/application-dev/dfx/hitracemeter-guidelines.md b/en/application-dev/dfx/hitracemeter-guidelines.md index ed99e4e89d..195aae4b2d 100644 --- a/en/application-dev/dfx/hitracemeter-guidelines.md +++ b/en/application-dev/dfx/hitracemeter-guidelines.md @@ -1,6 +1,6 @@ # Development of Performance Tracing (ArkTS) -## Introduction +## Overview hiTraceMeter provides APIs for system performance tracing. You can call the APIs provided by the hiTraceMeter module in your own service logic to effectively track service processes and check the system performance. @@ -21,7 +21,7 @@ hiTraceMeter provides APIs for system performance tracing. You can call the APIs ## Available APIs -The performance tracing APIs are provided by the **hiTraceMeter** module. For details, see [API Reference](../reference/apis/js-apis-hitracemeter.md). +The performance tracing APIs are provided by the **hiTraceMeter** module. For details, see [API Reference]( ../reference/apis/js-apis-hitracemeter.md). **APIs for performance tracing** @@ -35,60 +35,16 @@ The performance tracing APIs are provided by the **hiTraceMeter** module. For de In this example, distributed call chain tracing begins when the application startup execution page is loaded and stops when the service usage is completed. -1. Create a JS application project. In the displayed **Project** window, choose **entry** > **src** > **main** > **js** > **default** > **pages** > **index**, and double-click **index.js**. Add the code to implement performance tracing upon page loading. The sample code is as follows: - - ```js - import hiTraceMeter from '@ohos.hiTraceMeter' - - export default { - data: { - title: "" - }, - onInit() { - this.title = this.$t('strings.world'); - - // Start trace tasks with the same name concurrently. - hiTraceMeter.startTrace("business", 1); - // Keep the service process running. - console.log(`business running`); - hiTraceMeter.startTrace("business", 2); // Start the second trace task with the same name while the first task is still running. The tasks are running concurrently and therefore their taskId must be different. - // Keep the service process running. - console.log(`business running`); - hiTraceMeter.finishTrace("business", 1); - // Keep the service process running. - console.log(`business running`); - hiTraceMeter.finishTrace("business", 2); - - // Start trace tasks with the same name in serial mode. - hiTraceMeter.startTrace("business", 1); - // Keep the service process running. - console.log(`business running`); - hiTraceMeter.finishTrace("business", 1); // End the first trace task. - // Keep the service process running. - console.log(`business running`); - hiTraceMeter.startTrace("business", 1); // Start the second trace task with the same name in serial mode. - // Keep the service process running. - console.log(`business running`); - - let traceCount = 3; - hiTraceMeter.traceByValue("myTestCount", traceCount); - traceCount = 4; - hiTraceMeter.traceByValue("myTestCount", traceCount); - hiTraceMeter.finishTrace("business", 1); - } - } - ``` - -2. Create an ArkTs application project. In the displayed **Project** window, choose **entry** > **src** > **main** > **ets** > **pages** > **index**, and double-click **index.js**. Add the code to implement performance tracing upon page loading. For example, if the name of the trace task is **HITRACE\_TAG\_APP**, the sample code is as follows: - +1. Create an ArkTS application project. In the displayed **Project** window, choose **entry** > **src** > **main** > **ets** > **pages** > **index**, and double-click **index.js**. Add the code to implement performance tracing upon page loading. For example, if the name of the trace task is **HITRACE\_TAG\_APP**, the sample code is as follows: + ```ts import hitrace from '@ohos.hiTraceMeter'; - + @Entry @Component struct Index { @State message: string = 'Hello World'; - + build() { Row() { Column() { @@ -97,7 +53,7 @@ In this example, distributed call chain tracing begins when the application star .fontWeight(FontWeight.Bold) .onClick(() => { this.message = 'Hello ArkUI'; - + // Start trace tasks with the same name concurrently. hitrace.startTrace("HITRACE_TAG_APP", 1001); // Keep the service process running. @@ -107,7 +63,7 @@ In this example, distributed call chain tracing begins when the application star hitrace.startTrace("HITRACE_TAG_APP", 1002); // Keep the service process running. console.log(`HITRACE_TAG_APP running`); - + hitrace.finishTrace("HITRACE_TAG_APP", 1001); hitrace.finishTrace("HITRACE_TAG_APP", 1002); @@ -143,7 +99,7 @@ In this example, distributed call chain tracing begins when the application star ``` 3. Click the run button on the application page. Then, run the following commands in sequence in shell: - + ```shell hdc shell hitrace --trace_begin app diff --git a/en/application-dev/dfx/hitracemeter-native-guidelines.md b/en/application-dev/dfx/hitracemeter-native-guidelines.md index bb0274f7c4..912ec1c5f8 100644 --- a/en/application-dev/dfx/hitracemeter-native-guidelines.md +++ b/en/application-dev/dfx/hitracemeter-native-guidelines.md @@ -1,6 +1,6 @@ # Development of Performance Tracing (Native) -## Introduction +## Overview hiTraceMeter provides APIs for system performance tracing. You can call the APIs provided by the hiTraceMeter module in your own service logic to effectively track service processes and check the system performance. > **NOTE** diff --git a/en/application-dev/napi/neural-network-runtime-guidelines.md b/en/application-dev/napi/neural-network-runtime-guidelines.md index 344ae4f1d6..974ccc5baf 100644 --- a/en/application-dev/napi/neural-network-runtime-guidelines.md +++ b/en/application-dev/napi/neural-network-runtime-guidelines.md @@ -1,4 +1,4 @@ -# Connecting the Neural Network Runtime to an AI Inference Framework +# Development Guide for Connecting the Neural Network Runtime to an AI Inference Framework ## When to Use @@ -19,8 +19,7 @@ The environment requirements for the Neural Network Runtime are as follows: - Development environment: Ubuntu 18.04 or later. - Access device: a standard device running OpenHarmony. The built-in hardware accelerator driver has been connected to the Neural Network Runtime through an HDI API. -The Neural Network Runtime is opened to external systems through OpenHarmony Native APIs. Therefore, you need to use the Native development suite of the OpenHarmony to compile Neural Network Runtime applications. - +The Neural Network Runtime is opened to external systems through OpenHarmony Native APIs. Therefore, you need to use the Native development suite of the OpenHarmony to compile Neural Network Runtime applications. ### Environment Setup @@ -33,7 +32,6 @@ unzip native-linux-{version number}.zip ``` The directory structure after decompression is as follows. The content in the directory may vary depending on version iteration. Use the Native APIs of the latest version. - ```text native/ ─ ─ build // Cross-compilation toolchain @@ -488,4 +486,4 @@ The development process of the Neural Network Runtime consists of three phases: ```shell rm /data/local/tmp/*nncache - ``` \ No newline at end of file + ``` diff --git a/en/application-dev/reference/apis/js-apis-devicestatus-cooperate.md b/en/application-dev/reference/apis/js-apis-devicestatus-cooperate.md index 737c91f003..bae8a5884f 100644 --- a/en/application-dev/reference/apis/js-apis-devicestatus-cooperate.md +++ b/en/application-dev/reference/apis/js-apis-devicestatus-cooperate.md @@ -4,9 +4,9 @@ The **cooperate** module implements screen hopping for two or more networked dev > **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 @@ -26,7 +26,7 @@ Prepares for screen hopping. This API uses an asynchronous callback to return th | Name | Type | Mandatory | Description | | -------- | ------------------------- | ---- | --------------------------- | -| callback | AsyncCallback<void> | Yes|Callback used to return the result. | +| callback | AsyncCallback<void> | Yes|Callback used to return the result. If the operation is successful, **err** is **undefined**. Otherwise, **err** is an error object. | **Example** @@ -56,7 +56,7 @@ Prepares for screen hopping. This API uses a promise to return the result. | Parameters | Description | | ------------------- | ------------------------------- | -| Promise<void> | Promise used to return the result.| +| Promise<void> | Promise that returns no value.| @@ -75,7 +75,6 @@ try { ``` - ## cooperate.unprepare unprepare(callback: AsyncCallback<void>): void; @@ -86,7 +85,7 @@ Cancels the preparation for screen hopping. This API uses an asynchronous callba | Name | Type | Mandatory| Description | | -------- | ------------------------- | ---- | ------------------------------------------ | -| callback | AsyncCallback<void> | Yes | Callback used to return the result.| +| callback | AsyncCallback<void> | Yes | Callback used to return the result. If the operation is successful, **err** is **undefined**. Otherwise, **err** is an error object.| **Example** @@ -104,8 +103,6 @@ try { } ``` - - ## cooperate.unprepare unprepare(): Promise<void>; @@ -118,7 +115,7 @@ Cancels the preparation for screen hopping. This API uses a promise to return th | Parameters | Description | | ------------------- | --------------------------------------------- | -| Promise<void> | Promise used to return the result.| +| Promise<void> | Promise that returns no value.| ```js try { @@ -133,7 +130,6 @@ try { ``` - ## cooperate.activate activate(targetNetworkId: string, inputDeviceId: number, callback: AsyncCallback<void>): void; @@ -148,7 +144,7 @@ Starts screen hopping. This API uses an asynchronous callback to return the resu | -------- | ---------------------------- | ---- | ---------------------------- | | targetNetworkId | string | Yes | Descriptor of the target device for screen hopping. | | inputDeviceId | number | Yes | Identifier of the input device for screen hopping.| -| callback | AsyncCallback<void> | Yes | Callback used to return the result.| +| callback | AsyncCallback<void> | Yes | Callback used to return the result. If the operation is successful, **err** is **undefined**. Otherwise, **err** is an error object.| **Error codes** @@ -156,7 +152,7 @@ For details about the error codes, see [Screen Hopping Error Codes](../errorcode | ID| Error Message| | -------- | ---------------------------------------- | -| 20900001 | This error code is reported if the screen hopping status is abnormal when the screen hopping API is called. | +| 20900001 | Operation failed.| **Example** @@ -197,7 +193,7 @@ Starts screen hopping. This API uses a promise to return the result. | Name | Description | | ---------------------- | ------------------------------- | -| Promise<void> | Promise used to return the result. | +| Promise<void> | Promise that returns no value. | **Error codes** @@ -205,7 +201,7 @@ For details about the error codes, see [Screen Hopping Error Codes](../errorcode | ID| Error Message| | -------- | ---------------------------------------- | -| 20900001 | This error code is reported if the screen hopping status is abnormal when the screen hopping API is called. | +| 20900001 | Operation failed. | **Example** @@ -235,8 +231,8 @@ Stops screen hopping. This API uses an asynchronous callback to return the resul | Name | Type | Mandatory | Description | | -------- | ---------------------------- | ---- | ---------------------------- | -| isUnchained | boolean | Yes| Whether to disable the cross-device link.| -| callback | AsyncCallback<void> | Yes | Callback used to return the result. | +| isUnchained | boolean | Yes| Whether to disable the cross-device link.
The value **true** means to disable the cross-device link, and the value **false** means the opposite.| +| callback | AsyncCallback<void> | Yes | Callback used to return the result. If the operation is successful, **err** is **undefined**. Otherwise, **err** is an error object.| @@ -268,7 +264,7 @@ Stops screen hopping. This API uses a promise to return the result. | Name | Type | Mandatory| Description | | ----------- | ------- | ---- | ------------------ | -| isUnchained | boolean | Yes | Whether to disable the cross-device link.| +| isUnchained | boolean | Yes | Whether to disable the cross-device link.
The value **true** means to disable the cross-device link, and the value **false** means the opposite.| @@ -276,7 +272,7 @@ Stops screen hopping. This API uses a promise to return the result. | Name | Description | | -------- | ---------------------------- | -| Promise<void> | Promise used to return the result. | +| Promise<void> | Promise that returns no value. | @@ -307,7 +303,7 @@ Obtains the screen hopping status of the target device. This API uses an asynchr | Name | Type | Mandatory | Description | | -------- | --------- | ---- | ---------------------------- | | networkId | string | Yes | Descriptor of the target device for screen hopping. | -| callback | AsyncCallback<boolean> | Yes | Callback used to return the result.| +| callback | AsyncCallback<boolean> | Yes | Callback used to return the result. The value **true** indicates that screen hopping is enabled, and the value **false** indicates the opposite.| **Example** @@ -336,9 +332,9 @@ Obtains the screen hopping status of the target device. This API uses a promise **Parameters** -| Name | Type | Mandatory | Description | -| -------- | --------- | ---- | ---------------------------- | -| networkId | string | Yes | Descriptor of the target device for screen hopping. | +| Name | Type | Mandatory | Description | +| -------- | --------- | ---- | ---------------------------- | +| networkId | string | Yes | Descriptor of the target device for screen hopping. | @@ -346,7 +342,7 @@ Obtains the screen hopping status of the target device. This API uses a promise | Parameters | Description | | ------------------- | ------------------------------- | -| Promise<boolean> | Promise used to return the result.| +| Promise<boolean> | Promise used to return the result. The value **true** indicates that screen hopping is enabled, and the value **false** indicates the opposite.| diff --git a/en/application-dev/reference/apis/js-apis-hiappevent.md b/en/application-dev/reference/apis/js-apis-hiappevent.md index e2ff3f6fa9..ed0fdfc9c2 100644 --- a/en/application-dev/reference/apis/js-apis-hiappevent.md +++ b/en/application-dev/reference/apis/js-apis-hiappevent.md @@ -4,7 +4,7 @@ The **hiAppEvent** module provides the application event logging functions, such > **NOTE** > -> - The APIs provided by this module are deprecated since API version 9. You are advised to use [`@ohos.hiviewdfx.hiAppEvent`](js-apis-hiviewdfx-hiappevent.md) instead. +> - The APIs provided by this module are deprecated since API version 9. You are advised to use [`@ohos.hiviewdfx.hiAppEvent`](js-apis-hiviewdfx-hiappevent.md). > - 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. @@ -20,7 +20,7 @@ Before using application event logging, you need to understand the requirements **Event Name** -An event name is a string that contains a maximum of 48 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 (\_). +An event name is a string that contains a maximum of 48 characters, including digits (0 to 9), letters (a to z), and underscores (\_). It must start with a letter or dollar sign ($) and cannot end with an underscore (_). **Event Type** @@ -30,8 +30,8 @@ An event type is an enumerated value of [EventType](#eventtype). An event parameter is an object in key-value pair format, where the key is the parameter name and the value is the parameter value. The requirements are as follows: -- A parameter name is a string that contains a maximum of 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 (\_). -- The parameter value can be of the string, number, boolean, or array type. +- A parameter name is a string that contains a maximum of 16 characters, including digits (0 to 9), letters (a to z), and underscores (\_). It must start with a letter or dollar sign ($) and cannot end with an underscore (_). +- A parameter value can be of the string, number, boolean, or array type. - 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. @@ -156,12 +156,12 @@ Provides the configuration items for application event logging. | Name | Type | Mandatory| Description | | ---------- | ------- | ---- | ------------------------------------------------------------ | | disable | boolean | No | Application event logging switch. The value **true** means to disable the application event logging function, and the value **false** means the opposite.| -| maxStorage | string | No | Maximum size of the event file storage directory. The default value is 10M. If the specified size is exceeded, the oldest event logging files in the directory will be deleted to free up space.| +| maxStorage | string | No | Maximum size of the event file storage directory. The default value is **10M**. If the specified size is exceeded, the oldest event logging files in the directory will be deleted to free up space.| ## EventType -Enumerates event types. +Enumerates the event types. **System capability**: SystemCapability.HiviewDFX.HiAppEvent diff --git a/en/application-dev/reference/apis/js-apis-hiviewdfx-hiappevent.md b/en/application-dev/reference/apis/js-apis-hiviewdfx-hiappevent.md index 03cad26cfe..41d5566ed0 100644 --- a/en/application-dev/reference/apis/js-apis-hiviewdfx-hiappevent.md +++ b/en/application-dev/reference/apis/js-apis-hiviewdfx-hiappevent.md @@ -122,10 +122,10 @@ Defines parameters for an **AppEventInfo** object. | Name | Type | Mandatory| Description | | --------- | ----------------------- | ---- | ------------------------------------------------------------ | -| domain | string | Yes | Event domain. Event domain name, which 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 (_).| -| name | string | Yes | Event name. Event name, which 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 and cannot end with an underscore (_).| +| 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 (_).| +| 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. | -| params | object | Yes | Event parameter object, which consists of a parameter name and a parameter value. The specifications are as follows:
- 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 and cannot end with an underscore (_).
- 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.
- 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:
- 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 (_).
- 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.
- The maximum number of parameters is 32. If this limit is exceeded, excess parameters will be discarded.| ## hiAppEvent.configure @@ -436,7 +436,7 @@ hiAppEvent.clearData(); ## EventType -Enumerates event types. +Enumerates the event types. **System capability**: SystemCapability.HiviewDFX.HiAppEvent diff --git a/en/application-dev/reference/apis/js-apis-http.md b/en/application-dev/reference/apis/js-apis-http.md index 50069e9932..6f8d2c742f 100644 --- a/en/application-dev/reference/apis/js-apis-http.md +++ b/en/application-dev/reference/apis/js-apis-http.md @@ -86,7 +86,7 @@ Creates an HTTP request. You can use this API to initiate or destroy an HTTP req | Type | Description | | :---------- | :----------------------------------------------------------- | -| HttpRequest | An **HttpRequest** object, which contains the **request**, **request2**, **destroy**, **on**, or **off** method.| +| HttpRequest | An **HttpRequest** object, which contains the **request**, **requestInStream**, **destroy**, **on**, or **off** method.| **Example** @@ -364,9 +364,9 @@ Destroys an HTTP request. httpRequest.destroy(); ``` -### request210+ +### requestInStream10+ -request2(url: string, callback: AsyncCallback\): void +requestInStream(url: string, callback: AsyncCallback\): void Initiates an HTTP request containing specified options to a given URL. This API uses an asynchronous callback to return the result, which is a streaming response. @@ -424,18 +424,18 @@ Initiates an HTTP request containing specified options to a given URL. This API **Example** ```js -httpRequest.request2("EXAMPLE_URL", (err, data) => { +httpRequest.requestInStream("EXAMPLE_URL", (err, data) => { if (!err) { - console.info("request2 OK! ResponseCode is " + JSON.stringify(data)); + console.info("requestInStream OK! ResponseCode is " + JSON.stringify(data)); } else { - console.info("request2 ERROR : err = " + JSON.stringify(err)); + console.info("requestInStream ERROR : err = " + JSON.stringify(err)); } }) ``` -### request210+ +### requestInStream10+ -request2(url: string, options: HttpRequestOptions, callback: AsyncCallback\): void +requestInStream(url: string, options: HttpRequestOptions, callback: AsyncCallback\): void Initiates an HTTP request containing specified options to a given URL. This API uses an asynchronous callback to return the result, which is a streaming response. @@ -494,7 +494,7 @@ Initiates an HTTP request containing specified options to a given URL. This API **Example** ```js -httpRequest.request2("EXAMPLE_URL", +httpRequest.requestInStream("EXAMPLE_URL", { method: http.RequestMethod.GET, header: { @@ -504,16 +504,16 @@ httpRequest.request2("EXAMPLE_URL", connectTimeout: 60000 }, (err, data) => { if (!err) { - console.info("request2 OK! ResponseCode is " + JSON.stringify(data)); + console.info("requestInStream OK! ResponseCode is " + JSON.stringify(data)); } else { - console.info("request2 ERROR : err = " + JSON.stringify(err)); + console.info("requestInStream ERROR : err = " + JSON.stringify(err)); } }) ``` -### request210+ +### requestInStream10+ -request2(url: string, options? : HttpRequestOptions): Promise\ +requestInStream(url: string, options? : HttpRequestOptions): Promise\ Initiates an HTTP request containing specified options to a given URL. This API uses a promise to return the result, which is a streaming response. @@ -577,7 +577,7 @@ Initiates an HTTP request containing specified options to a given URL. This API **Example** ```js -let promise = httpRequest.request2("EXAMPLE_URL", { +let promise = httpRequest.requestInStream("EXAMPLE_URL", { method: http.RequestMethod.GET, connectTimeout: 60000, readTimeout: 60000, @@ -586,9 +586,9 @@ let promise = httpRequest.request2("EXAMPLE_URL", { } }); promise.then((data) => { - console.info("request2 OK!" + JSON.stringify(data)); + console.info("requestInStream OK!" + JSON.stringify(data)); }).catch((err) => { - console.info("request2 ERROR : err = " + JSON.stringify(err)); + console.info("requestInStream ERROR : err = " + JSON.stringify(err)); }); ``` @@ -815,9 +815,9 @@ Unregisters the observer for events indicating completion of receiving HTTP stre httpRequest.off('dataEnd'); ``` -### on('dataProgress')10+ +### on('dataReceiveProgress')10+ -on(type: 'dataProgress', callback: Callback\<{ receiveSize: number, totalSize: number }\>): void +on(type: 'dataReceiveProgress', callback: Callback\<{ receiveSize: number, totalSize: number }\>): void Registers an observer for events indicating progress of receiving HTTP streaming responses. @@ -830,20 +830,20 @@ Registers an observer for events indicating progress of receiving HTTP streaming | Name | Type | Mandatory| Description | | -------- | ----------------------- | ---- | --------------------------------- | -| type | string | Yes | Event type. The value is **dataProgress**.| +| type | string | Yes | Event type. The value is **dataReceiveProgress**.| | callback | AsyncCallback\<{ receiveSize: number, totalSize: number }\> | Yes | Callback used to return the result.
- **receiveSize**: number of received bytes.
- **totalSize**: total number of bytes to be received.| **Example** ```js -httpRequest.on('dataProgress', (data) => { - console.info('dataProgress:' + JSON.stringify(data)); +httpRequest.on('dataReceiveProgress', (data) => { + console.info('dataReceiveProgress:' + JSON.stringify(data)); }); ``` -### off('dataProgress')10+ +### off('dataReceiveProgress')10+ -off(type: 'dataProgress', callback?: Callback\<{ receiveSize: number, totalSize: number }\>): void +off(type: 'dataReceiveProgress', callback?: Callback\<{ receiveSize: number, totalSize: number }\>): void Unregisters the observer for events indicating progress of receiving HTTP streaming responses. @@ -856,13 +856,13 @@ Unregisters the observer for events indicating progress of receiving HTTP stream | Name | Type | Mandatory| Description | | -------- | ------------------ | ---- | -------------------------------------- | -| type | string | Yes | Event type. The value is **dataProgress**.| +| type | string | Yes | Event type. The value is **dataReceiveProgress**.| | callback | Callback\<{ receiveSize: number, totalSize: number }\> | No | Callback used to return the result. | **Example** ```js -httpRequest.off('dataProgress'); +httpRequest.off('dataReceiveProgress'); ``` ## HttpRequestOptions6+ diff --git a/en/application-dev/reference/apis/js-apis-net-connection.md b/en/application-dev/reference/apis/js-apis-net-connection.md index 0bd9b71642..0dc717e3b5 100644 --- a/en/application-dev/reference/apis/js-apis-net-connection.md +++ b/en/application-dev/reference/apis/js-apis-net-connection.md @@ -158,7 +158,7 @@ Obtains the global HTTP proxy configuration of the network. This API uses an asy | Name | Type | Mandatory| Description | | -------- | --------------------------------------- | ---- | ------------------------------------------------------------ | -| callback | AsyncCallback\<[HttpProxy](#httpproxy)> | Yes | Callback used to return the result. If the global HTTP proxy configuration of the network is obtained successfully, **error** is **undefined** and **data** is the global HTTP proxy configuration. Otherwise, **error** is an error object.| +| callback | AsyncCallback\<[HttpProxy](#httpproxy10)> | Yes | Callback used to return the result. If the global HTTP proxy configuration of the network is obtained successfully, **error** is **undefined** and **data** is the global HTTP proxy configuration. Otherwise, **error** is an error object.| **Error codes** @@ -192,7 +192,7 @@ Obtains the global HTTP proxy configuration of the network. This API uses a prom | Type | Description | | --------------------------------- | ------------------------------------- | -| Promise\<[HttpProxy](#httpproxy)> | Promise used to return the result.| +| Promise\<[HttpProxy](#httpproxy10)> | Promise used to return the result.| **Error codes** @@ -229,7 +229,7 @@ Sets the global HTTP proxy configuration of the network. This API uses an asynch | Name | Type | Mandatory| Description | | --------- | ----------------------- | ---- | ------------------------------------------------------------ | -| httpProxy | [HttpProxy](#httpproxy) | Yes | Global HTTP proxy configuration of the network. | +| httpProxy | [HttpProxy](#httpproxy10) | Yes | Global HTTP proxy configuration of the network. | | callback | AsyncCallback\ | Yes | Callback used to return the result. If the global HTTP proxy configuration of the network is set successfully, **error** is **undefined**. Otherwise, **error** is an error object.| **Error codes** @@ -274,7 +274,7 @@ Sets the global HTTP proxy configuration of the network. This API uses a promise | Name | Type | Mandatory| Description | | --------- | ------------------------------------------------------------ | ---- | ---------------- | -| httpProxy | [HttpProxy](#httpproxy) | Yes | Global HTTP proxy configuration of the network.| +| httpProxy | [HttpProxy](#httpproxy10) | Yes | Global HTTP proxy configuration of the network.| **Return value** @@ -324,7 +324,7 @@ This API uses an asynchronous callback to return the result. | Name | Type | Mandatory| Description | | -------- | -------------------------------------- | ---- | ------------------------------------------------------------ | -| callback | AsyncCallback<[HttpProxy](#httpproxy)> | Yes | Callback used to return the result. If the global HTTP proxy configuration of the network is obtained successfully, **error** is **undefined** and **data** is the global HTTP proxy configuration. Otherwise, **error** is an error object.| +| callback | AsyncCallback<[HttpProxy](#httpproxy10)> | Yes | Callback used to return the result. If the global HTTP proxy configuration of the network is obtained successfully, **error** is **undefined** and **data** is the global HTTP proxy configuration. Otherwise, **error** is an error object.| **Error codes** @@ -347,7 +347,7 @@ connection.getDefaultHttpProxy((error, data) => { getDefaultHttpProxy(): Promise\; Obtains the default proxy configuration of the network. -If the global proxy is set, the global proxy configuration is returned. If [setAppNet](#connectionsetappnet) is used to bind the application to the network specified by [NetHandle](#nethandle), the proxy configuration of this network is returned. In other cases, the HTTP proxy configuration of the default network is returned. +If the global proxy is set, the global HTTP proxy configuration is returned. If [setAppNet](#connectionsetappnet) is used to bind the application to the network specified by [NetHandle](#nethandle), the HTTP proxy configuration of this network is returned. In other cases, the HTTP proxy configuration of the default network is returned. This API uses a promise to return the result. **System capability**: SystemCapability.Communication.NetManager.Core @@ -356,7 +356,7 @@ This API uses a promise to return the result. | Type | Description | | -------------------------------- | ----------------------------------------- | -| Promise<[HttpProxy](#httpproxy)> | Promise used to return the result.| +| Promise<[HttpProxy](#httpproxy10)> | Promise used to return the result.| **Error codes** diff --git a/en/application-dev/reference/apis/js-apis-net-ethernet.md b/en/application-dev/reference/apis/js-apis-net-ethernet.md index 21fdb44e40..e7aae4ef5e 100644 --- a/en/application-dev/reference/apis/js-apis-net-ethernet.md +++ b/en/application-dev/reference/apis/js-apis-net-ethernet.md @@ -486,7 +486,7 @@ Defines the network configuration for the Ethernet connection. | gateway | string | Yes| Gateway of the Ethernet connection. The value must be an IPv4 address, which is a 32-bit number displayed in dotted decimal notation and each 8-bit field ranges from 0 to 255. This parameter does not need to be configured in DHCP mode.| | netMask | string | Yes| Subnet mask of the Ethernet connection. The value must be an IPv4 address, which is a 32-bit number displayed in dotted decimal notation and each 8-bit field ranges from 0 to 255. This parameter does not need to be configured in DHCP mode.| | dnsServers | string | Yes| DNS server addresses of the Ethernet connection. The value must be an IPv4 address. This parameter does not need to be configured in DHCP mode. Multiple addresses are separated by commas (,).| -| httpProxy10+ | [HttpProxy](js-apis-net-connection.md#httpproxy) | No| HTTP proxy of the Ethernet connection. By default, no proxy is configured.| +| httpProxy10+ | [HttpProxy](js-apis-net-connection.md#httpproxy10) | No| HTTP proxy of the Ethernet connection. By default, no proxy is configured.| ## IPSetMode9+ diff --git a/en/application-dev/reference/apis/js-apis-pointer.md b/en/application-dev/reference/apis/js-apis-pointer.md index 9f949c10e7..39d64c64f8 100644 --- a/en/application-dev/reference/apis/js-apis-pointer.md +++ b/en/application-dev/reference/apis/js-apis-pointer.md @@ -850,7 +850,7 @@ Enumerates mouse pointer styles. | MIDDLE_BTN_SOUTH_EAST | 36 | Scrolling south-east |![MID_Btn_South_East.png](./figures/MID_Btn_South_East.png)| | MIDDLE_BTN_SOUTH_WEST | 37 | Scrolling south-west |![MID_Btn_South_West.png](./figures/MID_Btn_South_West.png)| | MIDDLE_BTN_NORTH_SOUTH_WEST_EAST | 38 | Moving as a cone in four directions|![MID_Btn_North_South_West_East.png](./figures/MID_Btn_North_South_West_East.png)| -| HORIZONTAL_TEXT_CURSOR10+ | 39 | Horizontal text selection|![Horizontal_Text_Cursor.png](./figures/Horizontal_Text_Cursor.png)| +| HORIZONTAL_TEXT_CURSOR10+ | 39 | Horizontal text cursor|![Horizontal_Text_Cursor.png](./figures/Horizontal_Text_Cursor.png)| | CURSOR_CROSS10+ | 40 | Cross cursor|![Cursor_Cross.png](./figures/Cursor_Cross.png)| | CURSOR_CIRCLE10+ | 41 | Circular cursor|![Cursor_Circle.png](./figures/Cursor_Circle.png)| @@ -1726,3 +1726,357 @@ try { console.log(`getTouchpadRightClickType failed, error: ${JSON.stringify(error, [`code`, `message`])}`); } ``` + +## pointer.setPointerSize10+ + +setPointerSize(size: number, callback: AsyncCallback<void>): void + +Sets the pointer size. This API uses an asynchronous callback to return the result. + +**System capability**: SystemCapability.MultimodalInput.Input.Pointer + +**System API**: This is a system API. + +**Parameters** + +| Name | Type | Mandatory | Description | +| -------- | ------------------------- | ---- | ------------------------------------- | +| size | number | Yes | Pointer size. The value ranges from **1** to **7**. The default value is **1**. | +| callback | AsyncCallback<void> | Yes | Callback used to return the result. If the operation is successful, **err** is **undefined**. Otherwise, **err** is an error object.| + +**Example** + +```js +try { + pointer.setPointerSize(1, (error) => { + if (error) { + console.log(`setPointerSize failed, error: ${JSON.stringify(error, [`code`, `message`])}`); + return; + } + console.log(`setPointerSize success`); + }); +} catch (error) { + console.log(`setPointerSize failed, error: ${JSON.stringify(error, [`code`, `message`])}`); +} +``` + +## pointer.setPointerSize10+ + +setPointerSize(size: number): Promise<void> + +Sets the pointer size. This API uses a promise to return the result. + +**System capability**: SystemCapability.MultimodalInput.Input.Pointer + +**System API**: This is a system API. + +**Parameters** + +| Name | Type | Mandatory | Description | +| ----- | ------ | ---- | ----------------------------------- | +| size | number | Yes | Pointer size. The value ranges from **1** to **7**. The default value is **1**.| + +**Return value** + +| Name | Description | +| ------------------- | ---------------- | +| Promise<void> | Promise that returns no value.| + +**Example** + +```js +try { + pointer.setPointerSize(3).then(() => { + console.log(`setPointerSize success`); + }); +} catch (error) { + console.log(`setPointerSize failed, error: ${JSON.stringify(error, [`code`, `message`])}`); +} +``` + +## pointer.setPointerSizeSync10+ + +setPointerSizeSync(size: number): void; + +Sets the pointer size. This API returns the result synchronously. + +**System capability**: SystemCapability.MultimodalInput.Input.Pointer + +**System API**: This is a system API. + +**Parameters** + +| Name | Type | Mandatory | Description | +| ----- | ------ | ---- | ----------------------------------- | +| size | number | Yes | Pointer size. The value ranges from **1** to **7**. The default value is **1**.| + +**Example** + +```js +try { + pointer.setPointerSizeSync(5); + console.log(`setPointerSizeSync success`); +} catch (error) { + console.log(`setPointerSizeSync failed, error: ${JSON.stringify(error, [`code`, `message`])}`); +} +``` + +## pointer.getPointerSize10+ + +getPointerSize(callback: AsyncCallback<number>): void + +Obtains the pointer size. This API uses an asynchronous callback to return the result. + +**System capability**: SystemCapability.MultimodalInput.Input.Pointer + +**System API**: This is a system API. + +**Parameters** + +| Name | Type | Mandatory | Description | +| -------- | --------------------------- | ---- | -------------- | +| callback | AsyncCallback<number> | Yes | Callback used to return the result.| + +**Example** + +```js +try { + pointer.getPointerSize((error, size) => { + console.log(`getPointerSize success, size: ${JSON.stringify(size)}`); + }); +} catch (error) { + console.log(`getPointerSize failed, error: ${JSON.stringify(error, [`code`, `message`])}`); +} +``` + +## pointer.getPointerSize10+ + +getPointerSize(): Promise<number> + +Obtains the pointer size. This API uses a promise to return the result. + +**System capability**: SystemCapability.MultimodalInput.Input.Pointer + +**System API**: This is a system API. + +**Return value** + +| Name | Description | +| --------------------- | ------------------- | +| Promise<number> | Promise used to return the result.| + +**Example** + +```js +try { + pointer.getPointerSize().then((size) => { + console.log(`getPointerSize success, size: ${JSON.stringify(size)}`); + }); +} catch (error) { + console.log(`getPointerSize failed, error: ${JSON.stringify(error, [`code`, `message`])}`); +} +``` + +## pointer.getPointerSizeSync10+ + +getPointerSizeSync(): number + +Obtains the pointer size. This API returns the result synchronously. + +**System capability**: SystemCapability.MultimodalInput.Input.Pointer + +**System API**: This is a system API. + +**Return value** + +| Name | Description | +| --------------------- | ------------------- | +| number | Pointer size. | + +**Example** + +```js +try { + let pointerSize = pointer.getPointerSizeSync(); + console.log(`getPointerSizeSync success, pointerSize: ${JSON.stringify(pointerSize)}`); +} catch (error) { + console.log(`getPointerSizeSync failed, error: ${JSON.stringify(error, [`code`, `message`])}`); +} +``` + +## pointer.setPointerColor10+ + +setPointerColor(color: number, callback: AsyncCallback<void>): void + +Sets the pointer color. This API uses an asynchronous callback to return the result. + +**System capability**: SystemCapability.MultimodalInput.Input.Pointer + +**System API**: This is a system API. + +**Parameters** + +| Name | Type | Mandatory | Description | +| -------- | ------------------------- | ---- | ------------------------------------- | +| color | number | Yes | Pointer color. The default value is **black** (0x000000). | +| callback | AsyncCallback<void> | Yes | Callback used to return the result. If the operation is successful, **err** is **undefined**. Otherwise, **err** is an error object.| + +**Example** + +```js +try { + pointer.setPointerColor(0xF6C800, (error) => { + if (error) { + console.log(`setPointerColor failed, error: ${JSON.stringify(error, [`code`, `message`])}`); + return; + } + console.log(`setPointerColor success`); + }); +} catch (error) { + console.log(`setPointerColor failed, error: ${JSON.stringify(error, [`code`, `message`])}`); +} +``` + +## pointer.setPointerColor10+ + +setPointerColor(color: number): Promise<void> + +Sets the pointer color. This API uses a promise to return the result. + +**System capability**: SystemCapability.MultimodalInput.Input.Pointer + +**System API**: This is a system API. + +**Parameters** + +| Name | Type | Mandatory | Description | +| ----- | ------ | ---- | ----------------------------------- | +| color | number | Yes | Pointer color. The default value is **black** (0x000000).| + +**Return value** + +| Name | Description | +| ------------------- | ---------------- | +| Promise<void> | Promise that returns no value.| + +**Example** + +```js +try { + pointer.setPointerColor(0xF6C800).then(() => { + console.log(`setPointerColor success`); + }); +} catch (error) { + console.log(`setPointerColor failed, error: ${JSON.stringify(error, [`code`, `message`])}`); +} +``` + +## pointer.setPointerColorSync10+ + +setPointerColorSync(color: number): void; + +Sets the pointer color. This API returns the result synchronously. + +**System capability**: SystemCapability.MultimodalInput.Input.Pointer + +**System API**: This is a system API. + +**Parameters** + +| Name | Type | Mandatory | Description | +| ----- | ------ | ---- | ----------------------------------- | +| color | number | Yes | Pointer color. The default value is **black** (0x000000).| + +**Example** + +```js +try { + pointer.setPointerColorSync(0xF6C800); + console.log(`setPointerColorSync success`); +} catch (error) { + console.log(`setPointerColorSync failed, error: ${JSON.stringify(error, [`code`, `message`])}`); +} +``` + +## pointer.getPointerColor10+ + +getPointerColor(callback: AsyncCallback<number>): void + +Obtains the pointer color. This API uses an asynchronous callback to return the result. + +**System capability**: SystemCapability.MultimodalInput.Input.Pointer + +**System API**: This is a system API. + +**Parameters** + +| Name | Type | Mandatory | Description | +| -------- | --------------------------- | ---- | -------------- | +| callback | AsyncCallback<number> | Yes | Callback used to return the result.| + +**Example** + +```js +try { + pointer.getPointerColor((error, color) => { + console.log(`getPointerColor success, color: ${JSON.stringify(color)}`); + }); +} catch (error) { + console.log(`getPointerColor failed, error: ${JSON.stringify(error, [`code`, `message`])}`); +} +``` + +## pointer.getPointerColor10+ + +getPointerColor(): Promise<number> + +Obtains the pointer color. This API uses a promise to return the result. + +**System capability**: SystemCapability.MultimodalInput.Input.Pointer + +**System API**: This is a system API. + +**Return value** + +| Name | Description | +| --------------------- | ------------------- | +| Promise<number> | Promise used to return the result.| + +**Example** + +```js +try { + pointer.getPointerColor().then((color) => { + console.log(`getPointerColor success, color: ${JSON.stringify(color)}`); + }); +} catch (error) { + console.log(`getPointerColor failed, error: ${JSON.stringify(error, [`code`, `message`])}`); +} +``` + +## pointer.getPointerColorSync10+ + +getPointerColorSync(): number + +Obtains the pointer color. This API returns the result synchronously. + +**System capability**: SystemCapability.MultimodalInput.Input.Pointer + +**System API**: This is a system API. + +**Return value** + +| Name | Description | +| --------------------- | ------------------- | +| number | Pointer color.| + +**Example** + +```js +try { + let pointerColor = pointer.getPointerColorSync(); + console.log(`getPointerColorSync success, pointerColor: ${JSON.stringify(pointerColor)}`); +} catch (error) { + console.log(`getPointerColorSync failed, error: ${JSON.stringify(error, [`code`, `message`])}`); +} +``` diff --git a/en/application-dev/reference/apis/js-apis-resource-manager.md b/en/application-dev/reference/apis/js-apis-resource-manager.md index 40cb3dc087..d4807f0517 100644 --- a/en/application-dev/reference/apis/js-apis-resource-manager.md +++ b/en/application-dev/reference/apis/js-apis-resource-manager.md @@ -22,10 +22,10 @@ For details about how to reference context in the stage model, see [Context in t import UIAbility from '@ohos.app.ability.UIAbility'; export default class EntryAbility extends UIAbility { - onWindowStageCreate(windowStage) { - let context = this.context; - let resourceManager = context.resourceManager; - } + onWindowStageCreate(windowStage) { + let context = this.context; + let resourceManager = context.resourceManager; + } } ``` @@ -48,17 +48,17 @@ Obtains the **ResourceManager** object of this application. This API uses an asy **Example** ```js resourceManager.getResourceManager((error, mgr) => { + if (error != null) { + console.log("error is " + error); + return; + } + mgr.getStringValue(0x1000000, (error, value) => { if (error != null) { - console.log("error is " + error); - return; + console.log("error is " + error); + } else { + let str = value; } - mgr.getStringValue(0x1000000, (error, value) => { - if (error != null) { - console.log("error is " + error); - } else { - let str = value; - } - }); + }); }); ``` > **NOTE**
In the sample code, **0x1000000** indicates the resource ID, which can be found in the compiled **ResourceTable.txt** file. @@ -107,15 +107,15 @@ Obtains the **ResourceManager** object of this application. This API uses a prom **Example** ```js resourceManager.getResourceManager().then(mgr => { - mgr.getStringValue(0x1000000, (error, value) => { - if (error != null) { - console.log("error is " + error); - } else { - let str = value; - } - }); + mgr.getStringValue(0x1000000, (error, value) => { + if (error != null) { + console.log("error is " + error); + } else { + let str = value; + } + }); }).catch(error => { - console.log("error is " + error); + console.log("error is " + error); }); ``` > **NOTE**
In the sample code, **0x1000000** indicates the resource ID, which can be found in the compiled **ResourceTable.txt** file. @@ -150,7 +150,6 @@ Obtains the **ResourceManager** object of an application based on the specified }); ``` - ## resourceManager.getSystemResourceManager10+ getSystemResourceManager(): ResourceManager @@ -177,16 +176,16 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco ```js import resourceManager from '@ohos.resourceManager'; -try { + try { let systemResourceManager = resourceManager.getSystemResourceManager(); systemResourceManager.getStringValue($r('sys.string.ohos_lab_vibrate').id).then(value => { - let str = value; + let str = value; }).catch(error => { - 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}.`); -} + } ``` @@ -259,7 +258,7 @@ Defines the device capability. | Name | Type | Readable | Writable | Description | | ------------- | ------------------------------- | ---- | ---- | -------- | | screenDensity | [ScreenDensity](#screendensity) | Yes | No | Screen density of the device.| -| deviceType | [DeviceType](#devicetype) | Yes | No | Type of the device. | +| deviceType | [DeviceType](#devicetype) | Yes | No | Device type. | ## RawFileDescriptor8+ @@ -301,20 +300,25 @@ Defines the capability of accessing application resources. > > - Resource files are defined in the **resources** directory of the project. You can obtain the resource ID using **$r(resource address).id**, for example, **$r('app.string.test').id**. -### getStringValue9+ +### getStringSync9+ -getStringValue(resId: number, callback: AsyncCallback<string>): void +getStringSync(resId: number): string -Obtains the string corresponding to the specified resource ID. This API uses an asynchronous callback to return the result. +Obtains the string corresponding to the specified resource ID. This API returns the result synchronously. **System capability**: SystemCapability.Global.ResourceManager **Parameters** -| Name | Type | Mandatory | Description | -| -------- | --------------------------- | ---- | --------------- | -| resId | number | Yes | Resource ID. | -| callback | AsyncCallback<string> | Yes | Callback used to return the result.| +| Name | Type | Mandatory | Description | +| ----- | ------ | ---- | ----- | +| resId | number | Yes | Resource ID.| + +**Return value** + +| Type | Description | +| ------ | ----------- | +| string | String corresponding to the specified resource ID.| **Error codes** @@ -322,31 +326,24 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco | ID| Error Message| | -------- | ---------------------------------------- | -| 9001001 | If the module resId invalid. | -| 9001002 | If the resource not found by resId. | -| 9001006 | If the resource re-ref too much. | +| 9001001 | If the resId invalid. | +| 9001002 | If the resource not found by resId. | +| 9001006 | If the resource re-ref too much. | -**Example (stage)** +**Example** ```ts - try { - this.context.resourceManager.getStringValue($r('app.string.test').id, (error, value) => { - if (error != null) { - console.log("error is " + error); - } else { - let str = value; - } - }); - } catch (error) { - console.error(`callback getStringValue failed, error code: ${error.code}, message: ${error.message}.`); - } + try { + this.context.resourceManager.getStringSync($r('app.string.test').id); + } catch (error) { + console.error(`getStringSync failed, error code: ${error.code}, message: ${error.message}.`); + } ``` +### getStringSync10+ -### getStringValue9+ - -getStringValue(resId: number): Promise<string> +getStringSync(resId: number, ...args: Array): string -Obtains the string corresponding to the specified resource ID. This API uses a promise to return the result. +Obtains the string corresponding to the specified resource ID and formats the string based on **args**. This API returns the result synchronously. **System capability**: SystemCapability.Global.ResourceManager @@ -355,42 +352,39 @@ Obtains the string corresponding to the specified resource ID. This API uses a p | Name | Type | Mandatory | Description | | ----- | ------ | ---- | ----- | | resId | number | Yes | Resource ID.| +| args | Array | No | Arguments for formatting strings.
Supported arguments:
%d, %f, %s, and %%
Note: **%%** is used to translate **%**.
Example: **%%d** is translated into the **%d** string.| **Return value** -| Type | Description | -| --------------------- | ----------- | -| Promise<string> | Promise used to return the result.| +| Type | Description | +| ------ | ---------------------------- | +| string | Formatted string.| **Error codes** For details about the error codes, see [Resource Manager Error Codes](../errorcodes/errorcode-resource-manager.md). | ID| Error Message| -| -------- | ---------------------------------------- | -| 9001001 | If the resId invalid. | -| 9001002 | If the resource not found by resId. | -| 9001006 | If the resource re-ref too much. | +| -------- | ----------------------------------------------- | +| 9001001 | If the resId invalid. | +| 9001002 | If the resource not found by resId. | +| 9001006 | If the resource re-ref too much. | +| 9001007 | If the resource obtained by resId formatting error. | **Example** ```ts try { - this.context.resourceManager.getStringValue($r('app.string.test').id).then(value => { - let str = value; - }).catch(error => { - console.log("getStringValue promise error is " + error); - }); + this.context.resourceManager.getStringSync($r('app.string.test').id, "format string", 10, 98.78); } catch (error) { - console.error(`promise getStringValue failed, error code: ${error.code}, message: ${error.message}.`); + console.error(`getStringSync failed, error code: ${error.code}, message: ${error.message}.`); } ``` +### getStringSync9+ -### getStringValue9+ - -getStringValue(resource: Resource, callback: AsyncCallback<string>): void +getStringSync(resource: Resource): string -Obtains the string corresponding to the specified resource object. This API uses an asynchronous callback to return the result. +Obtains the string corresponding to the specified resource object. This API returns the result synchronously. **System capability**: SystemCapability.Global.ResourceManager @@ -398,10 +392,15 @@ Obtains the string corresponding to the specified resource object. This API uses **Parameters** -| Name | Type | Mandatory | Description | -| -------- | --------------------------- | ---- | --------------- | -| resource | [Resource](#resource9) | Yes | Resource object. | -| callback | AsyncCallback<string> | Yes | Callback used to return the result.| +| Name | Type | Mandatory | Description | +| -------- | ---------------------- | ---- | ---- | +| resource | [Resource](#resource9) | Yes | Resource object.| + +**Return value** + +| Type | Description | +| ------ | ---------------- | +| string | String corresponding to the specified resource object.| **Error codes** @@ -416,30 +415,22 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco **Example** ```ts let resource = { - bundleName: "com.example.myapplication", - moduleName: "entry", - id: $r('app.string.test').id + bundleName: "com.example.myapplication", + moduleName: "entry", + id: $r('app.string.test').id }; try { - this.context.resourceManager.getStringValue(resource, (error, value) => { - if (error != null) { - console.log("error is " + error); - } else { - let str = value; - } - }); + this.context.resourceManager.getStringSync(resource); } catch (error) { - console.error(`callback getStringValue failed, error code: ${error.code}, message: ${error.message}.`); + console.error(`getStringSync failed, error code: ${error.code}, message: ${error.message}.`); } - ``` +### getStringSync10+ -### getStringValue9+ - -getStringValue(resource: Resource): Promise<string> +getStringSync(resource: Resource, ...args: Array): string -Obtains the string corresponding to the specified resource object. This API uses a promise to return the result. +Obtains the string corresponding to the specified resource object and formats the string based on **args**. This API returns the result synchronously. **System capability**: SystemCapability.Global.ResourceManager @@ -450,12 +441,13 @@ Obtains the string corresponding to the specified resource object. This API uses | Name | Type | Mandatory | Description | | -------- | ---------------------- | ---- | ---- | | resource | [Resource](#resource9) | Yes | Resource object.| +| args | Array | No | Arguments for formatting strings.
Supported arguments:
%d, %f, %s, and %%
Note: **%%** is used to translate **%**.
Example: **%%d** is translated into the **%d** string.| **Return value** -| Type | Description | -| --------------------- | ---------------- | -| Promise<string> | Promise used to return the result.| +| Type | Description | +| ------ | ---------------------------- | +| string | Formatted string.| **Error codes** @@ -466,40 +458,41 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco | 9001001 | If the resId invalid. | | 9001002 | If the resource not found by resId. | | 9001006 | If the resource re-ref too much. | +| 9001007 | If the resource obtained by resId formatting error. | **Example** ```ts let resource = { - bundleName: "com.example.myapplication", - moduleName: "entry", - id: $r('app.string.test').id + bundleName: "com.example.myapplication", + moduleName: "entry", + id: $r('app.string.test').id }; try { - this.context.resourceManager.getStringValue(resource).then(value => { - let str = value; - }).catch(error => { - console.log("getStringValue promise error is " + error); - }); + this.context.resourceManager.getStringSync(resource, "format string", 10, 98.78); } catch (error) { - console.error(`promise getStringValue failed, error code: ${error.code}, message: ${error.message}.`); + console.error(`getStringSync failed, error code: ${error.code}, message: ${error.message}.`); } - ``` - + ``` -### getStringArrayValue9+ +### getStringByNameSync9+ -getStringArrayValue(resId: number, callback: AsyncCallback<Array<string>>): void +getStringByNameSync(resName: string): string -Obtains the string array corresponding to the specified resource ID. This API uses an asynchronous callback to return the result. +Obtains the string corresponding to the specified resource name. This API returns the result synchronously. **System capability**: SystemCapability.Global.ResourceManager **Parameters** -| Name | Type | Mandatory | Description | -| -------- | ---------------------------------------- | ---- | ----------------- | -| resId | number | Yes | Resource ID. | -| callback | AsyncCallback<Array<string>> | Yes | Callback used to return the result.| +| Name | Type | Mandatory | Description | +| ------- | ------ | ---- | ---- | +| resName | string | Yes | Resource name.| + +**Return value** + +| Type | Description | +| ------ | ---------- | +| string | String corresponding to the specified resource name.| **Error codes** @@ -507,45 +500,39 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco | ID| Error Message| | -------- | ---------------------------------------- | -| 9001001 | If the resId invalid. | -| 9001002 | If the resource not found by resId. | +| 9001003 | If the resName invalid. | +| 9001004 | If the resource not found by resName. | | 9001006 | If the resource re-ref too much. | **Example** ```ts try { - this.context.resourceManager.getStringArrayValue($r('app.strarray.test').id, (error, value) => { - if (error != null) { - console.log("error is " + error); - } else { - let strArray = value; - } - }); + this.context.resourceManager.getStringByNameSync("test"); } catch (error) { - console.error(`callback getStringArrayValue failed, error code: ${error.code}, message: ${error.message}.`); + console.error(`getStringByNameSync failed, error code: ${error.code}, message: ${error.message}.`); } ``` +### getStringByNameSync10+ -### getStringArrayValue9+ - -getStringArrayValue(resId: number): Promise<Array<string>> +getStringByNameSync(resName: string, ...args: Array): string -Obtains the string array corresponding to the specified resource ID. This API uses a promise to return the result. +Obtains the string corresponding to the specified resource name and formats the string based on **args**. This API returns the result synchronously. **System capability**: SystemCapability.Global.ResourceManager **Parameters** -| Name | Type | Mandatory | Description | -| ----- | ------ | ---- | ----- | -| resId | number | Yes | Resource ID.| +| Name | Type | Mandatory | Description | +| ------- | ------ | ---- | ---- | +| resName | string | Yes | Resource name.| +| args | Array | No | Arguments for formatting strings.
Supported arguments:
%d, %f, %s, and %%
Note: **%%** is used to translate **%**.
Example: **%%d** is translated into the **%d** string.| **Return value** -| Type | Description | -| ---------------------------------- | ------------- | -| Promise<Array<string>> | Promise used to return the result.| +| Type | Description | +| ------ | ---------------------------- | +| string | Formatted string.| **Error codes** @@ -553,39 +540,34 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco | ID| Error Message| | -------- | ---------------------------------------- | -| 9001001 | If the resId invalid. | -| 9001002 | If the resource not found by resId. | +| 9001003 | If the resName invalid. | +| 9001004 | If the resource not found by resName. | | 9001006 | If the resource re-ref too much. | +| 9001008 | If the resource obtained by resName formatting error. | **Example** ```ts try { - this.context.resourceManager.getStringArrayValue($r('app.strarray.test').id).then(value => { - let strArray = value; - }).catch(error => { - console.log("getStringArrayValue promise error is " + error); - }); + this.context.resourceManager.getStringByNameSync("test", "format string", 10, 98.78); } catch (error) { - console.error(`promise getStringArrayValue failed, error code: ${error.code}, message: ${error.message}.`); + console.error(`getStringByNameSync failed, error code: ${error.code}, message: ${error.message}.`); } - ``` + ``` -### getStringArrayValue9+ +### getStringValue9+ -getStringArrayValue(resource: Resource, callback: AsyncCallback<Array<string>>): void +getStringValue(resId: number, callback: AsyncCallback<string>): void -Obtains the string array corresponding to the specified resource object. This API uses an asynchronous callback to return the result. +Obtains the string corresponding to the specified resource ID. This API uses an asynchronous callback to return the result. **System capability**: SystemCapability.Global.ResourceManager -**Model restriction**: This API can be used only in the stage model. - **Parameters** -| Name | Type | Mandatory | Description | -| -------- | ---------------------------------------- | ---- | ----------------- | -| resource | [Resource](#resource9) | Yes | Resource object. | -| callback | AsyncCallback<Array<string>> | Yes | Callback used to return the result.| +| Name | Type | Mandatory | Description | +| -------- | --------------------------- | ---- | --------------- | +| resId | number | Yes | Resource ID. | +| callback | AsyncCallback<string> | Yes | Callback used to return the result.| **Error codes** @@ -593,51 +575,44 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco | ID| Error Message| | -------- | ---------------------------------------- | -| 9001001 | If the resId invalid. | -| 9001002 | If the resource not found by resId. | -| 9001006 | If the resource re-ref too much. | +| 9001001 | If the module resId invalid. | +| 9001002 | If the resource not found by resId. | +| 9001006 | If the resource re-ref too much. | -**Example** +**Example (stage)** ```ts - let resource = { - bundleName: "com.example.myapplication", - moduleName: "entry", - id: $r('app.strarray.test').id - }; try { - this.context.resourceManager.getStringArrayValue(resource, (error, value) => { + this.context.resourceManager.getStringValue($r('app.string.test').id, (error, value) => { if (error != null) { - console.log("error is " + error); + console.log("error is " + error); } else { - let strArray = value; + let str = value; } }); } catch (error) { - console.error(`callback getStringArrayValue failed, error code: ${error.code}, message: ${error.message}.`); + console.error(`callback getStringValue failed, error code: ${error.code}, message: ${error.message}.`); } ``` -### getStringArrayValue9+ +### getStringValue9+ -getStringArrayValue(resource: Resource): Promise<Array<string>> +getStringValue(resId: number): Promise<string> -Obtains the string array corresponding to the specified resource object. This API uses a promise to return the result. +Obtains the string corresponding to the specified resource ID. This API uses a promise to return the result. **System capability**: SystemCapability.Global.ResourceManager -**Model restriction**: This API can be used only in the stage model. - **Parameters** -| Name | Type | Mandatory | Description | -| -------- | ---------------------- | ---- | ---- | -| resource | [Resource](#resource9) | Yes | Resource object.| +| Name | Type | Mandatory | Description | +| ----- | ------ | ---- | ----- | +| resId | number | Yes | Resource ID.| **Return value** -| Type | Description | -| ---------------------------------- | ------------------ | -| Promise<Array<string>> | Promise used to return the result.| +| Type | Description | +| --------------------- | ----------- | +| Promise<string> | Promise used to return the result.| **Error codes** @@ -651,36 +626,33 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco **Example** ```ts - let resource = { - bundleName: "com.example.myapplication", - moduleName: "entry", - id: $r('app.strarray.test').id - }; try { - this.context.resourceManager.getStringArrayValue(resource).then(value => { - let strArray = value; + this.context.resourceManager.getStringValue($r('app.string.test').id).then(value => { + let str = value; }).catch(error => { - console.log("getStringArray promise error is " + error); + console.log("getStringValue promise error is " + error); }); } catch (error) { - console.error(`promise getStringArrayValue failed, error code: ${error.code}, message: ${error.message}.`); + console.error(`promise getStringValue failed, error code: ${error.code}, message: ${error.message}.`); } ``` -### getMediaContent9+ +### getStringValue9+ -getMediaContent(resId: number, callback: AsyncCallback<Uint8Array>): void +getStringValue(resource: Resource, callback: AsyncCallback<string>): void -Obtains the content of the media file corresponding to the specified resource ID. This API uses an asynchronous callback to return the result. +Obtains the string corresponding to the specified resource object. This API uses an asynchronous callback to return the result. **System capability**: SystemCapability.Global.ResourceManager +**Model restriction**: This API can be used only in the stage model. + **Parameters** -| Name | Type | Mandatory | Description | -| -------- | ------------------------------- | ---- | ------------------ | -| resId | number | Yes | Resource ID. | -| callback | AsyncCallback<Uint8Array> | Yes | Callback used to return the result.| +| Name | Type | Mandatory | Description | +| -------- | --------------------------- | ---- | --------------- | +| resource | [Resource](#resource9) | Yes | Resource object. | +| callback | AsyncCallback<string> | Yes | Callback used to return the result.| **Error codes** @@ -690,37 +662,49 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco | -------- | ---------------------------------------- | | 9001001 | If the resId invalid. | | 9001002 | If the resource not found by resId. | +| 9001006 | If the resource re-ref too much. | **Example** ```ts + let resource = { + bundleName: "com.example.myapplication", + moduleName: "entry", + id: $r('app.string.test').id + }; try { - this.context.resourceManager.getMediaContent($r('app.media.test').id, (error, value) => { - if (error != null) { - console.log("error is " + error); - } else { - let media = value; - } + this.context.resourceManager.getStringValue(resource, (error, value) => { + if (error != null) { + console.log("error is " + error); + } else { + let str = value; + } }); } catch (error) { - console.error(`callback getMediaContent failed, error code: ${error.code}, message: ${error.message}.`); + console.error(`callback getStringValue failed, error code: ${error.code}, message: ${error.message}.`); } ``` -### getMediaContent10+ +### getStringValue9+ -getMediaContent(resId: number, density: number, callback: AsyncCallback<Uint8Array>): void +getStringValue(resource: Resource): Promise<string> -Obtains the content of the media file with the screen density corresponding to the specified resource ID. This API uses an asynchronous callback to return the result. +Obtains the string corresponding to the specified resource object. This API uses a promise to return the result. **System capability**: SystemCapability.Global.ResourceManager +**Model restriction**: This API can be used only in the stage model. + **Parameters** -| Name | Type | Mandatory | Description | -| -------- | ------------------------------- | ---- | ------------------ | -| resId | number | Yes | Resource ID. | -| [density](#screendensity) | number | Yes | Screen density. The value **0** indicates the default screen density. | -| callback | AsyncCallback<Uint8Array> | Yes | Callback used to return the result.| +| Name | Type | Mandatory | Description | +| -------- | ---------------------- | ---- | ---- | +| resource | [Resource](#resource9) | Yes | Resource object.| + +**Return value** + +| Type | Description | +| --------------------- | ---------------- | +| Promise<string> | Promise used to return the result.| **Error codes** @@ -730,41 +714,85 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco | -------- | ---------------------------------------- | | 9001001 | If the resId invalid. | | 9001002 | If the resource not found by resId. | +| 9001006 | If the resource re-ref too much. | **Example** ```ts + let resource = { + bundleName: "com.example.myapplication", + moduleName: "entry", + id: $r('app.string.test').id + }; try { - this.context.resourceManager.getMediaContent($r('app.media.test').id, 120, (error, value) => { - if (error != null) { - console.error(`callback getMediaContent failed, error code: ${error.code}, message: ${error.message}.`); - } else { - let media = value; - } + this.context.resourceManager.getStringValue(resource).then(value => { + let str = value; + }).catch(error => { + console.log("getStringValue promise error is " + error); }); } catch (error) { - console.error(`callback getMediaContent failed, error code: ${error.code}, message: ${error.message}.`); + console.error(`promise getStringValue failed, error code: ${error.code}, message: ${error.message}.`); } ``` -### getMediaContent9+ +### getStringByName9+ -getMediaContent(resId: number): Promise<Uint8Array> +getStringByName(resName: string, callback: AsyncCallback<string>): void -Obtains the content of the media file corresponding to the specified resource ID. This API uses a promise to return the result. +Obtains the string corresponding to the specified resource name. This API uses an asynchronous callback to return the result. **System capability**: SystemCapability.Global.ResourceManager **Parameters** -| Name | Type | Mandatory | Description | -| ----- | ------ | ---- | ----- | -| resId | number | Yes | Resource ID.| +| Name | Type | Mandatory | Description | +| -------- | --------------------------- | ---- | --------------- | +| resName | string | Yes | Resource name. | +| callback | AsyncCallback<string> | Yes | Callback used to return the result.| + +**Error codes** + +For details about the error codes, see [Resource Manager Error Codes](../errorcodes/errorcode-resource-manager.md). + +| ID| Error Message| +| -------- | ---------------------------------------- | +| 9001003 | If the resName invalid. | +| 9001004 | If the resource not found by resName. | +| 9001006 | If the resource re-ref too much. | + +**Example** + ```ts + try { + this.context.resourceManager.getStringByName("test", (error, value) => { + if (error != null) { + console.log("error is " + error); + } else { + let str = value; + } + }); + } catch (error) { + console.error(`callback getStringByName failed, error code: ${error.code}, message: ${error.message}.`); + } + ``` + +### getStringByName9+ + +getStringByName(resName: string): Promise<string> + +Obtains the string corresponding to the specified resource name. This API uses a promise to return the result. + +**System capability**: SystemCapability.Global.ResourceManager + +**Parameters** + +| Name | Type | Mandatory | Description | +| ------- | ------ | ---- | ---- | +| resName | string | Yes | Resource name.| **Return value** -| Type | Description | -| ------------------------- | -------------- | -| Promise<Uint8Array> | Promise used to return the result.| +| Type | Description | +| --------------------- | ---------- | +| Promise<string> | Promise used to return the result.| **Error codes** @@ -772,27 +800,28 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco | ID| Error Message| | -------- | ---------------------------------------- | -| 9001001 | If the resId invalid. | -| 9001002 | If the resource not found by resId. | +| 9001003 | If the resName invalid. | +| 9001004 | If the resource not found by resName. | +| 9001006 | If the resource re-ref too much. | **Example** ```ts try { - this.context.resourceManager.getMediaContent($r('app.media.test').id).then(value => { - let media = value; - }).catch(error => { - console.log("getMediaContent promise error is " + error); - }); + this.context.resourceManager.getStringByName("test").then(value => { + let str = value; + }).catch(error => { + console.log("getStringByName promise error is " + error); + }); } catch (error) { - console.error(`promise getMediaContent failed, error code: ${error.code}, message: ${error.message}.`); + console.error(`promise getStringByName failed, error code: ${error.code}, message: ${error.message}.`); } ``` -### getMediaContent10+ +### getStringArrayValueSync10+ -getMediaContent(resId: number, density: number): Promise<Uint8Array> +getStringArrayValueSync(resId: number): Array<string> -Obtains the content of the media file with the screen density corresponding to the specified resource ID. This API uses a promise to return the result. +Obtains the string array corresponding to the specified resource ID. This API returns the result synchronously. **System capability**: SystemCapability.Global.ResourceManager @@ -801,13 +830,12 @@ Obtains the content of the media file with the screen density corresponding to t | Name | Type | Mandatory | Description | | ----- | ------ | ---- | ----- | | resId | number | Yes | Resource ID.| -| [density](#screendensity) | number | Yes | Screen density. The value **0** indicates the default screen density. | **Return value** -| Type | Description | -| ------------------------- | -------------- | -| Promise<Uint8Array> | Promise used to return the result.| +| Type | Description | +| --------------------- | ----------- | +| Array<string> | String array corresponding to the specified resource ID.| **Error codes** @@ -817,25 +845,22 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco | -------- | ---------------------------------------- | | 9001001 | If the resId invalid. | | 9001002 | If the resource not found by resId. | +| 9001006 | If the resource re-ref too much. | **Example** ```ts try { - this.context.resourceManager.getMediaContent($r('app.media.test').id, 120).then(value => { - let media = value; - }).catch(error => { - console.error(`promise getMediaContent failed, error code: ${error.code}, message: ${error.message}.`); - }); + this.context.resourceManager.getStringArrayValueSync($r('app.strarray.test').id); } catch (error) { - console.error(`promise getMediaContent failed, error code: ${error.code}, message: ${error.message}.`); + console.error(`getStringArrayValueSync failed, error code: ${error.code}, message: ${error.message}.`); } ``` -### getMediaContent9+ +### getStringArrayValueSync10+ -getMediaContent(resource: Resource, callback: AsyncCallback<Uint8Array>): void +getStringArrayValueSync(resource: Resource): Array<string> -Obtains the content of the media file corresponding to the specified resource object. This API uses an asynchronous callback to return the result. +Obtains the string array corresponding to the specified resource object. This API returns the result synchronously. **System capability**: SystemCapability.Global.ResourceManager @@ -843,10 +868,15 @@ Obtains the content of the media file corresponding to the specified resource ob **Parameters** -| Name | Type | Mandatory | Description | -| -------- | ------------------------------- | ---- | ------------------ | -| resource | [Resource](#resource9) | Yes | Resource object. | -| callback | AsyncCallback<Uint8Array> | Yes | Callback used to return the result.| +| Name | Type | Mandatory | Description | +| ----- | ------ | ---- | ----- | +| resource | [Resource](#resource9) | Yes | Resource object.| + +**Return value** + +| Type | Description | +| --------------------- | ----------- | +| Array<string> | String array corresponding to the specified resource object.| **Error codes** @@ -856,44 +886,36 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco | -------- | ---------------------------------------- | | 9001001 | If the resId invalid. | | 9001002 | If the resource not found by resId. | +| 9001006 | If the resource re-ref too much. | **Example** ```ts let resource = { - bundleName: "com.example.myapplication", - moduleName: "entry", - id: $r('app.media.test').id + bundleName: "com.example.myapplication", + moduleName: "entry", + id: $r('app.strarray.test').id }; try { - this.context.resourceManager.getMediaContent(resource, (error, value) => { - if (error != null) { - console.log("error is " + error); - } else { - let media = value; - } - }); + this.context.resourceManager.getStringArrayValueSync(resource); } catch (error) { - console.error(`callback getMediaContent failed, error code: ${error.code}, message: ${error.message}.`); + console.error(`getStringArrayValueSync failed, error code: ${error.code}, message: ${error.message}.`); } ``` -### getMediaContent10+ +### getStringArrayValue9+ -getMediaContent(resource: Resource, density: number, callback: AsyncCallback<Uint8Array>): void +getStringArrayValue(resId: number, callback: AsyncCallback<Array<string>>): void -Obtains the content of the media file with the screen density corresponding to the specified resource object. This API uses an asynchronous callback to return the result. +Obtains the string array corresponding to the specified resource ID. This API uses an asynchronous callback to return the result. **System capability**: SystemCapability.Global.ResourceManager -**Model restriction**: This API can be used only in the stage model. - **Parameters** -| Name | Type | Mandatory | Description | -| -------- | ------------------------------- | ---- | ------------------ | -| resource | [Resource](#resource9) | Yes | Resource object. | -| [density](#screendensity) | number | Yes | Screen density. The value **0** indicates the default screen density. | -| callback | AsyncCallback<Uint8Array> | Yes | Callback used to return the result.| +| Name | Type | Mandatory | Description | +| -------- | ---------------------------------------- | ---- | ----------------- | +| resId | number | Yes | Resource ID. | +| callback | AsyncCallback<Array<string>> | Yes | Callback used to return the result.| **Error codes** @@ -903,48 +925,42 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco | -------- | ---------------------------------------- | | 9001001 | If the resId invalid. | | 9001002 | If the resource not found by resId. | +| 9001006 | If the resource re-ref too much. | **Example** ```ts - let resource = { - bundleName: "com.example.myapplication", - moduleName: "entry", - id: $r('app.media.test').id - }; try { - this.context.resourceManager.getMediaContent(resource, 120, (error, value) => { - if (error != null) { - console.error(`callback getMediaContent failed, error code: ${error.code}, message: ${error.message}.`); - } else { - let media = value; - } + this.context.resourceManager.getStringArrayValue($r('app.strarray.test').id, (error, value) => { + if (error != null) { + console.log("error is " + error); + } else { + let strArray = value; + } }); } catch (error) { - console.error(`callback getMediaContent failed, error code: ${error.code}, message: ${error.message}.`); + console.error(`callback getStringArrayValue failed, error code: ${error.code}, message: ${error.message}.`); } ``` -### getMediaContent9+ +### getStringArrayValue9+ -getMediaContent(resource: Resource): Promise<Uint8Array> +getStringArrayValue(resId: number): Promise<Array<string>> -Obtains the content of the media file corresponding to the specified resource object. This API uses a promise to return the result. +Obtains the string array corresponding to the specified resource ID. This API uses a promise to return the result. **System capability**: SystemCapability.Global.ResourceManager -**Model restriction**: This API can be used only in the stage model. - **Parameters** -| Name | Type | Mandatory | Description | -| -------- | ---------------------- | ---- | ---- | -| resource | [Resource](#resource9) | Yes | Resource object.| +| Name | Type | Mandatory | Description | +| ----- | ------ | ---- | ----- | +| resId | number | Yes | Resource ID.| **Return value** -| Type | Description | -| ------------------------- | ------------------- | -| Promise<Uint8Array> | Promise used to return the result.| +| Type | Description | +| ---------------------------------- | ------------- | +| Promise<Array<string>> | Promise used to return the result.| **Error codes** @@ -954,30 +970,26 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco | -------- | ---------------------------------------- | | 9001001 | If the resId invalid. | | 9001002 | If the resource not found by resId. | +| 9001006 | If the resource re-ref too much. | **Example** ```ts - let resource = { - bundleName: "com.example.myapplication", - moduleName: "entry", - id: $r('app.media.test').id - }; try { - this.context.resourceManager.getMediaContent(resource).then(value => { - let media = value; + this.context.resourceManager.getStringArrayValue($r('app.strarray.test').id).then(value => { + let strArray = value; }).catch(error => { - console.log("getMediaContent promise error is " + error); + console.log("getStringArrayValue promise error is " + error); }); } catch (error) { - console.error(`promise getMediaContent failed, error code: ${error.code}, message: ${error.message}.`); + console.error(`promise getStringArrayValue failed, error code: ${error.code}, message: ${error.message}.`); } ``` -### getMediaContent10+ +### getStringArrayValue9+ -getMediaContent(resource: Resource, density: number): Promise<Uint8Array> +getStringArrayValue(resource: Resource, callback: AsyncCallback<Array<string>>): void -Obtains the content of the media file with the screen density corresponding to the specified resource object. This API uses a promise to return the result. +Obtains the string array corresponding to the specified resource object. This API uses an asynchronous callback to return the result. **System capability**: SystemCapability.Global.ResourceManager @@ -985,16 +997,10 @@ Obtains the content of the media file with the screen density corresponding to t **Parameters** -| Name | Type | Mandatory | Description | -| -------- | ---------------------- | ---- | ---- | -| resource | [Resource](#resource9) | Yes | Resource object.| -| [density](#screendensity) | number | Yes | Screen density. The value **0** indicates the default screen density. | - -**Return value** - -| Type | Description | -| ------------------------- | ------------------- | -| Promise<Uint8Array> | Promise used to return the result.| +| Name | Type | Mandatory | Description | +| -------- | ---------------------------------------- | ---- | ----------------- | +| resource | [Resource](#resource9) | Yes | Resource object. | +| callback | AsyncCallback<Array<string>> | Yes | Callback used to return the result.| **Error codes** @@ -1004,39 +1010,49 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco | -------- | ---------------------------------------- | | 9001001 | If the resId invalid. | | 9001002 | If the resource not found by resId. | +| 9001006 | If the resource re-ref too much. | **Example** ```ts let resource = { - bundleName: "com.example.myapplication", - moduleName: "entry", - id: $r('app.media.test').id + bundleName: "com.example.myapplication", + moduleName: "entry", + id: $r('app.strarray.test').id }; try { - this.context.resourceManager.getMediaContent(resource, 120).then(value => { - let media = value; - }).catch(error => { - console.error(`promise getMediaContent failed, error code: ${error.code}, message: ${error.message}.`); + this.context.resourceManager.getStringArrayValue(resource, (error, value) => { + if (error != null) { + console.log("error is " + error); + } else { + let strArray = value; + } }); } catch (error) { - console.error(`promise getMediaContent failed, error code: ${error.code}, message: ${error.message}.`); + console.error(`callback getStringArrayValue failed, error code: ${error.code}, message: ${error.message}.`); } ``` -### getMediaContentBase649+ +### getStringArrayValue9+ -getMediaContentBase64(resId: number, callback: AsyncCallback<string>): void +getStringArrayValue(resource: Resource): Promise<Array<string>> -Obtains the Base64 code of the image corresponding to the specified resource ID. This API uses an asynchronous callback to return the result. +Obtains the string array corresponding to the specified resource object. This API uses a promise to return the result. **System capability**: SystemCapability.Global.ResourceManager +**Model restriction**: This API can be used only in the stage model. + **Parameters** -| Name | Type | Mandatory | Description | -| -------- | --------------------------- | ---- | ------------------------ | -| resId | number | Yes | Resource ID. | -| callback | AsyncCallback<string> | Yes | Callback used to return the result.| +| Name | Type | Mandatory | Description | +| -------- | ---------------------- | ---- | ---- | +| resource | [Resource](#resource9) | Yes | Resource object.| + +**Return value** + +| Type | Description | +| ---------------------------------- | ------------------ | +| Promise<Array<string>> | Promise used to return the result.| **Error codes** @@ -1046,37 +1062,40 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco | -------- | ---------------------------------------- | | 9001001 | If the resId invalid. | | 9001002 | If the resource not found by resId. | +| 9001006 | If the resource re-ref too much. | **Example** ```ts + let resource = { + bundleName: "com.example.myapplication", + moduleName: "entry", + id: $r('app.strarray.test').id + }; try { - this.context.resourceManager.getMediaContentBase64($r('app.media.test').id, (error, value) => { - if (error != null) { - console.log("error is " + error); - } else { - let media = value; - } - }); + this.context.resourceManager.getStringArrayValue(resource).then(value => { + let strArray = value; + }).catch(error => { + console.log("getStringArray promise error is " + error); + }); } catch (error) { - console.error(`callback getMediaContentBase64 failed, error code: ${error.code}, message: ${error.message}.`); + console.error(`promise getStringArrayValue failed, error code: ${error.code}, message: ${error.message}.`); } ``` -### getMediaContentBase6410+ +### getStringArrayByName9+ -getMediaContentBase64(resId: number, density: number, callback: AsyncCallback<string>): void +getStringArrayByName(resName: string, callback: AsyncCallback<Array<string>>): void -Obtains the Base64 code of an image with the screen density corresponding to the specified resource ID. This API uses an asynchronous callback to return the result. +Obtains the string array corresponding to the specified resource name. This API uses an asynchronous callback to return the result. **System capability**: SystemCapability.Global.ResourceManager **Parameters** -| Name | Type | Mandatory | Description | -| -------- | --------------------------- | ---- | ------------------------ | -| resId | number | Yes | Resource ID. | -| [density](#screendensity) | number | Yes | Screen density. The value **0** indicates the default screen density. | -| callback | AsyncCallback<string> | Yes | Callback used to return the result.| +| Name | Type | Mandatory | Description | +| -------- | ---------------------------------------- | ---- | ----------------- | +| resName | string | Yes | Resource name. | +| callback | AsyncCallback<Array<string>> | Yes | Callback used to return the result.| **Error codes** @@ -1084,43 +1103,44 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco | ID| Error Message| | -------- | ---------------------------------------- | -| 9001001 | If the resId invalid. | -| 9001002 | If the resource not found by resId. | +| 9001003 | If the resName invalid. | +| 9001004 | If the resource not found by resName. | +| 9001006 | If the resource re-ref too much. | **Example** ```ts try { - this.context.resourceManager.getMediaContentBase64($r('app.media.test').id, 120, (error, value) => { - if (error != null) { - console.error(`callback getMediaContentBase64 failed, error code: ${error.code}, message: ${error.message}.`); - } else { - let media = value; - } - }); + this.context.resourceManager.getStringArrayByName("test", (error, value) => { + if (error != null) { + console.log("error is " + error); + } else { + let strArray = value; + } + }); } catch (error) { - console.error(`callback getMediaContentBase64 failed, error code: ${error.code}, message: ${error.message}.`); + console.error(`callback getStringArrayByName failed, error code: ${error.code}, message: ${error.message}.`); } ``` -### getMediaContentBase649+ +### getStringArrayByName9+ -getMediaContentBase64(resId: number): Promise<string> +getStringArrayByName(resName: string): Promise<Array<string>> -Obtains the Base64 code of the image corresponding to the specified resource ID. This API uses a promise to return the result. +Obtains the string array corresponding to the specified resource name. This API uses a promise to return the result. **System capability**: SystemCapability.Global.ResourceManager **Parameters** -| Name | Type | Mandatory | Description | -| ----- | ------ | ---- | ----- | -| resId | number | Yes | Resource ID.| +| Name | Type | Mandatory | Description | +| ------- | ------ | ---- | ---- | +| resName | string | Yes | Resource name.| **Return value** -| Type | Description | -| --------------------- | -------------------- | -| Promise<string> | Promise used to return the result.| +| Type | Description | +| ---------------------------------- | ------------ | +| Promise<Array<string>> | Promise used to return the result.| **Error codes** @@ -1128,27 +1148,28 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco | ID| Error Message| | -------- | ---------------------------------------- | -| 9001001 | If the resId invalid. | -| 9001002 | If the resource not found by resId. | +| 9001003 | If the resName invalid. | +| 9001004 | If the resource not found by resName. | +| 9001006 | If the resource re-ref too much. | **Example** ```ts try { - this.context.resourceManager.getMediaContentBase64($r('app.media.test').id).then(value => { - let media = value; + this.context.resourceManager.getStringArrayByName("test").then(value => { + let strArray = value; }).catch(error => { - console.log("getMediaContentBase64 promise error is " + error); + console.log("getStringArrayByName promise error is " + error); }); } catch (error) { - console.error(`promise getMediaContentBase64 failed, error code: ${error.code}, message: ${error.message}.`); + console.error(`promise getStringArrayByName failed, error code: ${error.code}, message: ${error.message}.`); } ``` -### getMediaContentBase6410+ +### getPluralStringValueSync10+ -getMediaContentBase64(resId: number, density: number): Promise<string> +getPluralStringValueSync(resId: number, num: number): string -Obtains the Base64 code of an image with the screen density corresponding to the specified resource ID. This API uses a promise to return the result. +Obtains the singular-plural string corresponding to the specified resource ID based on the specified number. This API returns the result synchronously. **System capability**: SystemCapability.Global.ResourceManager @@ -1157,13 +1178,13 @@ Obtains the Base64 code of an image with the screen density corresponding to the | Name | Type | Mandatory | Description | | ----- | ------ | ---- | ----- | | resId | number | Yes | Resource ID.| -| [density](#screendensity) | number | Yes | Screen density. The value **0** indicates the default screen density. | +| num | number | Yes | Number. | **Return value** -| Type | Description | -| --------------------- | -------------------- | -| Promise<string> | Promise used to return the result.| +| Type | Description | +| -------- | ----------- | +| string | Singular-plural string corresponding to the specified resource ID.| **Error codes** @@ -1173,25 +1194,22 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco | -------- | ---------------------------------------- | | 9001001 | If the resId invalid. | | 9001002 | If the resource not found by resId. | +| 9001006 | If the resource re-ref too much. | **Example** ```ts try { - this.context.resourceManager.getMediaContentBase64($r('app.media.test').id, 120).then(value => { - let media = value; - }).catch(error => { - console.error(`promise getMediaContentBase64 failed, error code: ${error.code}, message: ${error.message}.`); - }); + this.context.resourceManager.getPluralStringValueSync($r('app.plural.test').id, 1); } catch (error) { - console.error(`promise getMediaContentBase64 failed, error code: ${error.code}, message: ${error.message}.`); + console.error(`getPluralStringValueSync failed, error code: ${error.code}, message: ${error.message}.`); } ``` -### getMediaContentBase649+ +### getPluralStringValueSync10+ -getMediaContentBase64(resource: Resource, callback: AsyncCallback<string>): void +getPluralStringValueSync(resource: Resource, num: number): string -Obtains the Base64 code of the image corresponding to the specified resource object. This API uses an asynchronous callback to return the result. +Obtains the singular-plural string corresponding to the specified resource object based on the specified number. This API returns the result synchronously. **System capability**: SystemCapability.Global.ResourceManager @@ -1199,10 +1217,16 @@ Obtains the Base64 code of the image corresponding to the specified resource obj **Parameters** -| Name | Type | Mandatory | Description | -| -------- | --------------------------- | ---- | ------------------------ | -| resource | [Resource](#resource9) | Yes | Resource object. | -| callback | AsyncCallback<string> | Yes | Callback used to return the result.| +| Name | Type | Mandatory | Description | +| ----- | ------ | ---- | ----- | +| resource | [Resource](#resource9) | Yes | Resource object.| +| num | number | Yes | Number. | + +**Return value** + +| Type | Description | +| --------------------- | ----------- | +| string | Singular-plural string corresponding to the specified resource object.| **Error codes** @@ -1212,43 +1236,36 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco | -------- | ---------------------------------------- | | 9001001 | If the resId invalid. | | 9001002 | If the resource not found by resId. | +| 9001006 | If the resource re-ref too much. | **Example** ```ts let resource = { - bundleName: "com.example.myapplication", - moduleName: "entry", - id: $r('app.media.test').id + bundleName: "com.example.myapplication", + moduleName: "entry", + id: $r('app.plural.test').id }; try { - this.context.resourceManager.getMediaContentBase64(resource, (error, value) => { - if (error != null) { - console.log("error is " + error); - } else { - let media = value; - } - }); + this.context.resourceManager.getPluralStringValueSync(resource, 1); } catch (error) { - console.error(`callback getMediaContentBase64 failed, error code: ${error.code}, message: ${error.message}.`); + console.error(`getPluralStringValueSync failed, error code: ${error.code}, message: ${error.message}.`); } ``` -### getMediaContentBase6410+ +### getPluralStringValue9+ -getMediaContentBase64(resource: Resource, density: number, callback: AsyncCallback<string>): void +getPluralStringValue(resId: number, num: number, callback: AsyncCallback<string>): void -Obtains the Base64 code of an image with the screen density corresponding to the specified resource object. This API uses an asynchronous callback to return the result. +Obtains the singular-plural string corresponding to the specified resource ID based on the specified number. This API uses an asynchronous callback to return the result. **System capability**: SystemCapability.Global.ResourceManager -**Model restriction**: This API can be used only in the stage model. - **Parameters** -| Name | Type | Mandatory | Description | -| -------- | --------------------------- | ---- | ------------------------ | -| resource | [Resource](#resource9) | Yes | Resource object. | -| [density](#screendensity) | number | Yes | Screen density. The value **0** indicates the default screen density. | +| Name | Type | Mandatory | Description | +| -------- | --------------------------- | ---- | ------------------------------- | +| resId | number | Yes | Resource ID. | +| num | number | Yes | Number. | | callback | AsyncCallback<string> | Yes | Callback used to return the result.| **Error codes** @@ -1259,48 +1276,84 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco | -------- | ---------------------------------------- | | 9001001 | If the resId invalid. | | 9001002 | If the resource not found by resId. | +| 9001006 | If the resource re-ref too much. | **Example** ```ts - let resource = { - bundleName: "com.example.myapplication", - moduleName: "entry", - id: $r('app.media.test').id - }; try { - this.context.resourceManager.getMediaContentBase64(resource, 120, (error, value) => { - if (error != null) { - console.error(`callback getMediaContentBase64 failed, error code: ${error.code}, message: ${error.message}.`); - } else { - let media = value; - } + this.context.resourceManager.getPluralStringValue($r("app.plural.test").id, 1, (error, value) => { + if (error != null) { + console.log("error is " + error); + } else { + let str = value; + } }); } catch (error) { - console.error(`callback getMediaContentBase64 failed, error code: ${error.code}, message: ${error.message}.`); + console.error(`callback getPluralStringValue failed, error code: ${error.code}, message: ${error.message}.`); } ``` -### getMediaContentBase649+ +### getPluralStringValue9+ -getMediaContentBase64(resource: Resource): Promise<string> +getPluralStringValue(resId: number, num: number): Promise<string> -Obtains the Base64 code of the image corresponding to the specified resource object. This API uses a promise to return the result. +Obtains the singular-plural string corresponding to the specified resource ID based on the specified number. This API uses a promise to return the result. **System capability**: SystemCapability.Global.ResourceManager -**Model restriction**: This API can be used only in the stage model. - **Parameters** -| Name | Type | Mandatory | Description | -| -------- | ---------------------- | ---- | ---- | -| resource | [Resource](#resource9) | Yes | Resource object.| +| Name | Type | Mandatory | Description | +| ----- | ------ | ---- | ----- | +| resId | number | Yes | Resource ID.| +| num | number | Yes | Number. | **Return value** | Type | Description | | --------------------- | ------------------------- | -| Promise<string> | Promise used to return the result.| +| Promise<string> | Promise used to return the result.| + +**Error codes** + +For details about the error codes, see [Resource Manager Error Codes](../errorcodes/errorcode-resource-manager.md). + +| ID| Error Message| +| -------- | ---------------------------------------- | +| 9001001 | If the resId invalid. | +| 9001002 | If the resource not found by resId. | +| 9001006 | If the resource re-ref too much. | + +**Example** + ```ts + try { + this.context.resourceManager.getPluralStringValue($r("app.plural.test").id, 1).then(value => { + let str = value; + }).catch(error => { + console.log("getPluralStringValue promise error is " + error); + }); + } catch (error) { + console.error(`promise getPluralStringValue failed, error code: ${error.code}, message: ${error.message}.`); + } + ``` + +### getPluralStringValue9+ + +getPluralStringValue(resource: Resource, num: number, callback: AsyncCallback<string>): void + +Obtains the singular-plural string corresponding to the specified resource object based on the specified number. This API uses an asynchronous callback to return the result. + +**System capability**: SystemCapability.Global.ResourceManager + +**Model restriction**: This API can be used only in the stage model. + +**Parameters** + +| Name | Type | Mandatory | Description | +| -------- | --------------------------- | ---- | ------------------------------------ | +| resource | [Resource](#resource9) | Yes | Resource object. | +| num | number | Yes | Number. | +| callback | AsyncCallback<string> | Yes | Callback used to return the result.| **Error codes** @@ -1310,30 +1363,33 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco | -------- | ---------------------------------------- | | 9001001 | If the resId invalid. | | 9001002 | If the resource not found by resId. | +| 9001006 | If the resource re-ref too much. | **Example** ```ts let resource = { - bundleName: "com.example.myapplication", - moduleName: "entry", - id: $r('app.media.test').id + bundleName: "com.example.myapplication", + moduleName: "entry", + id: $r('app.plural.test').id }; try { - this.context.resourceManager.getMediaContentBase64(resource).then(value => { - let media = value; - }).catch(error => { - console.log("getMediaContentBase64 promise error is " + error); + this.context.resourceManager.getPluralStringValue(resource, 1, (error, value) => { + if (error != null) { + console.log("error is " + error); + } else { + let str = value; + } }); } catch (error) { - console.error(`promise getMediaContentBase64 failed, error code: ${error.code}, message: ${error.message}.`); + console.error(`callback getPluralStringValue failed, error code: ${error.code}, message: ${error.message}.`); } ``` -### getMediaContentBase6410+ +### getPluralStringValue9+ -getMediaContentBase64(resource: Resource, density: number): Promise<string> +getPluralStringValue(resource: Resource, num: number): Promise<string> -Obtains the Base64 code of an image with the screen density corresponding to the specified resource object. This API uses a promise to return the result. +Obtains the singular-plural string corresponding to the specified resource object based on the specified number. This API uses a promise to return the result. **System capability**: SystemCapability.Global.ResourceManager @@ -1344,13 +1400,13 @@ Obtains the Base64 code of an image with the screen density corresponding to the | Name | Type | Mandatory | Description | | -------- | ---------------------- | ---- | ---- | | resource | [Resource](#resource9) | Yes | Resource object.| -| [density](#screendensity) | number | Yes | Screen density. The value **0** indicates the default screen density. | +| num | number | Yes | Number. | **Return value** -| Type | Description | -| --------------------- | ------------------------- | -| Promise<string> | Promise used to return the result.| +| Type | Description | +| --------------------- | ------------------------------ | +| Promise<string> | Promise used to return the result.| **Error codes** @@ -1360,159 +1416,178 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco | -------- | ---------------------------------------- | | 9001001 | If the resId invalid. | | 9001002 | If the resource not found by resId. | +| 9001006 | If the resource re-ref too much. | **Example** ```ts let resource = { - bundleName: "com.example.myapplication", - moduleName: "entry", - id: $r('app.media.test').id + bundleName: "com.example.myapplication", + moduleName: "entry", + id: $r('app.plural.test').id }; try { - this.context.resourceManager.getMediaContentBase64(resource, 120).then(value => { - let media = value; + this.context.resourceManager.getPluralStringValue(resource, 1).then(value => { + let str = value; }).catch(error => { - console.error(`promise getMediaContentBase64 failed, error code: ${error.code}, message: ${error.message}.`); + console.log("getPluralStringValue promise error is " + error); }); } catch (error) { - console.error(`promise getMediaContentBase64 failed, error code: ${error.code}, message: ${error.message}.`); + console.error(`promise getPluralStringValue failed, error code: ${error.code}, message: ${error.message}.`); } ``` -### getConfiguration +### getPluralStringByName9+ -getConfiguration(callback: AsyncCallback<Configuration>): void +getPluralStringByName(resName: string, num: number, callback: AsyncCallback<string>): void -Obtains the device configuration. This API uses an asynchronous callback to return the result. +Obtains the plural string corresponding to the specified resource name based on the specified number. This API uses an asynchronous callback to return the result. **System capability**: SystemCapability.Global.ResourceManager **Parameters** -| Name | Type | Mandatory | Description | -| -------- | ---------------------------------------- | ---- | ------------------------- | -| callback | AsyncCallback<[Configuration](#configuration)> | Yes | Callback used to return the result.| +| Name | Type | Mandatory | Description | +| -------- | --------------------------- | ---- | ----------------------------- | +| resName | string | Yes | Resource name. | +| num | number | Yes | Number. | +| callback | AsyncCallback<string> | Yes | Callback used to return the result.| + +**Error codes** + +For details about the error codes, see [Resource Manager Error Codes](../errorcodes/errorcode-resource-manager.md). + +| ID| Error Message| +| -------- | ---------------------------------------- | +| 9001003 | If the resName invalid. | +| 9001004 | If the resource not found by resName. | +| 9001006 | If the resource re-ref too much. | **Example** ```ts try { - this.context.resourceManager.getConfiguration((error, value) => { + this.context.resourceManager.getPluralStringByName("test", 1, (error, value) => { if (error != null) { - console.error("getConfiguration callback error is " + error); + console.log("error is " + error); } else { - let direction = value.direction; - let locale = value.locale; + let str = value; } }); } catch (error) { - console.error("getConfiguration callback error is " + error); + console.error(`callback getPluralStringByName failed, error code: ${error.code}, message: ${error.message}.`); } ``` +### getPluralStringByName9+ -### getConfiguration - -getConfiguration(): Promise<Configuration> +getPluralStringByName(resName: string, num: number): Promise<string> -Obtains the device configuration. This API uses a promise to return the result. +Obtains the plural string corresponding to the specified resource name based on the specified number. This API uses a promise to return the result. **System capability**: SystemCapability.Global.ResourceManager +**Parameters** + +| Name | Type | Mandatory | Description | +| ------- | ------ | ---- | ---- | +| resName | string | Yes | Resource name.| +| num | number | Yes | Number. | + **Return value** -| Type | Description | -| ---------------------------------------- | ---------------- | -| Promise<[Configuration](#configuration)> | Promise used to return the result.| +| Type | Description | +| --------------------- | ---------------------- | +| Promise<string> | Promise used to return the result.| + +**Error codes** + +For details about the error codes, see [Resource Manager Error Codes](../errorcodes/errorcode-resource-manager.md). + +| ID| Error Message| +| -------- | ---------------------------------------- | +| 9001003 | If the resName invalid. | +| 9001004 | If the resource not found by resName. | +| 9001006 | If the resource re-ref too much. | **Example** ```ts try { - this.context.resourceManager.getConfiguration().then(value => { - let direction = value.direction; - let locale = value.locale; + this.context.resourceManager.getPluralStringByName("test", 1).then(value => { + let str = value; }).catch(error => { - console.error("getConfiguration promise error is " + error); + console.log("getPluralStringByName promise error is " + error); }); } catch (error) { - console.error("getConfiguration promise error is " + error); + console.error(`promise getPluralStringByName failed, error code: ${error.code}, message: ${error.message}.`); } ``` +### getMediaContentSync10+ -### getDeviceCapability - -getDeviceCapability(callback: AsyncCallback<DeviceCapability>): void +getMediaContentSync(resId: number, density?: number): Uint8Array -Obtains the device capability. This API uses an asynchronous callback to return the result. +Obtains the content of the media file (with the default or specified screen density) corresponding to the specified resource ID. This API returns the result synchronously. **System capability**: SystemCapability.Global.ResourceManager **Parameters** -| Name | Type | Mandatory | Description | -| -------- | ---------------------------------------- | ---- | ---------------------------- | -| callback | AsyncCallback<[DeviceCapability](#devicecapability)> | Yes | Callback used to return the result.| - -**Example** - ```ts - try { - this.context.resourceManager.getDeviceCapability((error, value) => { - if (error != null) { - console.error("getDeviceCapability callback error is " + error); - } else { - let screenDensity = value.screenDensity; - let deviceType = value.deviceType; - } - }); - } catch (error) { - console.error("getDeviceCapability callback error is " + error); - } - ``` - - -### getDeviceCapability +| Name | Type | Mandatory | Description | +| ----- | ------ | ---- | ----- | +| resId | number | Yes | Resource ID.| +| [density](#screendensity) | number | No | Screen density. The default value or value **0** indicates the default screen density.| -getDeviceCapability(): Promise<DeviceCapability> +**Return value** -Obtains the device capability. This API uses a promise to return the result. +| Type | Description | +| -------- | ----------- | +| Uint8Array | Content of the media file corresponding to the specified resource ID.| -**System capability**: SystemCapability.Global.ResourceManager +**Error codes** -**Return value** +For details about the error codes, see [Resource Manager Error Codes](../errorcodes/errorcode-resource-manager.md). -| Type | Description | -| ---------------------------------------- | ------------------- | -| Promise<[DeviceCapability](#devicecapability)> | Promise used to return the result.| +| ID| Error Message| +| -------- | ---------------------------------------- | +| 9001001 | If the resId invalid. | +| 9001002 | If the resource not found by resId. | **Example** ```ts try { - this.context.resourceManager.getDeviceCapability().then(value => { - let screenDensity = value.screenDensity; - let deviceType = value.deviceType; - }).catch(error => { - console.error("getDeviceCapability promise error is " + error); - }); + this.context.resourceManager.getMediaContentSync($r('app.media.test').id); // Default screen density } catch (error) { - console.error("getDeviceCapability promise error is " + error); + console.error(`getMediaContentSync failed, error code: ${error.code}, message: ${error.message}.`); + } + + try { + this.context.resourceManager.getMediaContentSync($r('app.media.test').id, 120); // Specified screen density + } catch (error) { + console.error(`getMediaContentSync failed, error code: ${error.code}, message: ${error.message}.`); } ``` -### getPluralStringValue9+ +### getMediaContentSync10+ -getPluralStringValue(resId: number, num: number, callback: AsyncCallback<string>): void +getMediaContentSync(resource: Resource, density?: number): Uint8Array -Obtains the singular-plural string corresponding to the specified resource ID based on the specified number. This API uses an asynchronous callback to return the result. +Obtains the content of the media file (with the default or specified screen density) corresponding to the specified resource object. This API returns the result synchronously. **System capability**: SystemCapability.Global.ResourceManager +**Model restriction**: This API can be used only in the stage model. + **Parameters** -| Name | Type | Mandatory | Description | -| -------- | --------------------------- | ---- | ------------------------------- | -| resId | number | Yes | Resource ID. | -| num | number | Yes | Number. | -| callback | AsyncCallback<string> | Yes | Callback used to return the result.| +| Name | Type | Mandatory | Description | +| ----- | ------ | ---- | ----- | +| resource | [Resource](#resource9) | Yes | Resource object.| +| [density](#screendensity) | number | No | Screen density. The default value or value **0** indicates the default screen density.| + +**Return value** + +| Type | Description | +| --------------------- | ----------- | +| Uint8Array | Content of the media file corresponding to the specified resource object| **Error codes** @@ -1522,44 +1597,41 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco | -------- | ---------------------------------------- | | 9001001 | If the resId invalid. | | 9001002 | If the resource not found by resId. | -| 9001006 | If the resource re-ref too much. | **Example** ```ts + let resource = { + bundleName: "com.example.myapplication", + moduleName: "entry", + id: $r('app.media.test').id + }; try { - this.context.resourceManager.getPluralStringValue($r("app.plural.test").id, 1, (error, value) => { - if (error != null) { - console.log("error is " + error); - } else { - let str = value; - } - }); + this.context.resourceManager.getMediaContentSync(resource); // Default screen density } catch (error) { - console.error(`callback getPluralStringValue failed, error code: ${error.code}, message: ${error.message}.`); + console.error(`getMediaContentSync failed, error code: ${error.code}, message: ${error.message}.`); } - ``` + try { + this.context.resourceManager.getMediaContentSync(resource, 120); // Specified screen density + } catch (error) { + console.error(`getMediaContentSync failed, error code: ${error.code}, message: ${error.message}.`); + } + ``` -### getPluralStringValue9+ +### getMediaContent9+ -getPluralStringValue(resId: number, num: number): Promise<string> +getMediaContent(resId: number, callback: AsyncCallback<Uint8Array>): void -Obtains the singular-plural string corresponding to the specified resource ID based on the specified number. This API uses a promise to return the result. +Obtains the content of the media file corresponding to the specified resource ID. This API uses an asynchronous callback to return the result. **System capability**: SystemCapability.Global.ResourceManager **Parameters** -| Name | Type | Mandatory | Description | -| ----- | ------ | ---- | ----- | -| resId | number | Yes | Resource ID.| -| num | number | Yes | Number. | - -**Return value** - -| Type | Description | -| --------------------- | ------------------------- | -| Promise<string> | Promise used to return the result.| +| Name | Type | Mandatory | Description | +| -------- | ------------------------------- | ---- | ------------------ | +| resId | number | Yes | Resource ID. | +| callback | AsyncCallback<Uint8Array> | Yes | Callback used to return the result.| **Error codes** @@ -1569,38 +1641,37 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco | -------- | ---------------------------------------- | | 9001001 | If the resId invalid. | | 9001002 | If the resource not found by resId. | -| 9001006 | If the resource re-ref too much. | **Example** ```ts try { - this.context.resourceManager.getPluralStringValue($r("app.plural.test").id, 1).then(value => { - let str = value; - }).catch(error => { - console.log("getPluralStringValue promise error is " + error); + this.context.resourceManager.getMediaContent($r('app.media.test').id, (error, value) => { + if (error != null) { + console.log("error is " + error); + } else { + let media = value; + } }); } catch (error) { - console.error(`promise getPluralStringValue failed, error code: ${error.code}, message: ${error.message}.`); + console.error(`callback getMediaContent failed, error code: ${error.code}, message: ${error.message}.`); } ``` -### getPluralStringValue9+ +### getMediaContent10+ -getPluralStringValue(resource: Resource, num: number, callback: AsyncCallback<string>): void +getMediaContent(resId: number, density: number, callback: AsyncCallback<Uint8Array>): void -Obtains the singular-plural string corresponding to the specified resource object based on the specified number. This API uses an asynchronous callback to return the result. +Obtains the content of the media file (with the specified screen density) corresponding to the specified resource ID. This API uses an asynchronous callback to return the result. **System capability**: SystemCapability.Global.ResourceManager -**Model restriction**: This API can be used only in the stage model. - **Parameters** -| Name | Type | Mandatory | Description | -| -------- | --------------------------- | ---- | ------------------------------------ | -| resource | [Resource](#resource9) | Yes | Resource object. | -| num | number | Yes | Number. | -| callback | AsyncCallback<string> | Yes | Callback used to return the result.| +| Name | Type | Mandatory | Description | +| -------- | ------------------------------- | ---- | ------------------ | +| resId | number | Yes | Resource ID. | +| [density](#screendensity) | number | Yes | Screen density. The value **0** indicates the default screen density. | +| callback | AsyncCallback<Uint8Array> | Yes | Callback used to return the result.| **Error codes** @@ -1610,50 +1681,41 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco | -------- | ---------------------------------------- | | 9001001 | If the resId invalid. | | 9001002 | If the resource not found by resId. | -| 9001006 | If the resource re-ref too much. | **Example** ```ts - let resource = { - bundleName: "com.example.myapplication", - moduleName: "entry", - id: $r('app.plural.test').id - }; try { - this.context.resourceManager.getPluralStringValue(resource, 1, (error, value) => { - if (error != null) { - console.log("error is " + error); - } else { - let str = value; - } + this.context.resourceManager.getMediaContent($r('app.media.test').id, 120, (error, value) => { + if (error != null) { + console.error(`callback getMediaContent failed, error code: ${error.code}, message: ${error.message}.`); + } else { + let media = value; + } }); } catch (error) { - console.error(`callback getPluralStringValue failed, error code: ${error.code}, message: ${error.message}.`); + console.error(`callback getMediaContent failed, error code: ${error.code}, message: ${error.message}.`); } ``` -### getPluralStringValue9+ +### getMediaContent9+ -getPluralStringValue(resource: Resource, num: number): Promise<string> +getMediaContent(resId: number): Promise<Uint8Array> -Obtains the singular-plural string corresponding to the specified resource object based on the specified number. This API uses a promise to return the result. +Obtains the content of the media file corresponding to the specified resource ID. This API uses a promise to return the result. **System capability**: SystemCapability.Global.ResourceManager -**Model restriction**: This API can be used only in the stage model. - **Parameters** -| Name | Type | Mandatory | Description | -| -------- | ---------------------- | ---- | ---- | -| resource | [Resource](#resource9) | Yes | Resource object.| -| num | number | Yes | Number. | +| Name | Type | Mandatory | Description | +| ----- | ------ | ---- | ----- | +| resId | number | Yes | Resource ID.| **Return value** -| Type | Description | -| --------------------- | ------------------------------ | -| Promise<string> | Promise used to return the result.| +| Type | Description | +| ------------------------- | -------------- | +| Promise<Uint8Array> | Promise used to return the result.| **Error codes** @@ -1663,41 +1725,40 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco | -------- | ---------------------------------------- | | 9001001 | If the resId invalid. | | 9001002 | If the resource not found by resId. | -| 9001006 | If the resource re-ref too much. | **Example** ```ts - let resource = { - bundleName: "com.example.myapplication", - moduleName: "entry", - id: $r('app.plural.test').id - }; try { - this.context.resourceManager.getPluralStringValue(resource, 1).then(value => { - let str = value; + this.context.resourceManager.getMediaContent($r('app.media.test').id).then(value => { + let media = value; }).catch(error => { - console.log("getPluralStringValue promise error is " + error); + console.log("getMediaContent promise error is " + error); }); } catch (error) { - console.error(`promise getPluralStringValue failed, error code: ${error.code}, message: ${error.message}.`); + console.error(`promise getMediaContent failed, error code: ${error.code}, message: ${error.message}.`); } ``` +### getMediaContent10+ -### getRawFileContent9+ - -getRawFileContent(path: string, callback: AsyncCallback<Uint8Array>): void +getMediaContent(resId: number, density: number): Promise<Uint8Array> -Obtains the content of the raw file in the **resources/rawfile** directory. This API uses an asynchronous callback to return the result. +Obtains the content of the media file (with the specified screen density) corresponding to the specified resource ID. This API uses a promise to return the result. **System capability**: SystemCapability.Global.ResourceManager **Parameters** -| Name | Type | Mandatory | Description | -| -------- | ------------------------------- | ---- | ----------------------- | -| path | string | Yes | Path of the raw file. | -| callback | AsyncCallback<Uint8Array> | Yes | Callback used to return the result.| +| Name | Type | Mandatory | Description | +| ----- | ------ | ---- | ----- | +| resId | number | Yes | Resource ID.| +| [density](#screendensity) | number | Yes | Screen density. The value **0** indicates the default screen density. | + +**Return value** + +| Type | Description | +| ------------------------- | -------------- | +| Promise<Uint8Array> | Promise used to return the result.| **Error codes** @@ -1705,42 +1766,38 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco | ID| Error Message| | -------- | ---------------------------------------- | -| 9001005 | If the resource not found by path. | +| 9001001 | If the resId invalid. | +| 9001002 | If the resource not found by resId. | **Example** ```ts try { - this.context.resourceManager.getRawFileContent("test.xml", (error, value) => { - if (error != null) { - console.log("error is " + error); - } else { - let rawFile = value; - } + this.context.resourceManager.getMediaContent($r('app.media.test').id, 120).then(value => { + let media = value; + }).catch(error => { + console.error(`promise getMediaContent failed, error code: ${error.code}, message: ${error.message}.`); }); } catch (error) { - console.error(`callback getRawFileContent failed, error code: ${error.code}, message: ${error.message}.`); + console.error(`promise getMediaContent failed, error code: ${error.code}, message: ${error.message}.`); } ``` -### getRawFileContent9+ +### getMediaContent9+ -getRawFileContent(path: string): Promise<Uint8Array> +getMediaContent(resource: Resource, callback: AsyncCallback<Uint8Array>): void -Obtains the content of the raw file in the **resources/rawfile** directory. This API uses a promise to return the result. +Obtains the content of the media file corresponding to the specified resource object. This API uses an asynchronous callback to return the result. **System capability**: SystemCapability.Global.ResourceManager -**Parameters** - -| Name | Type | Mandatory | Description | -| ---- | ------ | ---- | ----------- | -| path | string | Yes | Path of the raw file.| +**Model restriction**: This API can be used only in the stage model. -**Return value** +**Parameters** -| Type | Description | -| ------------------------- | ----------- | -| Promise<Uint8Array> | Promise used to return the result.| +| Name | Type | Mandatory | Description | +| -------- | ------------------------------- | ---- | ------------------ | +| resource | [Resource](#resource9) | Yes | Resource object. | +| callback | AsyncCallback<Uint8Array> | Yes | Callback used to return the result.| **Error codes** @@ -1748,36 +1805,46 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco | ID| Error Message| | -------- | ---------------------------------------- | -| 9001005 | If the resource not found by path. | +| 9001001 | If the resId invalid. | +| 9001002 | If the resource not found by resId. | **Example** ```ts + let resource = { + bundleName: "com.example.myapplication", + moduleName: "entry", + id: $r('app.media.test').id + }; try { - this.context.resourceManager.getRawFileContent("test.xml").then(value => { - let rawFile = value; - }).catch(error => { - console.log("getRawFileContent promise error is " + error); + this.context.resourceManager.getMediaContent(resource, (error, value) => { + if (error != null) { + console.log("error is " + error); + } else { + let media = value; + } }); } catch (error) { - console.error(`promise getRawFileContent failed, error code: ${error.code}, message: ${error.message}.`); + console.error(`callback getMediaContent failed, error code: ${error.code}, message: ${error.message}.`); } ``` +### getMediaContent10+ -### getRawFd9+ - -getRawFd(path: string, callback: AsyncCallback<RawFileDescriptor>): void +getMediaContent(resource: Resource, density: number, callback: AsyncCallback<Uint8Array>): void -Obtains the descriptor of the raw file in the **resources/rawfile** directory. This API uses an asynchronous callback to return the result. +Obtains the content of the media file (with the specified screen density) corresponding to the specified resource object. This API uses an asynchronous callback to return the result. **System capability**: SystemCapability.Global.ResourceManager +**Model restriction**: This API can be used only in the stage model. + **Parameters** -| Name | Type | Mandatory | Description | -| -------- | ---------------------------------------- | ---- | -------------------------------- | -| path | string | Yes | Path of the raw file. | -| callback | AsyncCallback<[RawFileDescriptor](#rawfiledescriptor8)> | Yes | Callback used to return the result.| +| Name | Type | Mandatory | Description | +| -------- | ------------------------------- | ---- | ------------------ | +| resource | [Resource](#resource9) | Yes | Resource object. | +| [density](#screendensity) | number | Yes | Screen density. The value **0** indicates the default screen density. | +| callback | AsyncCallback<Uint8Array> | Yes | Callback used to return the result.| **Error codes** @@ -1785,44 +1852,50 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco | ID| Error Message| | -------- | ---------------------------------------- | -| 9001005 | If the resource not found by path. | +| 9001001 | If the resId invalid. | +| 9001002 | If the resource not found by resId. | **Example** ```ts + let resource = { + bundleName: "com.example.myapplication", + moduleName: "entry", + id: $r('app.media.test').id + }; try { - this.context.resourceManager.getRawFd("test.xml", (error, value) => { - if (error != null) { - console.log(`callback getRawFd failed error code: ${error.code}, message: ${error.message}.`); - } else { - let fd = value.fd; - let offset = value.offset; - let length = value.length; - } + this.context.resourceManager.getMediaContent(resource, 120, (error, value) => { + if (error != null) { + console.error(`callback getMediaContent failed, error code: ${error.code}, message: ${error.message}.`); + } else { + let media = value; + } }); } catch (error) { - console.error(`callback getRawFd failed, error code: ${error.code}, message: ${error.message}.`); + console.error(`callback getMediaContent failed, error code: ${error.code}, message: ${error.message}.`); } ``` -### getRawFd9+ +### getMediaContent9+ -getRawFd(path: string): Promise<RawFileDescriptor> +getMediaContent(resource: Resource): Promise<Uint8Array> -Obtains the descriptor of the raw file in the **resources/rawfile** directory. This API uses a promise to return the result. +Obtains the content of the media file corresponding to the specified resource object. This API uses a promise to return the result. **System capability**: SystemCapability.Global.ResourceManager +**Model restriction**: This API can be used only in the stage model. + **Parameters** -| Name | Type | Mandatory | Description | -| ---- | ------ | ---- | ----------- | -| path | string | Yes | Path of the raw file.| +| Name | Type | Mandatory | Description | +| -------- | ---------------------- | ---- | ---- | +| resource | [Resource](#resource9) | Yes | Resource object.| **Return value** -| Type | Description | -| ---------------------------------------- | ------------------- | -| Promise<[RawFileDescriptor](#rawfiledescriptor8)> | Promise used to return the result.| +| Type | Description | +| ------------------------- | ------------------- | +| Promise<Uint8Array> | Promise used to return the result.| **Error codes** @@ -1830,37 +1903,49 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco | ID| Error Message| | -------- | ---------------------------------------- | -| 9001005 | If the resource not found by path. | +| 9001001 | If the resId invalid. | +| 9001002 | If the resource not found by resId. | **Example** ```ts + let resource = { + bundleName: "com.example.myapplication", + moduleName: "entry", + id: $r('app.media.test').id + }; try { - this.context.resourceManager.getRawFd("test.xml").then(value => { - let fd = value.fd; - let offset = value.offset; - let length = value.length; + this.context.resourceManager.getMediaContent(resource).then(value => { + let media = value; }).catch(error => { - console.log(`promise getRawFd error error code: ${error.code}, message: ${error.message}.`); + console.log("getMediaContent promise error is " + error); }); } catch (error) { - console.error(`promise getRawFd failed, error code: ${error.code}, message: ${error.message}.`); + console.error(`promise getMediaContent failed, error code: ${error.code}, message: ${error.message}.`); } ``` -### getRawFileList10+ +### getMediaContent10+ -getRawFileList(path: string, callback: AsyncCallback<Array\>): void; +getMediaContent(resource: Resource, density: number): Promise<Uint8Array> -Obtains the list of files in the **resources/rawfile** directory. This API uses an asynchronous callback to return the result. +Obtains the content of the media file (with the specified screen density) corresponding to the specified resource object. This API uses a promise to return the result. **System capability**: SystemCapability.Global.ResourceManager +**Model restriction**: This API can be used only in the stage model. + **Parameters** -| Name | Type | Mandatory | Description | -| -------- | ------------------------------- | ---- | ----------------------- | -| path | string | Yes | Path of the **rawfile** folder. | -| callback | AsyncCallback<Array\> | Yes| Callback used to return the result.| +| Name | Type | Mandatory | Description | +| -------- | ---------------------- | ---- | ---- | +| resource | [Resource](#resource9) | Yes | Resource object.| +| [density](#screendensity) | number | Yes | Screen density. The value **0** indicates the default screen density. | + +**Return value** + +| Type | Description | +| ------------------------- | ------------------- | +| Promise<Uint8Array> | Promise used to return the result.| **Error codes** @@ -1868,42 +1953,41 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco | ID| Error Message| | -------- | ---------------------------------------- | -| 9001005 | If the resource not found by path. | +| 9001001 | If the resId invalid. | +| 9001002 | If the resource not found by resId. | **Example** ```ts - try { // Passing "" means to obtain the list of files in the root directory of the raw file. - this.context.resourceManager.getRawFileList("", (error, value) => { - if (error != null) { - console.error(`callback getRawFileList failed, error code: ${error.code}, message: ${error.message}.`); - } else { - let rawFile = value; - } + let resource = { + bundleName: "com.example.myapplication", + moduleName: "entry", + id: $r('app.media.test').id + }; + try { + this.context.resourceManager.getMediaContent(resource, 120).then(value => { + let media = value; + }).catch(error => { + console.error(`promise getMediaContent failed, error code: ${error.code}, message: ${error.message}.`); }); } catch (error) { - console.error(`callback getRawFileList failed, error code: ${error.code}, message: ${error.message}.`); + console.error(`promise getMediaContent failed, error code: ${error.code}, message: ${error.message}.`); } ``` -### getRawFileList10+ +### getMediaByName9+ -getRawFileList(path: string): Promise<Array\> +getMediaByName(resName: string, callback: AsyncCallback<Uint8Array>): void -Obtains the list of files in the **resources/rawfile** directory. This API uses a promise to return the result. +Obtains the content of the media file corresponding to the specified resource ID. This API uses an asynchronous callback to return the result. **System capability**: SystemCapability.Global.ResourceManager **Parameters** -| Name | Type | Mandatory | Description | -| ---- | ------ | ---- | ----------- | -| path | string | Yes | Path of the **rawfile** folder.| - -**Return value** - -| Type | Description | -| ------------------------- | ----------- | -| Promise<Array\> | List of files in the **rawfile** folder.| +| Name | Type | Mandatory | Description | +| -------- | ------------------------------- | ---- | ------------------ | +| resName | string | Yes | Resource name. | +| callback | AsyncCallback<Uint8Array> | Yes | Callback used to return the result.| **Error codes** @@ -1911,35 +1995,39 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco | ID| Error Message| | -------- | ---------------------------------------- | -| 9001005 | If the resource not found by path. | +| 9001003 | If the resName invalid. | +| 9001004 | If the resource not found by resName. | **Example** ```ts - try { // Passing "" means to obtain the list of files in the root directory of the raw file. - this.context.resourceManager.getRawFileList("").then(value => { - let rawFile = value; - }).catch(error => { - console.error(`promise getRawFileList failed, error code: ${error.code}, message: ${error.message}.`); + try { + this.context.resourceManager.getMediaByName("test", (error, value) => { + if (error != null) { + console.log("error is " + error); + } else { + let media = value; + } }); } catch (error) { - console.error(`promise getRawFileList failed, error code: ${error.code}, message: ${error.message}.`); + console.error(`callback getMediaByName failed, error code: ${error.code}, message: ${error.message}.`); } ``` -### closeRawFd9+ +### getMediaByName10+ -closeRawFd(path: string, callback: AsyncCallback<void>): void +getMediaByName(resName: string, density: number, callback: AsyncCallback<Uint8Array>): void -Closes the descriptor of the raw file in the **resources/rawfile** directory. This API uses an asynchronous callback to return the result. +Obtains the content of the media file (with the specified screen density) corresponding to the specified resource ID. This API uses an asynchronous callback to return the result. **System capability**: SystemCapability.Global.ResourceManager **Parameters** -| Name | Type | Mandatory | Description | -| -------- | ------------------------- | ---- | ----------- | -| path | string | Yes | Path of the raw file.| -| callback | AsyncCallback<void> | Yes | Callback used to return the result. | +| Name | Type | Mandatory | Description | +| -------- | ------------------------------- | ---- | ------------------ | +| resName | string | Yes | Resource name. | +| [density](#screendensity) | number | Yes | Screen density. The value **0** indicates the default screen density. | +| callback | AsyncCallback<Uint8Array> | Yes | Callback used to return the result.| **Error codes** @@ -1947,41 +2035,43 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco | ID| Error Message| | -------- | ---------------------------------------- | -| 9001005 | The resource not found by path. | +| 9001003 | If the resName invalid. | +| 9001004 | If the resource not found by resName. | **Example** ```ts try { - this.context.resourceManager.closeRawFd("test.xml", (error, value) => { - if (error != null) { - console.log("error is " + error); - } + this.context.resourceManager.getMediaByName("test", 120, (error, value) => { + if (error != null) { + console.error(`callback getMediaByName failed, error code: ${error.code}, message: ${error.message}.`); + } else { + let media = value; + } }); } catch (error) { - console.error(`callback closeRawFd failed, error code: ${error.code}, message: ${error.message}.`); + console.error(`callback getMediaByName failed, error code: ${error.code}, message: ${error.message}.`); } - ``` -### closeRawFd9+ +### getMediaByName9+ -closeRawFd(path: string): Promise<void> +getMediaByName(resName: string): Promise<Uint8Array> -Closes the descriptor of the raw file in the **resources/rawfile** directory. This API uses a promise to return the result. +Obtains the content of the media file corresponding to the specified resource name. This API uses a promise to return the result. **System capability**: SystemCapability.Global.ResourceManager **Parameters** -| Name | Type | Mandatory | Description | -| ---- | ------ | ---- | ----------- | -| path | string | Yes | Path of the raw file.| +| Name | Type | Mandatory | Description | +| ------- | ------ | ---- | ---- | +| resName | string | Yes | Resource name.| **Return value** -| Type | Description | -| ------------------- | ---- | -| Promise<void> | Promise that returns no value.| +| Type | Description | +| ------------------------- | ------------- | +| Promise<Uint8Array> | Promise used to return the result.| **Error codes** @@ -1989,97 +2079,85 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco | ID| Error Message| | -------- | ---------------------------------------- | -| 9001005 | If the resource not found by path. | +| 9001003 | If the resName invalid. | +| 9001004 | If the resource not found by resName. | **Example** ```ts try { - this.context.resourceManager.closeRawFd("test.xml").then(value => { - let result = value; + this.context.resourceManager.getMediaByName("test").then(value => { + let media = value; }).catch(error => { - console.log("closeRawFd promise error is " + error); + console.log("getMediaByName promise error is " + error); }); } catch (error) { - console.error(`promise closeRawFd failed, error code: ${error.code}, message: ${error.message}.`); + console.error(`promise getMediaByName failed, error code: ${error.code}, message: ${error.message}.`) } ``` -### release7+ +### getMediaByName10+ -release() +getMediaByName(resName: string, density: number): Promise<Uint8Array> -Releases a created **resourceManager** object. +Obtains the content of the media file (with the specified screen density) corresponding to the specified resource name. This API uses a promise to return the result. **System capability**: SystemCapability.Global.ResourceManager -**Example** - ```ts - try { - this.context.resourceManager.release(); - } catch (error) { - console.error("release error is " + error); - } - ``` +**Parameters** -### getStringByName9+ +| Name | Type | Mandatory | Description | +| ------- | ------ | ---- | ---- | +| resName | string | Yes | Resource name.| +| [density](#screendensity) | number | Yes | Screen density. The value **0** indicates the default screen density. | -getStringByName(resName: string, callback: AsyncCallback<string>): void +**Return value** -Obtains the string corresponding to the specified resource name. This API uses an asynchronous callback to return the result. +| Type | Description | +| ------------------------- | ------------- | +| Promise<Uint8Array> | Promise used to return the result.| -**System capability**: SystemCapability.Global.ResourceManager +**Error codes** -**Parameters** - -| Name | Type | Mandatory | Description | -| -------- | --------------------------- | ---- | --------------- | -| resName | string | Yes | Resource name. | -| callback | AsyncCallback<string> | Yes | Callback used to return the result.| - -**Error codes** - -For details about the error codes, see [Resource Manager Error Codes](../errorcodes/errorcode-resource-manager.md). +For details about the error codes, see [Resource Manager Error Codes](../errorcodes/errorcode-resource-manager.md). | ID| Error Message| | -------- | ---------------------------------------- | | 9001003 | If the resName invalid. | | 9001004 | If the resource not found by resName. | -| 9001006 | If the resource re-ref too much. | **Example** ```ts try { - this.context.resourceManager.getStringByName("test", (error, value) => { - if (error != null) { - console.log("error is " + error); - } else { - let string = value; - } + this.context.resourceManager.getMediaByName("test", 120).then(value => { + let media = value; + }).catch(error => { + console.error(`promise getMediaByName failed, error code: ${error.code}, message: ${error.message}.`); }); } catch (error) { - console.error(`callback getStringByName failed, error code: ${error.code}, message: ${error.message}.`); + console.error(`promise getMediaByName failed, error code: ${error.code}, message: ${error.message}.`); } ``` -### getStringByName9+ +### getMediaContentBase64Sync10+ -getStringByName(resName: string): Promise<string> +getMediaContentBase64Sync(resId: number, density?: number): string -Obtains the string corresponding to the specified resource name. This API uses a promise to return the result. +Obtains the Base64 code of the image (with the default or specified screen density) corresponding to the specified resource ID. **System capability**: SystemCapability.Global.ResourceManager **Parameters** -| Name | Type | Mandatory | Description | -| ------- | ------ | ---- | ---- | -| resName | string | Yes | Resource name.| +| Name | Type | Mandatory | Description | +| ----- | ------ | ---- | ----- | +| resId | number | Yes | Resource ID.| +| [density](#screendensity) | number | No | Screen density. The default value or value **0** indicates the default screen density.| **Return value** -| Type | Description | -| --------------------- | ---------- | -| Promise<string> | Promise used to return the result.| +| Type | Description | +| -------- | ----------- | +| string | Base64 code of the image corresponding to the specified resource ID.| **Error codes** @@ -2087,82 +2165,46 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco | ID| Error Message| | -------- | ---------------------------------------- | -| 9001003 | If the resName invalid. | -| 9001004 | If the resource not found by resName. | -| 9001006 | If the resource re-ref too much. | +| 9001001 | If the resId invalid. | +| 9001002 | If the resource not found by resId. | **Example** ```ts try { - this.context.resourceManager.getStringByName("test").then(value => { - let string = value; - }).catch(error => { - console.log("getStringByName promise error is " + error); - }); + this.context.resourceManager.getMediaContentBase64Sync($r('app.media.test').id); // Default screen density } catch (error) { - console.error(`promise getStringByName failed, error code: ${error.code}, message: ${error.message}.`); + console.error(`getMediaContentBase64Sync failed, error code: ${error.code}, message: ${error.message}.`); } - ``` - -### getStringArrayByName9+ - -getStringArrayByName(resName: string, callback: AsyncCallback<Array<string>>): void - -Obtains the string array corresponding to the specified resource name. This API uses an asynchronous callback to return the result. - -**System capability**: SystemCapability.Global.ResourceManager - -**Parameters** - -| Name | Type | Mandatory | Description | -| -------- | ---------------------------------------- | ---- | ----------------- | -| resName | string | Yes | Resource name. | -| callback | AsyncCallback<Array<string>> | Yes | Callback used to return the result.| - -**Error codes** - -For details about the error codes, see [Resource Manager Error Codes](../errorcodes/errorcode-resource-manager.md). - -| ID| Error Message| -| -------- | ---------------------------------------- | -| 9001003 | If the resName invalid. | -| 9001004 | If the resource not found by resName. | -| 9001006 | If the resource re-ref too much. | -**Example** - ```ts try { - this.context.resourceManager.getStringArrayByName("test", (error, value) => { - if (error != null) { - console.log("error is " + error); - } else { - let strArray = value; - } - }); + this.context.resourceManager.getMediaContentBase64Sync($r('app.media.test').id, 120); // Specified screen density } catch (error) { - console.error(`callback getStringArrayByName failed, error code: ${error.code}, message: ${error.message}.`); + console.error(`getMediaContentBase64Sync failed, error code: ${error.code}, message: ${error.message}.`); } ``` -### getStringArrayByName9+ +### getMediaContentBase64Sync10+ -getStringArrayByName(resName: string): Promise<Array<string>> +getMediaContentBase64Sync(resource: Resource, density?: number): string -Obtains the string array corresponding to the specified resource name. This API uses a promise to return the result. +Obtains the Base64 code of the image (with the default or specified screen density) corresponding to the specified resource object. **System capability**: SystemCapability.Global.ResourceManager +**Model restriction**: This API can be used only in the stage model. + **Parameters** -| Name | Type | Mandatory | Description | -| ------- | ------ | ---- | ---- | -| resName | string | Yes | Resource name.| +| Name | Type | Mandatory | Description | +| ----- | ------ | ---- | ----- | +| resource | [Resource](#resource9) | Yes | Resource object.| +| [density](#screendensity) | number | No | Screen density. The default value or value **0** indicates the default screen density.| **Return value** -| Type | Description | -| ---------------------------------- | ------------ | -| Promise<Array<string>> | Promise used to return the result.| +| Type | Description | +| --------------------- | ----------- | +| string | Base64 code of the media file corresponding to the specified resource object.| **Error codes** @@ -2170,37 +2212,43 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco | ID| Error Message| | -------- | ---------------------------------------- | -| 9001003 | If the resName invalid. | -| 9001004 | If the resource not found by resName. | -| 9001006 | If the resource re-ref too much. | +| 9001001 | If the resId invalid. | +| 9001002 | If the resource not found by resId. | **Example** ```ts + let resource = { + bundleName: "com.example.myapplication", + moduleName: "entry", + id: $r('app.media.test').id + }; try { - this.context.resourceManager.getStringArrayByName("test").then(value => { - let strArray = value; - }).catch(error => { - console.log("getStringArrayByName promise error is " + error); - }); + this.context.resourceManager.getMediaContentBase64Sync(resource); // Default screen density } catch (error) { - console.error(`promise getStringArrayByName failed, error code: ${error.code}, message: ${error.message}.`); + console.error(`getMediaContentBase64Sync failed, error code: ${error.code}, message: ${error.message}.`); + } + + try { + this.context.resourceManager.getMediaContentBase64Sync(resource, 120); // Specified screen density + } catch (error) { + console.error(`getMediaContentBase64Sync failed, error code: ${error.code}, message: ${error.message}.`); } ``` -### getMediaByName9+ +### getMediaContentBase649+ -getMediaByName(resName: string, callback: AsyncCallback<Uint8Array>): void +getMediaContentBase64(resId: number, callback: AsyncCallback<string>): void -Obtains the content of the media file corresponding to the specified resource ID. This API uses an asynchronous callback to return the result. +Obtains the Base64 code of the image corresponding to the specified resource ID. This API uses an asynchronous callback to return the result. **System capability**: SystemCapability.Global.ResourceManager **Parameters** -| Name | Type | Mandatory | Description | -| -------- | ------------------------------- | ---- | ------------------ | -| resName | string | Yes | Resource name. | -| callback | AsyncCallback<Uint8Array> | Yes | Callback used to return the result.| +| Name | Type | Mandatory | Description | +| -------- | --------------------------- | ---- | ------------------------ | +| resId | number | Yes | Resource ID. | +| callback | AsyncCallback<string> | Yes | Callback used to return the result.| **Error codes** @@ -2208,39 +2256,39 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco | ID| Error Message| | -------- | ---------------------------------------- | -| 9001003 | If the resName invalid. | -| 9001004 | If the resource not found by resName. | +| 9001001 | If the resId invalid. | +| 9001002 | If the resource not found by resId. | **Example** ```ts try { - this.context.resourceManager.getMediaByName("test", (error, value) => { - if (error != null) { - console.log("error is " + error); - } else { - let media = value; - } + this.context.resourceManager.getMediaContentBase64($r('app.media.test').id, (error, value) => { + if (error != null) { + console.log("error is " + error); + } else { + let media = value; + } }); } catch (error) { - console.error(`callback getMediaByName failed, error code: ${error.code}, message: ${error.message}.`); + console.error(`callback getMediaContentBase64 failed, error code: ${error.code}, message: ${error.message}.`); } ``` -### getMediaByName10+ +### getMediaContentBase6410+ -getMediaByName(resName: string, density: number, callback: AsyncCallback<Uint8Array>): void +getMediaContentBase64(resId: number, density: number, callback: AsyncCallback<string>): void -Obtains the content of the media file with the screen density corresponding to the specified resource ID. This API uses an asynchronous callback to return the result. +Obtains the Base64 code of an image with the screen density corresponding to the specified resource ID. This API uses an asynchronous callback to return the result. **System capability**: SystemCapability.Global.ResourceManager **Parameters** -| Name | Type | Mandatory | Description | -| -------- | ------------------------------- | ---- | ------------------ | -| resName | string | Yes | Resource name. | +| Name | Type | Mandatory | Description | +| -------- | --------------------------- | ---- | ------------------------ | +| resId | number | Yes | Resource ID. | | [density](#screendensity) | number | Yes | Screen density. The value **0** indicates the default screen density. | -| callback | AsyncCallback<Uint8Array> | Yes | Callback used to return the result.| +| callback | AsyncCallback<string> | Yes | Callback used to return the result.| **Error codes** @@ -2248,43 +2296,43 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco | ID| Error Message| | -------- | ---------------------------------------- | -| 9001003 | If the resName invalid. | -| 9001004 | If the resource not found by resName. | +| 9001001 | If the resId invalid. | +| 9001002 | If the resource not found by resId. | **Example** ```ts try { - this.context.resourceManager.getMediaByName("test", 120, (error, value) => { - if (error != null) { - console.error(`callback getMediaByName failed, error code: ${error.code}, message: ${error.message}.`); - } else { - let media = value; - } + this.context.resourceManager.getMediaContentBase64($r('app.media.test').id, 120, (error, value) => { + if (error != null) { + console.error(`callback getMediaContentBase64 failed, error code: ${error.code}, message: ${error.message}.`); + } else { + let media = value; + } }); } catch (error) { - console.error(`callback getMediaByName failed, error code: ${error.code}, message: ${error.message}.`); + console.error(`callback getMediaContentBase64 failed, error code: ${error.code}, message: ${error.message}.`); } ``` -### getMediaByName9+ +### getMediaContentBase649+ -getMediaByName(resName: string): Promise<Uint8Array> +getMediaContentBase64(resId: number): Promise<string> -Obtains the content of the media file corresponding to the specified resource name. This API uses a promise to return the result. +Obtains the Base64 code of the image corresponding to the specified resource ID. This API uses a promise to return the result. **System capability**: SystemCapability.Global.ResourceManager **Parameters** -| Name | Type | Mandatory | Description | -| ------- | ------ | ---- | ---- | -| resName | string | Yes | Resource name.| +| Name | Type | Mandatory | Description | +| ----- | ------ | ---- | ----- | +| resId | number | Yes | Resource ID.| **Return value** -| Type | Description | -| ------------------------- | ------------- | -| Promise<Uint8Array> | Promise used to return the result.| +| Type | Description | +| --------------------- | -------------------- | +| Promise<string> | Promise used to return the result.| **Error codes** @@ -2292,42 +2340,42 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco | ID| Error Message| | -------- | ---------------------------------------- | -| 9001003 | If the resName invalid. | -| 9001004 | If the resource not found by resName. | +| 9001001 | If the resId invalid. | +| 9001002 | If the resource not found by resId. | **Example** ```ts try { - this.context.resourceManager.getMediaByName("test").then(value => { - let media = value; + this.context.resourceManager.getMediaContentBase64($r('app.media.test').id).then(value => { + let media = value; }).catch(error => { - console.log("getMediaByName promise error is " + error); + console.log("getMediaContentBase64 promise error is " + error); }); } catch (error) { - console.error(`promise getMediaByName failed, error code: ${error.code}, message: ${error.message}.`) + console.error(`promise getMediaContentBase64 failed, error code: ${error.code}, message: ${error.message}.`); } ``` -### getMediaByName10+ +### getMediaContentBase6410+ -getMediaByName(resName: string, density: number): Promise<Uint8Array> +getMediaContentBase64(resId: number, density: number): Promise<string> -Obtains the content of the media file with the screen density corresponding to the specified resource name. This API uses a promise to return the result. +Obtains the Base64 code of an image with the screen density corresponding to the specified resource ID. This API uses a promise to return the result. **System capability**: SystemCapability.Global.ResourceManager **Parameters** -| Name | Type | Mandatory | Description | -| ------- | ------ | ---- | ---- | -| resName | string | Yes | Resource name.| +| Name | Type | Mandatory | Description | +| ----- | ------ | ---- | ----- | +| resId | number | Yes | Resource ID.| | [density](#screendensity) | number | Yes | Screen density. The value **0** indicates the default screen density. | **Return value** -| Type | Description | -| ------------------------- | ------------- | -| Promise<Uint8Array> | Promise used to return the result.| +| Type | Description | +| --------------------- | -------------------- | +| Promise<string> | Promise used to return the result.| **Error codes** @@ -2335,35 +2383,37 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco | ID| Error Message| | -------- | ---------------------------------------- | -| 9001003 | If the resName invalid. | -| 9001004 | If the resource not found by resName. | +| 9001001 | If the resId invalid. | +| 9001002 | If the resource not found by resId. | **Example** ```ts try { - this.context.resourceManager.getMediaByName("test", 120).then(value => { - let media = value; + this.context.resourceManager.getMediaContentBase64($r('app.media.test').id, 120).then(value => { + let media = value; }).catch(error => { - console.error(`promise getMediaByName failed, error code: ${error.code}, message: ${error.message}.`); + console.error(`promise getMediaContentBase64 failed, error code: ${error.code}, message: ${error.message}.`); }); } catch (error) { - console.error(`promise getMediaByName failed, error code: ${error.code}, message: ${error.message}.`); + console.error(`promise getMediaContentBase64 failed, error code: ${error.code}, message: ${error.message}.`); } ``` -### getMediaBase64ByName9+ +### getMediaContentBase649+ -getMediaBase64ByName(resName: string, callback: AsyncCallback<string>): void +getMediaContentBase64(resource: Resource, callback: AsyncCallback<string>): void -Obtains the Base64 code of the image corresponding to the specified resource name. This API uses an asynchronous callback to return the result. +Obtains the Base64 code of the image corresponding to the specified resource object. This API uses an asynchronous callback to return the result. **System capability**: SystemCapability.Global.ResourceManager +**Model restriction**: This API can be used only in the stage model. + **Parameters** | Name | Type | Mandatory | Description | | -------- | --------------------------- | ---- | ------------------------ | -| resName | string | Yes | Resource name. | +| resource | [Resource](#resource9) | Yes | Resource object. | | callback | AsyncCallback<string> | Yes | Callback used to return the result.| **Error codes** @@ -2372,37 +2422,44 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco | ID| Error Message| | -------- | ---------------------------------------- | -| 9001003 | If the resName invalid. | -| 9001004 | If the resource not found by resName. | +| 9001001 | If the resId invalid. | +| 9001002 | If the resource not found by resId. | **Example** ```ts + let resource = { + bundleName: "com.example.myapplication", + moduleName: "entry", + id: $r('app.media.test').id + }; try { - this.context.resourceManager.getMediaBase64ByName("test", (error, value) => { - if (error != null) { - console.log("error is " + error); - } else { - let media = value; - } + this.context.resourceManager.getMediaContentBase64(resource, (error, value) => { + if (error != null) { + console.log("error is " + error); + } else { + let media = value; + } }); } catch (error) { - console.error(`callback getMediaBase64ByName failed, error code: ${error.code}, message: ${error.message}.`); + console.error(`callback getMediaContentBase64 failed, error code: ${error.code}, message: ${error.message}.`); } ``` -### getMediaBase64ByName10+ +### getMediaContentBase6410+ -getMediaBase64ByName(resName: string, density: number, callback: AsyncCallback<string>): void +getMediaContentBase64(resource: Resource, density: number, callback: AsyncCallback<string>): void -Obtains the Base64 code of an image with the screen density corresponding to the specified resource name. This API uses an asynchronous callback to return the result. +Obtains the Base64 code of an image with the screen density corresponding to the specified resource object. This API uses an asynchronous callback to return the result. **System capability**: SystemCapability.Global.ResourceManager +**Model restriction**: This API can be used only in the stage model. + **Parameters** | Name | Type | Mandatory | Description | | -------- | --------------------------- | ---- | ------------------------ | -| resName | string | Yes | Resource name. | +| resource | [Resource](#resource9) | Yes | Resource object. | | [density](#screendensity) | number | Yes | Screen density. The value **0** indicates the default screen density. | | callback | AsyncCallback<string> | Yes | Callback used to return the result.| @@ -2412,42 +2469,49 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco | ID| Error Message| | -------- | ---------------------------------------- | -| 9001003 | If the resName invalid. | -| 9001004 | If the resource not found by resName. | +| 9001001 | If the resId invalid. | +| 9001002 | If the resource not found by resId. | **Example** ```ts + let resource = { + bundleName: "com.example.myapplication", + moduleName: "entry", + id: $r('app.media.test').id + }; try { - this.context.resourceManager.getMediaBase64ByName("test", 120, (error, value) => { - if (error != null) { - console.error(`callback getMediaBase64ByName failed, error code: ${error.code}, message: ${error.message}.`); - } else { - let media = value; - } + this.context.resourceManager.getMediaContentBase64(resource, 120, (error, value) => { + if (error != null) { + console.error(`callback getMediaContentBase64 failed, error code: ${error.code}, message: ${error.message}.`); + } else { + let media = value; + } }); } catch (error) { - console.error(`callback getMediaBase64ByName failed, error code: ${error.code}, message: ${error.message}.`); + console.error(`callback getMediaContentBase64 failed, error code: ${error.code}, message: ${error.message}.`); } ``` -### getMediaBase64ByName9+ +### getMediaContentBase649+ -getMediaBase64ByName(resName: string): Promise<string> +getMediaContentBase64(resource: Resource): Promise<string> -Obtains the Base64 code of the image corresponding to the specified resource name. This API uses a promise to return the result. +Obtains the Base64 code of the image corresponding to the specified resource object. This API uses a promise to return the result. **System capability**: SystemCapability.Global.ResourceManager +**Model restriction**: This API can be used only in the stage model. + **Parameters** -| Name | Type | Mandatory | Description | -| ------- | ------ | ---- | ---- | -| resName | string | Yes | Resource name.| +| Name | Type | Mandatory | Description | +| -------- | ---------------------- | ---- | ---- | +| resource | [Resource](#resource9) | Yes | Resource object.| **Return value** -| Type | Description | -| --------------------- | ------------------- | +| Type | Description | +| --------------------- | ------------------------- | | Promise<string> | Promise used to return the result.| **Error codes** @@ -2456,41 +2520,48 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco | ID| Error Message| | -------- | ---------------------------------------- | -| 9001003 | If the resName invalid. | -| 9001004 | If the resource not found by resName. | +| 9001001 | If the resId invalid. | +| 9001002 | If the resource not found by resId. | **Example** ```ts + let resource = { + bundleName: "com.example.myapplication", + moduleName: "entry", + id: $r('app.media.test').id + }; try { - this.context.resourceManager.getMediaBase64ByName("test").then(value => { - let media = value; + this.context.resourceManager.getMediaContentBase64(resource).then(value => { + let media = value; }).catch(error => { - console.log("getMediaBase64ByName promise error is " + error); + console.log("getMediaContentBase64 promise error is " + error); }); } catch (error) { - console.error(`promise getMediaBase64ByName failed, error code: ${error.code}, message: ${error.message}.`); + console.error(`promise getMediaContentBase64 failed, error code: ${error.code}, message: ${error.message}.`); } ``` -### getMediaBase64ByName10+ +### getMediaContentBase6410+ -getMediaBase64ByName(resName: string, density: number): Promise<string> +getMediaContentBase64(resource: Resource, density: number): Promise<string> -Obtains the Base64 code of an image with the screen density corresponding to the specified resource name. This API uses a promise to return the result. +Obtains the Base64 code of an image with the screen density corresponding to the specified resource object. This API uses a promise to return the result. **System capability**: SystemCapability.Global.ResourceManager +**Model restriction**: This API can be used only in the stage model. + **Parameters** -| Name | Type | Mandatory | Description | -| ------- | ------ | ---- | ---- | -| resName | string | Yes | Resource name.| +| Name | Type | Mandatory | Description | +| -------- | ---------------------- | ---- | ---- | +| resource | [Resource](#resource9) | Yes | Resource object.| | [density](#screendensity) | number | Yes | Screen density. The value **0** indicates the default screen density. | **Return value** -| Type | Description | -| --------------------- | ------------------- | +| Type | Description | +| --------------------- | ------------------------- | | Promise<string> | Promise used to return the result.| **Error codes** @@ -2499,36 +2570,40 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco | ID| Error Message| | -------- | ---------------------------------------- | -| 9001003 | If the resName invalid. | -| 9001004 | If the resource not found by resName. | +| 9001001 | If the resId invalid. | +| 9001002 | If the resource not found by resId. | **Example** ```ts + let resource = { + bundleName: "com.example.myapplication", + moduleName: "entry", + id: $r('app.media.test').id + }; try { - this.context.resourceManager.getMediaBase64ByName("test", 120).then(value => { - let media = value; + this.context.resourceManager.getMediaContentBase64(resource, 120).then(value => { + let media = value; }).catch(error => { - console.error(`promise getMediaBase64ByName failed, error code: ${error.code}, message: ${error.message}.`); + console.error(`promise getMediaContentBase64 failed, error code: ${error.code}, message: ${error.message}.`); }); } catch (error) { - console.error(`promise getMediaBase64ByName failed, error code: ${error.code}, message: ${error.message}.`); + console.error(`promise getMediaContentBase64 failed, error code: ${error.code}, message: ${error.message}.`); } ``` -### getPluralStringByName9+ +### getMediaBase64ByName9+ -getPluralStringByName(resName: string, num: number, callback: AsyncCallback<string>): void +getMediaBase64ByName(resName: string, callback: AsyncCallback<string>): void -Obtains the plural string corresponding to the specified resource name based on the specified number. This API uses an asynchronous callback to return the result. +Obtains the Base64 code of the image corresponding to the specified resource name. This API uses an asynchronous callback to return the result. **System capability**: SystemCapability.Global.ResourceManager **Parameters** -| Name | Type | Mandatory | Description | -| -------- | --------------------------- | ---- | ----------------------------- | -| resName | string | Yes | Resource name. | -| num | number | Yes | Number. | +| Name | Type | Mandatory | Description | +| -------- | --------------------------- | ---- | ------------------------ | +| resName | string | Yes | Resource name. | | callback | AsyncCallback<string> | Yes | Callback used to return the result.| **Error codes** @@ -2539,44 +2614,37 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco | -------- | ---------------------------------------- | | 9001003 | If the resName invalid. | | 9001004 | If the resource not found by resName. | -| 9001006 | If the resource re-ref too much. | **Example** ```ts try { - this.context.resourceManager.getPluralStringByName("test", 1, (error, value) => { - if (error != null) { - console.log("error is " + error); - } else { - let str = value; - } + this.context.resourceManager.getMediaBase64ByName("test", (error, value) => { + if (error != null) { + console.log("error is " + error); + } else { + let media = value; + } }); } catch (error) { - console.error(`callback getPluralStringByName failed, error code: ${error.code}, message: ${error.message}.`); + console.error(`callback getMediaBase64ByName failed, error code: ${error.code}, message: ${error.message}.`); } - ``` -### getPluralStringByName9+ +### getMediaBase64ByName10+ -getPluralStringByName(resName: string, num: number): Promise<string> +getMediaBase64ByName(resName: string, density: number, callback: AsyncCallback<string>): void -Obtains the plural string corresponding to the specified resource name based on the specified number. This API uses a promise to return the result. +Obtains the Base64 code of an image with the screen density corresponding to the specified resource name. This API uses an asynchronous callback to return the result. **System capability**: SystemCapability.Global.ResourceManager **Parameters** -| Name | Type | Mandatory | Description | -| ------- | ------ | ---- | ---- | -| resName | string | Yes | Resource name.| -| num | number | Yes | Number. | - -**Return value** - -| Type | Description | -| --------------------- | ---------------------- | -| Promise<string> | Promise used to return the result.| +| Name | Type | Mandatory | Description | +| -------- | --------------------------- | ---- | ------------------------ | +| resName | string | Yes | Resource name. | +| [density](#screendensity) | number | Yes | Screen density. The value **0** indicates the default screen density. | +| callback | AsyncCallback<string> | Yes | Callback used to return the result.| **Error codes** @@ -2586,40 +2654,41 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco | -------- | ---------------------------------------- | | 9001003 | If the resName invalid. | | 9001004 | If the resource not found by resName. | -| 9001006 | If the resource re-ref too much. | **Example** ```ts try { - this.context.resourceManager.getPluralStringByName("test", 1).then(value => { - let str = value; - }).catch(error => { - console.log("getPluralStringByName promise error is " + error); + this.context.resourceManager.getMediaBase64ByName("test", 120, (error, value) => { + if (error != null) { + console.error(`callback getMediaBase64ByName failed, error code: ${error.code}, message: ${error.message}.`); + } else { + let media = value; + } }); } catch (error) { - console.error(`promise getPluralStringByName failed, error code: ${error.code}, message: ${error.message}.`); + console.error(`callback getMediaBase64ByName failed, error code: ${error.code}, message: ${error.message}.`); } ``` -### getStringSync9+ +### getMediaBase64ByName9+ -getStringSync(resId: number): string +getMediaBase64ByName(resName: string): Promise<string> -Obtains the string corresponding to the specified resource ID. This API returns the result synchronously. +Obtains the Base64 code of the image corresponding to the specified resource name. This API uses a promise to return the result. **System capability**: SystemCapability.Global.ResourceManager **Parameters** -| Name | Type | Mandatory | Description | -| ----- | ------ | ---- | ----- | -| resId | number | Yes | Resource ID.| +| Name | Type | Mandatory | Description | +| ------- | ------ | ---- | ---- | +| resName | string | Yes | Resource name.| **Return value** -| Type | Description | -| ------ | ----------- | -| string | String corresponding to the specified resource ID.| +| Type | Description | +| --------------------- | ------------------- | +| Promise<string> | Promise used to return the result.| **Error codes** @@ -2627,81 +2696,85 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco | ID| Error Message| | -------- | ---------------------------------------- | -| 9001001 | If the resId invalid. | -| 9001002 | If the resource not found by resId. | -| 9001006 | If the resource re-ref too much. | +| 9001003 | If the resName invalid. | +| 9001004 | If the resource not found by resName. | **Example** ```ts try { - this.context.resourceManager.getStringSync($r('app.string.test').id); + this.context.resourceManager.getMediaBase64ByName("test").then(value => { + let media = value; + }).catch(error => { + console.log("getMediaBase64ByName promise error is " + error); + }); } catch (error) { - console.error(`getStringSync failed, error code: ${error.code}, message: ${error.message}.`); + console.error(`promise getMediaBase64ByName failed, error code: ${error.code}, message: ${error.message}.`); } ``` -### getStringSync10+ +### getMediaBase64ByName10+ -getStringSync(resId: number, ...args: Array): string +getMediaBase64ByName(resName: string, density: number): Promise<string> -Obtains the string corresponding to the specified resource ID and formats the string based on **args**. This API returns the result synchronously. +Obtains the Base64 code of an image with the screen density corresponding to the specified resource name. This API uses a promise to return the result. **System capability**: SystemCapability.Global.ResourceManager **Parameters** -| Name | Type | Mandatory | Description | -| ----- | ------ | ---- | ----- | -| resId | number | Yes | Resource ID.| -| args | Array | No | Arguments for formatting strings.
Supported arguments:
-%d, %f, %s, and %%
Note: **%%** is used to translate **%**.
Example: **%%d** is translated into the **%d** string.| +| Name | Type | Mandatory | Description | +| ------- | ------ | ---- | ---- | +| resName | string | Yes | Resource name.| +| [density](#screendensity) | number | Yes | Screen density. The value **0** indicates the default screen density. | **Return value** -| Type | Description | -| ------ | ---------------------------- | -| string | Formatted string.| +| Type | Description | +| --------------------- | ------------------- | +| Promise<string> | Promise used to return the result.| **Error codes** For details about the error codes, see [Resource Manager Error Codes](../errorcodes/errorcode-resource-manager.md). | ID| Error Message| -| -------- | ----------------------------------------------- | -| 9001001 | If the resId invalid. | -| 9001002 | If the resource not found by resId. | -| 9001006 | If the resource re-ref too much. | -| 9001007 | If the resource obtained by resId formatting error. | +| -------- | ---------------------------------------- | +| 9001003 | If the resName invalid. | +| 9001004 | If the resource not found by resName. | **Example** ```ts try { - this.context.resourceManager.getStringSync($r('app.string.test').id, "format string", 10, 98.78); + this.context.resourceManager.getMediaBase64ByName("test", 120).then(value => { + let media = value; + }).catch(error => { + console.error(`promise getMediaBase64ByName failed, error code: ${error.code}, message: ${error.message}.`); + }); } catch (error) { - console.error(`getStringSync failed, error code: ${error.code}, message: ${error.message}.`); + console.error(`promise getMediaBase64ByName failed, error code: ${error.code}, message: ${error.message}.`); } ``` -### getStringSync9+ +### getDrawableDescriptor10+ -getStringSync(resource: Resource): string +getDrawableDescriptor(resId: number, density?: number): DrawableDescriptor; -Obtains the string corresponding to the specified resource object. This API returns the result synchronously. +Obtains the **DrawableDescriptor** object corresponding to the specified resource ID. This API returns the result synchronously. **System capability**: SystemCapability.Global.ResourceManager -**Model restriction**: This API can be used only in the stage model. - **Parameters** -| Name | Type | Mandatory | Description | -| -------- | ---------------------- | ---- | ---- | -| resource | [Resource](#resource9) | Yes | Resource object.| +| Name | Type | Mandatory | Description | +| ----- | ------ | ---- | ----- | +| resId | number | Yes | Resource ID.| +| [density](#screendensity) | number | No | Screen density. The default value or value **0** indicates the default screen density.| **Return value** -| Type | Description | -| ------ | ---------------- | -| string | String corresponding to the specified resource object.| +| Type | Description | +| ------ | ---------- | +| DrawableDescriptor | **DrawableDescriptor** object corresponding to the specified resource ID.| **Error codes** @@ -2711,27 +2784,26 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco | -------- | ---------------------------------------- | | 9001001 | If the resId invalid. | | 9001002 | If the resource not found by resId. | -| 9001006 | If the resource re-ref too much. | **Example** ```ts - let resource = { - bundleName: "com.example.myapplication", - moduleName: "entry", - id: $r('app.string.test').id - }; try { - this.context.resourceManager.getStringSync(resource); + this.context.resourceManager.getDrawableDescriptor($r('app.media.icon').id); } catch (error) { - console.error(`getStringSync failed, error code: ${error.code}, message: ${error.message}.`); + console.error(`getDrawableDescriptor failed, error code: ${error.code}, message: ${error.message}.`); + } + try { + this.context.resourceManager.getDrawableDescriptor($r('app.media.icon').id, 120); + } catch (error) { + console.error(`getDrawableDescriptor failed, error code: ${error.code}, message: ${error.message}.`); } ``` -### getStringSync10+ +### getDrawableDescriptor10+ -getStringSync(resource: Resource, ...args: Array): string +getDrawableDescriptor(resource: Resource, density?: number): DrawableDescriptor; -Obtains the string corresponding to the specified resource object and formats the string based on **args**. This API returns the result synchronously. +Obtains the **DrawableDescriptor** object corresponding to the specified resource object. This API returns the result synchronously. **System capability**: SystemCapability.Global.ResourceManager @@ -2742,13 +2814,13 @@ Obtains the string corresponding to the specified resource object and formats th | Name | Type | Mandatory | Description | | -------- | ---------------------- | ---- | ---- | | resource | [Resource](#resource9) | Yes | Resource object.| -| args | Array | No | Arguments for formatting strings.
Supported arguments:
-%d, %f, %s, and %%
Note: **%%** is used to translate **%**.
Example: **%%d** is translated into the **%d** string.| +| [density](#screendensity) | number | No | Screen density. The default value or value **0** indicates the default screen density.| **Return value** -| Type | Description | -| ------ | ---------------------------- | -| string | Formatted string.| +| Type | Description | +| ------- | ----------------- | +| DrawableDescriptor | **DrawableDescriptor** object corresponding to the specified resource ID.| **Error codes** @@ -2758,28 +2830,31 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco | -------- | ---------------------------------------- | | 9001001 | If the resId invalid. | | 9001002 | If the resource not found by resId. | -| 9001006 | If the resource re-ref too much. | -| 9001007 | If the resource obtained by resId formatting error. | **Example** ```ts let resource = { - bundleName: "com.example.myapplication", - moduleName: "entry", - id: $r('app.string.test').id + bundleName: "com.example.myapplication", + moduleName: "entry", + id: $r('app.media.icon').id }; try { - this.context.resourceManager.getStringSync(resource, "format string", 10, 98.78); + this.context.resourceManager.getDrawableDescriptor(resource); } catch (error) { - console.error(`getStringSync failed, error code: ${error.code}, message: ${error.message}.`); + console.error(`getDrawableDescriptor failed, error code: ${error.code}, message: ${error.message}.`); } - ``` + try { + this.context.resourceManager.getDrawableDescriptor(resource, 120); + } catch (error) { + console.error(`getDrawableDescriptor failed, error code: ${error.code}, message: ${error.message}.`); + } + ``` -### getStringByNameSync9+ +### getDrawableDescriptorByName10+ -getStringByNameSync(resName: string): string +getDrawableDescriptorByName(resName: string, density?: number): DrawableDescriptor; -Obtains the string corresponding to the specified resource name. This API returns the result synchronously. +Obtains the **DrawableDescriptor** object corresponding to the specified resource name. This API returns the result synchronously. **System capability**: SystemCapability.Global.ResourceManager @@ -2788,12 +2863,13 @@ Obtains the string corresponding to the specified resource name. This API return | Name | Type | Mandatory | Description | | ------- | ------ | ---- | ---- | | resName | string | Yes | Resource name.| +| [density](#screendensity) | number | No | Screen density. The default value or value **0** indicates the default screen density.| **Return value** -| Type | Description | -| ------ | ---------- | -| string | String corresponding to the specified resource name.| +| Type | Description | +| ------ | --------- | +| DrawableDescriptor | **DrawableDescriptor** object corresponding to the specified resource ID.| **Error codes** @@ -2803,57 +2879,20 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco | -------- | ---------------------------------------- | | 9001003 | If the resName invalid. | | 9001004 | If the resource not found by resName. | -| 9001006 | If the resource re-ref too much. | **Example** ```ts try { - this.context.resourceManager.getStringByNameSync("test"); + this.context.resourceManager.getDrawableDescriptorByName('icon'); } catch (error) { - console.error(`getStringByNameSync failed, error code: ${error.code}, message: ${error.message}.`); + console.error(`getDrawableDescriptorByName failed, error code: ${error.code}, message: ${error.message}.`); } - ``` - -### getStringByNameSync10+ - -getStringByNameSync(resName: string, ...args: Array): string - -Obtains the string corresponding to the specified resource name and formats the string based on **args**. This API returns the result synchronously. - -**System capability**: SystemCapability.Global.ResourceManager - -**Parameters** - -| Name | Type | Mandatory | Description | -| ------- | ------ | ---- | ---- | -| resName | string | Yes | Resource name.| -| args | Array | No | Arguments for formatting strings.
Supported arguments:
-%d, %f, %s, and %%
Note: **%%** is used to translate **%**.
Example: **%%d** is translated into the **%d** string.| - -**Return value** - -| Type | Description | -| ------ | ---------------------------- | -| string | Formatted string.| - -**Error codes** - -For details about the error codes, see [Resource Manager Error Codes](../errorcodes/errorcode-resource-manager.md). - -| ID| Error Message| -| -------- | ---------------------------------------- | -| 9001003 | If the resName invalid. | -| 9001004 | If the resource not found by resName. | -| 9001006 | If the resource re-ref too much. | -| 9001008 | If the resource obtained by resName formatting error. | - -**Example** - ```ts try { - this.context.resourceManager.getStringByNameSync("test", "format string", 10, 98.78); + this.context.resourceManager.getDrawableDescriptorByName('icon', 120); } catch (error) { - console.error(`getStringByNameSync failed, error code: ${error.code}, message: ${error.message}.`); + console.error(`getDrawableDescriptorByName failed, error code: ${error.code}, message: ${error.message}.`); } - ``` + ``` ### getBoolean9+ @@ -2928,9 +2967,9 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco **Example** ```ts let resource = { - bundleName: "com.example.myapplication", - moduleName: "entry", - id: $r('app.boolean.boolean_test').id + bundleName: "com.example.myapplication", + moduleName: "entry", + id: $r('app.boolean.boolean_test').id }; try { this.context.resourceManager.getBoolean(resource); @@ -3058,9 +3097,9 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco **Example** ```ts let resource = { - bundleName: "com.example.myapplication", - moduleName: "entry", - id: $r('app.integer.integer_test').id + bundleName: "com.example.myapplication", + moduleName: "entry", + id: $r('app.integer.integer_test').id }; try { this.context.resourceManager.getNumber(resource);// integer refers to the original value; float refers to the actual pixel value. @@ -3114,11 +3153,11 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco } ``` -### getDrawableDescriptor10+ +### getColorSync10+ -getDrawableDescriptor(resId: number, density?: number): DrawableDescriptor; +getColorSync(resId: number) : number; -Obtains the **DrawableDescriptor** object corresponding to the specified resource ID. This API returns the result synchronously. +Obtains the color value corresponding to the specified resource ID. This API returns the result synchronously. **System capability**: SystemCapability.Global.ResourceManager @@ -3127,13 +3166,12 @@ Obtains the **DrawableDescriptor** object corresponding to the specified resourc | Name | Type | Mandatory | Description | | ----- | ------ | ---- | ----- | | resId | number | Yes | Resource ID.| -| [density](#screendensity) | number | No | Screen density. The default value is **0**.| **Return value** -| Type | Description | -| ------ | ---------- | -| DrawableDescriptor | **DrawableDescriptor** object corresponding to the specified resource ID.| +| Type | Description | +| ------ | ----------- | +| number | Color value corresponding to the resource ID (decimal).| **Error codes** @@ -3143,26 +3181,22 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco | -------- | ---------------------------------------- | | 9001001 | If the resId invalid. | | 9001002 | If the resource not found by resId. | +| 9001006 | If the resource re-ref too much. | **Example** ```ts try { - this.context.resourceManager.getDrawableDescriptor($r('app.media.icon').id); - } catch (error) { - console.error(`getDrawableDescriptor failed, error code: ${error.code}, message: ${error.message}.`); - } - try { - this.context.resourceManager.getDrawableDescriptor($r('app.media.icon').id, 120); + this.context.resourceManager.getColorSync($r('app.color.test').id); } catch (error) { - console.error(`getDrawableDescriptor failed, error code: ${error.code}, message: ${error.message}.`); + console.error(`getColorSync failed, error code: ${error.code}, message: ${error.message}.`); } ``` -### getDrawableDescriptor10+ +### getColorSync10+ -getDrawableDescriptor(resource: Resource, density?: number): DrawableDescriptor; +getColorSync(resource: Resource): number -Obtains the **DrawableDescriptor** object corresponding to the specified resource object. This API returns the result synchronously. +Obtains the color value corresponding to the specified resource object. This API returns the result synchronously. **System capability**: SystemCapability.Global.ResourceManager @@ -3173,13 +3207,12 @@ Obtains the **DrawableDescriptor** object corresponding to the specified resourc | Name | Type | Mandatory | Description | | -------- | ---------------------- | ---- | ---- | | resource | [Resource](#resource9) | Yes | Resource object.| -| [density](#screendensity) | number | No | Screen density. The default value is **0**.| **Return value** -| Type | Description | -| ------- | ----------------- | -| DrawableDescriptor | **DrawableDescriptor** object corresponding to the specified resource ID.| +| Type | Description | +| ------ | ---------------- | +| number | Color value corresponding to the resource object (decimal).| **Error codes** @@ -3189,31 +3222,27 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco | -------- | ---------------------------------------- | | 9001001 | If the resId invalid. | | 9001002 | If the resource not found by resId. | +| 9001006 | If the resource re-ref too much. | **Example** ```ts let resource = { - bundleName: "com.example.myapplication", - moduleName: "entry", - id: $r('app.media.icon').id + bundleName: "com.example.myapplication", + moduleName: "entry", + id: $r('app.color.test').id }; try { - this.context.resourceManager.getDrawableDescriptor(resource); - } catch (error) { - console.error(`getDrawableDescriptor failed, error code: ${error.code}, message: ${error.message}.`); - } - try { - this.context.resourceManager.getDrawableDescriptor(resource, 120); + this.context.resourceManager.getColorSync(resource); } catch (error) { - console.error(`getDrawableDescriptor failed, error code: ${error.code}, message: ${error.message}.`); + console.error(`getColorSync failed, error code: ${error.code}, message: ${error.message}.`); } ``` -### getDrawableDescriptorByName10+ +### getColorByNameSync10+ -getDrawableDescriptorByName(resName: string, density?: number): DrawableDescriptor; +getColorByNameSync(resName: string) : number; -Obtains the **DrawableDescriptor** object corresponding to the specified resource name. This API returns the result synchronously. +Obtains the color value corresponding to the specified resource name. This API returns the result synchronously. **System capability**: SystemCapability.Global.ResourceManager @@ -3222,13 +3251,12 @@ Obtains the **DrawableDescriptor** object corresponding to the specified resourc | Name | Type | Mandatory | Description | | ------- | ------ | ---- | ---- | | resName | string | Yes | Resource name.| -| [density](#screendensity) | number | No | Screen density. The default value is **0**.| **Return value** -| Type | Description | -| ------ | --------- | -| DrawableDescriptor | **DrawableDescriptor** object corresponding to the specified resource ID.| +| Type | Description | +| ------ | ---------- | +| number | Color value corresponding to the resource name (decimal).| **Error codes** @@ -3238,18 +3266,14 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco | -------- | ---------------------------------------- | | 9001003 | If the resName invalid. | | 9001004 | If the resource not found by resName. | +| 9001006 | If the resource re-ref too much. | **Example** ```ts try { - this.context.resourceManager.getDrawableDescriptorByName('icon'); - } catch (error) { - console.error(`getDrawableDescriptorByName failed, error code: ${error.code}, message: ${error.message}.`); - } - try { - this.context.resourceManager.getDrawableDescriptorByName('icon', 120); + this.context.resourceManager.getColorByNameSync("test"); } catch (error) { - console.error(`getDrawableDescriptorByName failed, error code: ${error.code}, message: ${error.message}.`); + console.error(`getColorByNameSync failed, error code: ${error.code}, message: ${error.message}.`); } ``` @@ -3280,17 +3304,17 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco **Example (stage)** ```ts - try { - this.context.resourceManager.getColor($r('app.color.test').id, (error, value) => { - if (error != null) { - console.log("error is " + error); - } else { - let str = value; - } - }); - } catch (error) { - console.error(`callback getColor failed, error code: ${error.code}, message: ${error.message}.`); - } + try { + this.context.resourceManager.getColor($r('app.color.test').id, (error, value) => { + if (error != null) { + console.log("error is " + error); + } else { + let str = value; + } + }); + } catch (error) { + console.error(`callback getColor failed, error code: ${error.code}, message: ${error.message}.`); + } ``` ### getColor10+ @@ -3311,7 +3335,7 @@ Obtains the color value corresponding to the specified resource ID. This API use | Type | Description | | --------------------- | ----------- | -| Promise<number> | Color value corresponding to the resource ID (decimal).| +| Promise<number> | Promise used to return the result.| **Error codes** @@ -3327,9 +3351,9 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco ```ts try { this.context.resourceManager.getColor($r('app.color.test').id).then(value => { - let str = value; + let str = value; }).catch(error => { - console.log("getColor promise error is " + error); + console.log("getColor promise error is " + error); }); } catch (error) { console.error(`promise getColor failed, error code: ${error.code}, message: ${error.message}.`); @@ -3366,17 +3390,17 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco **Example** ```ts let resource = { - bundleName: "com.example.myapplication", - moduleName: "entry", - id: $r('app.color.test').id + bundleName: "com.example.myapplication", + moduleName: "entry", + id: $r('app.color.test').id }; try { this.context.resourceManager.getColor(resource, (error, value) => { - if (error != null) { - console.log("error is " + error); - } else { - let str = value; - } + if (error != null) { + console.log("error is " + error); + } else { + let str = value; + } }); } catch (error) { console.error(`callback getColor failed, error code: ${error.code}, message: ${error.message}.`); @@ -3403,7 +3427,7 @@ Obtains the color value corresponding to the specified resource object. This API | Type | Description | | --------------------- | ---------------- | -| Promise<number> | Color value corresponding to the resource object (decimal).| +| Promise<number> | Promise used to return the result.| **Error codes** @@ -3418,9 +3442,9 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco **Example** ```ts let resource = { - bundleName: "com.example.myapplication", - moduleName: "entry", - id: $r('app.color.test').id + bundleName: "com.example.myapplication", + moduleName: "entry", + id: $r('app.color.test').id }; try { this.context.resourceManager.getColor(resource).then(value => { @@ -3462,11 +3486,11 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco ```ts try { this.context.resourceManager.getColorByName("test", (error, value) => { - if (error != null) { - console.log("error is " + error); - } else { - let string = value; - } + if (error != null) { + console.log("error is " + error); + } else { + let string = value; + } }); } catch (error) { console.error(`callback getColorByName failed, error code: ${error.code}, message: ${error.message}.`); @@ -3491,7 +3515,7 @@ Obtains the color value corresponding to the specified resource name. This API u | Type | Description | | --------------------- | ---------- | -| Promise<number> | Color value corresponding to the resource name (decimal).| +| Promise<number> | Promise used to return the result.| **Error codes** @@ -3507,34 +3531,34 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco ```ts try { this.context.resourceManager.getColorByName("test").then(value => { - let string = value; + let string = value; }).catch(error => { - console.log("getColorByName promise error is " + error); + console.log("getColorByName promise error is " + error); }); } catch (error) { console.error(`promise getColorByName failed, error code: ${error.code}, message: ${error.message}.`); } ``` -### getColorSync10+ +### getRawFileContentSync10+ -getColorSync(resId: number) : number; +getRawFileContentSync(path: string): Uint8Array -Obtains the color value corresponding to the specified resource ID. This API returns the result synchronously. +Obtains the content of the raw file in the **resources/rawfile** directory. This API returns the result synchronously. **System capability**: SystemCapability.Global.ResourceManager **Parameters** -| Name | Type | Mandatory | Description | -| ----- | ------ | ---- | ----- | -| resId | number | Yes | Resource ID.| +| Name | Type | Mandatory | Description | +| -------- | ------------------------------- | ---- | ----------------------- | +| path | string | Yes | Path of the raw file. | **Return value** -| Type | Description | -| ------ | ----------- | -| number | Color value corresponding to the resource ID (decimal).| +| Type | Description | +| --------------------- | ---------- | +| Uint8Array | Content of the raw file.| **Error codes** @@ -3542,40 +3566,74 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco | ID| Error Message| | -------- | ---------------------------------------- | -| 9001001 | If the resId invalid. | -| 9001002 | If the resource not found by resId. | -| 9001006 | If the resource re-ref too much. | +| 9001005 | If the resource not found by path. | **Example** ```ts try { - this.context.resourceManager.getColorSync($r('app.color.test').id); + this.context.resourceManager.getRawFileContentSync("test.txt"); } catch (error) { - console.error(`getColorSync failed, error code: ${error.code}, message: ${error.message}.`); + console.error(`getRawFileContentSync failed, error code: ${error.code}, message: ${error.message}.`); } ``` -### getColorSync10+ +### getRawFileContent9+ -getColorSync(resource: Resource): number +getRawFileContent(path: string, callback: AsyncCallback<Uint8Array>): void -Obtains the color value corresponding to the specified resource object. This API returns the result synchronously. +Obtains the content of the raw file in the **resources/rawfile** directory. This API uses an asynchronous callback to return the result. **System capability**: SystemCapability.Global.ResourceManager -**Model restriction**: This API can be used only in the stage model. +**Parameters** + +| Name | Type | Mandatory | Description | +| -------- | ------------------------------- | ---- | ----------------------- | +| path | string | Yes | Path of the raw file. | +| callback | AsyncCallback<Uint8Array> | Yes | Callback used to return the result.| + +**Error codes** + +For details about the error codes, see [Resource Manager Error Codes](../errorcodes/errorcode-resource-manager.md). + +| ID| Error Message| +| -------- | ---------------------------------------- | +| 9001005 | If the resource not found by path. | + +**Example** + ```ts + try { + this.context.resourceManager.getRawFileContent("test.xml", (error, value) => { + if (error != null) { + console.log("error is " + error); + } else { + let rawFile = value; + } + }); + } catch (error) { + console.error(`callback getRawFileContent failed, error code: ${error.code}, message: ${error.message}.`); + } + ``` + +### getRawFileContent9+ + +getRawFileContent(path: string): Promise<Uint8Array> + +Obtains the content of the raw file in the **resources/rawfile** directory. This API uses a promise to return the result. + +**System capability**: SystemCapability.Global.ResourceManager **Parameters** -| Name | Type | Mandatory | Description | -| -------- | ---------------------- | ---- | ---- | -| resource | [Resource](#resource9) | Yes | Resource object.| +| Name | Type | Mandatory | Description | +| ---- | ------ | ---- | ----------- | +| path | string | Yes | Path of the raw file.| **Return value** -| Type | Description | -| ------ | ---------------- | -| number | Color value corresponding to the resource object (decimal).| +| Type | Description | +| ------------------------- | ----------- | +| Promise<Uint8Array> | Promise used to return the result.| **Error codes** @@ -3583,43 +3641,40 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco | ID| Error Message| | -------- | ---------------------------------------- | -| 9001001 | If the resId invalid. | -| 9001002 | If the resource not found by resId. | -| 9001006 | If the resource re-ref too much. | +| 9001005 | If the resource not found by path. | **Example** ```ts - let resource = { - bundleName: "com.example.myapplication", - moduleName: "entry", - id: $r('app.color.test').id - }; try { - this.context.resourceManager.getColorSync(resource); + this.context.resourceManager.getRawFileContent("test.xml").then(value => { + let rawFile = value; + }).catch(error => { + console.log("getRawFileContent promise error is " + error); + }); } catch (error) { - console.error(`getColorSync failed, error code: ${error.code}, message: ${error.message}.`); + console.error(`promise getRawFileContent failed, error code: ${error.code}, message: ${error.message}.`); } ``` -### getColorByNameSync10+ +### getRawFileListSync10+ -getColorByNameSync(resName: string) : number; +getRawFileListSync(path: string): Array\ -Obtains the color value corresponding to the specified resource name. This API returns the result synchronously. +Obtains the list of files in the **resources/rawfile** directory. This API uses an asynchronous callback to return the result. **System capability**: SystemCapability.Global.ResourceManager **Parameters** -| Name | Type | Mandatory | Description | -| ------- | ------ | ---- | ---- | -| resName | string | Yes | Resource name.| +| Name | Type | Mandatory | Description | +| -------- | ------------------------------- | ---- | ----------------------- | +| path | string | Yes | Path of the **rawfile** folder. | **Return value** -| Type | Description | -| ------ | ---------- | -| number | Color value corresponding to the resource name (decimal).| +| Type | Description | +| ------------------------- | ----------- | +| Array\ | List of files in the **resources/rawfile** directory.| **Error codes** @@ -3627,16 +3682,454 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco | ID| Error Message| | -------- | ---------------------------------------- | -| 9001003 | If the resName invalid. | -| 9001004 | If the resource not found by resName. | -| 9001006 | If the resource re-ref too much. | +| 9001005 | If the resource not found by path. | **Example** ```ts - try { - this.context.resourceManager.getColorByNameSync("test"); + try { // Passing "" means to obtain the list of files in the root directory of the raw file. + this.context.resourceManager.getRawFileListSync("") } catch (error) { - console.error(`getColorByNameSync failed, error code: ${error.code}, message: ${error.message}.`); + console.error(`getRawFileListSync failed, error code: ${error.code}, message: ${error.message}.`); + } + ``` + +### getRawFileList10+ + +getRawFileList(path: string, callback: AsyncCallback<Array\>): void; + +Obtains the list of files in the **resources/rawfile** directory. This API uses an asynchronous callback to return the result. + +**System capability**: SystemCapability.Global.ResourceManager + +**Parameters** + +| Name | Type | Mandatory | Description | +| -------- | ------------------------------- | ---- | ----------------------- | +| path | string | Yes | Path of the **rawfile** folder. | +| callback | AsyncCallback<Array\> | Yes| Callback used to return the result.| + +**Error codes** + +For details about the error codes, see [Resource Manager Error Codes](../errorcodes/errorcode-resource-manager.md). + +| ID| Error Message| +| -------- | ---------------------------------------- | +| 9001005 | If the resource not found by path. | + +**Example** + ```ts + try { // Passing "" means to obtain the list of files in the root directory of the raw file. + this.context.resourceManager.getRawFileList("", (error, value) => { + if (error != null) { + console.error(`callback getRawFileList failed, error code: ${error.code}, message: ${error.message}.`); + } else { + let rawFile = value; + } + }); + } catch (error) { + console.error(`callback getRawFileList failed, error code: ${error.code}, message: ${error.message}.`); + } + ``` + +### getRawFileList10+ + +getRawFileList(path: string): Promise<Array\> + +Obtains the list of files in the **resources/rawfile** directory. This API uses a promise to return the result. + +**System capability**: SystemCapability.Global.ResourceManager + +**Parameters** + +| Name | Type | Mandatory | Description | +| ---- | ------ | ---- | ----------- | +| path | string | Yes | Path of the **rawfile** folder.| + +**Return value** + +| Type | Description | +| ------------------------- | ----------- | +| Promise<Array\> | Promise used to return the result.| + +**Error codes** + +For details about the error codes, see [Resource Manager Error Codes](../errorcodes/errorcode-resource-manager.md). + +| ID| Error Message| +| -------- | ---------------------------------------- | +| 9001005 | If the resource not found by path. | + +**Example** + ```ts + try { // Passing "" means to obtain the list of files in the root directory of the raw file. + this.context.resourceManager.getRawFileList("").then(value => { + let rawFile = value; + }).catch(error => { + console.error(`promise getRawFileList failed, error code: ${error.code}, message: ${error.message}.`); + }); + } catch (error) { + console.error(`promise getRawFileList failed, error code: ${error.code}, message: ${error.message}.`); + } + ``` + +### getRawFdSync10+ + +getRawFdSync(path: string): RawFileDescriptor + +Obtains the descriptor of the raw file in the **resources/rawfile** directory. + +**System capability**: SystemCapability.Global.ResourceManager + +**Parameters** + +| Name | Type | Mandatory | Description | +| -------- | ---------------------------------------- | ---- | -------------------------------- | +| path | string | Yes | Path of the raw file. | + +**Return value** + +| Type | Description | +| ------------------------- | ----------- | +| [RawFileDescriptor](#rawfiledescriptor8) | Descriptor of the raw file.| + +**Error codes** + +For details about the error codes, see [Resource Manager Error Codes](../errorcodes/errorcode-resource-manager.md). + +| ID| Error Message| +| -------- | ---------------------------------------- | +| 9001005 | If the resource not found by path. | + +**Example** + ```ts + try { + this.context.resourceManager.getRawFdSync("test.txt"); + } catch (error) { + console.error(`getRawFdSync failed, error code: ${error.code}, message: ${error.message}.`); + } + ``` + +### getRawFd9+ + +getRawFd(path: string, callback: AsyncCallback<RawFileDescriptor>): void + +Obtains the descriptor of the raw file in the **resources/rawfile** directory. This API uses an asynchronous callback to return the result. + +**System capability**: SystemCapability.Global.ResourceManager + +**Parameters** + +| Name | Type | Mandatory | Description | +| -------- | ---------------------------------------- | ---- | -------------------------------- | +| path | string | Yes | Path of the raw file. | +| callback | AsyncCallback<[RawFileDescriptor](#rawfiledescriptor8)> | Yes | Callback used to return the result.| + +**Error codes** + +For details about the error codes, see [Resource Manager Error Codes](../errorcodes/errorcode-resource-manager.md). + +| ID| Error Message| +| -------- | ---------------------------------------- | +| 9001005 | If the resource not found by path. | + +**Example** + ```ts + try { + this.context.resourceManager.getRawFd("test.xml", (error, value) => { + if (error != null) { + console.log(`callback getRawFd failed error code: ${error.code}, message: ${error.message}.`); + } else { + let fd = value.fd; + let offset = value.offset; + let length = value.length; + } + }); + } catch (error) { + console.error(`callback getRawFd failed, error code: ${error.code}, message: ${error.message}.`); + } + ``` + +### getRawFd9+ + +getRawFd(path: string): Promise<RawFileDescriptor> + +Obtains the descriptor of the raw file in the **resources/rawfile** directory. This API uses a promise to return the result. + +**System capability**: SystemCapability.Global.ResourceManager + +**Parameters** + +| Name | Type | Mandatory | Description | +| ---- | ------ | ---- | ----------- | +| path | string | Yes | Path of the raw file.| + +**Return value** + +| Type | Description | +| ---------------------------------------- | ------------------- | +| Promise<[RawFileDescriptor](#rawfiledescriptor8)> | Promise used to return the result.| + +**Error codes** + +For details about the error codes, see [Resource Manager Error Codes](../errorcodes/errorcode-resource-manager.md). + +| ID| Error Message| +| -------- | ---------------------------------------- | +| 9001005 | If the resource not found by path. | + +**Example** + ```ts + try { + this.context.resourceManager.getRawFd("test.xml").then(value => { + let fd = value.fd; + let offset = value.offset; + let length = value.length; + }).catch(error => { + console.log(`promise getRawFd error error code: ${error.code}, message: ${error.message}.`); + }); + } catch (error) { + console.error(`promise getRawFd failed, error code: ${error.code}, message: ${error.message}.`); + } + ``` + +### closeRawFdSync10+ + +closeRawFdSync(path: string): void + +Closes the descriptor of the raw file in the **resources/rawfile** directory. + +**System capability**: SystemCapability.Global.ResourceManager + +**Parameters** + +| Name | Type | Mandatory | Description | +| -------- | ------------------------- | ---- | ----------- | +| path | string | Yes | Path of the raw file.| + +**Error codes** + +For details about the error codes, see [Resource Manager Error Codes](../errorcodes/errorcode-resource-manager.md). + +| ID| Error Message| +| -------- | ---------------------------------------- | +| 9001005 | The resource not found by path. | + +**Example** + ```ts + try { + this.context.resourceManager.closeRawFdSync("test.txt"); + } catch (error) { + console.error(`closeRawFd failed, error code: ${error.code}, message: ${error.message}.`); + } + ``` + +### closeRawFd9+ + +closeRawFd(path: string, callback: AsyncCallback<void>): void + +Closes the descriptor of the raw file in the **resources/rawfile** directory. This API uses an asynchronous callback to return the result. + +**System capability**: SystemCapability.Global.ResourceManager + +**Parameters** + +| Name | Type | Mandatory | Description | +| -------- | ------------------------- | ---- | ----------- | +| path | string | Yes | Path of the raw file.| +| callback | AsyncCallback<void> | Yes | Callback used to return the result. | + +**Error codes** + +For details about the error codes, see [Resource Manager Error Codes](../errorcodes/errorcode-resource-manager.md). + +| ID| Error Message| +| -------- | ---------------------------------------- | +| 9001005 | The resource not found by path. | + +**Example** + ```ts + try { + this.context.resourceManager.closeRawFd("test.xml", (error, value) => { + if (error != null) { + console.log("error is " + error); + } + }); + } catch (error) { + console.error(`callback closeRawFd failed, error code: ${error.code}, message: ${error.message}.`); + } + ``` + +### closeRawFd9+ + +closeRawFd(path: string): Promise<void> + +Closes the descriptor of the raw file in the **resources/rawfile** directory. This API uses a promise to return the result. + +**System capability**: SystemCapability.Global.ResourceManager + +**Parameters** + +| Name | Type | Mandatory | Description | +| ---- | ------ | ---- | ----------- | +| path | string | Yes | Path of the raw file.| + +**Return value** + +| Type | Description | +| ------------------- | ---- | +| Promise<void> | Promise that returns no value.| + +**Error codes** + +For details about the error codes, see [Resource Manager Error Codes](../errorcodes/errorcode-resource-manager.md). + +| ID| Error Message| +| -------- | ---------------------------------------- | +| 9001005 | If the resource not found by path. | + +**Example** + ```ts + try { + this.context.resourceManager.closeRawFd("test.xml").then(value => { + let result = value; + }).catch(error => { + console.log("closeRawFd promise error is " + error); + }); + } catch (error) { + console.error(`promise closeRawFd failed, error code: ${error.code}, message: ${error.message}.`); + } + ``` + +### getConfiguration + +getConfiguration(callback: AsyncCallback<Configuration>): void + +Obtains the device configuration. This API uses an asynchronous callback to return the result. + +**System capability**: SystemCapability.Global.ResourceManager + +**Parameters** + +| Name | Type | Mandatory | Description | +| -------- | ---------------------------------------- | ---- | ------------------------- | +| callback | AsyncCallback<[Configuration](#configuration)> | Yes | Callback used to return the result.| + +**Example** + ```ts + try { + this.context.resourceManager.getConfiguration((error, value) => { + if (error != null) { + console.error("getConfiguration callback error is " + error); + } else { + let direction = value.direction; + let locale = value.locale; + } + }); + } catch (error) { + console.error("getConfiguration callback error is " + error); + } + ``` + +### getConfiguration + +getConfiguration(): Promise<Configuration> + +Obtains the device configuration. This API uses a promise to return the result. + +**System capability**: SystemCapability.Global.ResourceManager + +**Return value** + +| Type | Description | +| ---------------------------------------- | ---------------- | +| Promise<[Configuration](#configuration)> | Promise used to return the result.| + +**Example** + ```ts + try { + this.context.resourceManager.getConfiguration().then(value => { + let direction = value.direction; + let locale = value.locale; + }).catch(error => { + console.error("getConfiguration promise error is " + error); + }); + } catch (error) { + console.error("getConfiguration promise error is " + error); + } + ``` + +### getDeviceCapability + +getDeviceCapability(callback: AsyncCallback<DeviceCapability>): void + +Obtains the device capability. This API uses an asynchronous callback to return the result. + +**System capability**: SystemCapability.Global.ResourceManager + +**Parameters** + +| Name | Type | Mandatory | Description | +| -------- | ---------------------------------------- | ---- | ---------------------------- | +| callback | AsyncCallback<[DeviceCapability](#devicecapability)> | Yes | Callback used to return the result.| + +**Example** + ```ts + try { + this.context.resourceManager.getDeviceCapability((error, value) => { + if (error != null) { + console.error("getDeviceCapability callback error is " + error); + } else { + let screenDensity = value.screenDensity; + let deviceType = value.deviceType; + } + }); + } catch (error) { + console.error("getDeviceCapability callback error is " + error); + } + ``` + +### getDeviceCapability + +getDeviceCapability(): Promise<DeviceCapability> + +Obtains the device capability. This API uses a promise to return the result. + +**System capability**: SystemCapability.Global.ResourceManager + +**Return value** + +| Type | Description | +| ---------------------------------------- | ------------------- | +| Promise<[DeviceCapability](#devicecapability)> | Promise used to return the result.| + +**Example** + ```ts + try { + this.context.resourceManager.getDeviceCapability().then(value => { + let screenDensity = value.screenDensity; + let deviceType = value.deviceType; + }).catch(error => { + console.error("getDeviceCapability promise error is " + error); + }); + } catch (error) { + console.error("getDeviceCapability promise error is " + error); + } + ``` + +### release7+ + +release() + +Releases a created **resourceManager** object. + +**System capability**: SystemCapability.Global.ResourceManager + +**Example** + ```ts + try { + this.context.resourceManager.release(); + } catch (error) { + console.error("release error is " + error); } ``` @@ -3666,9 +4159,9 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco ```ts let path = getContext().bundleCodeDir + "/library1-default-signed.hsp"; try { - this.context.resourceManager.addResource(path); + this.context.resourceManager.addResource(path); } catch (error) { - console.error(`addResource failed, error code: ${error.code}, message: ${error.message}.`); + console.error(`addResource failed, error code: ${error.code}, message: ${error.message}.`); } ``` @@ -3698,9 +4191,9 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco ```ts let path = getContext().bundleCodeDir + "/library1-default-signed.hsp"; try { - this.resmgr.removeResource(path); + this.resmgr.removeResource(path); } catch (error) { - console.error(`removeResource failed, error code: ${error.code}, message: ${error.message}.`); + console.error(`removeResource failed, error code: ${error.code}, message: ${error.message}.`); } ``` diff --git a/en/application-dev/reference/apis/js-apis-sim.md b/en/application-dev/reference/apis/js-apis-sim.md index fb3aa7540b..cbc5ed086f 100644 --- a/en/application-dev/reference/apis/js-apis-sim.md +++ b/en/application-dev/reference/apis/js-apis-sim.md @@ -2732,7 +2732,7 @@ Obtains the MSISDN of the SIM card in the specified slot. This API uses an async **System API**: This is a system API. -**Required permission**: ohos.permission.GET_TELEPHONY_STATE +**Required permission**: ohos.permission.GET_PHONE_NUMBERS **System capability**: SystemCapability.Telephony.CoreService @@ -2775,7 +2775,7 @@ Obtains the MSISDN of the SIM card in the specified slot. This API uses a promis **System API**: This is a system API. -**Required permission**: ohos.permission.GET_TELEPHONY_STATE +**Required permission**: ohos.permission.GET_PHONE_NUMBERS **System capability**: SystemCapability.Telephony.CoreService diff --git a/en/application-dev/reference/apis/js-apis-socket.md b/en/application-dev/reference/apis/js-apis-socket.md index 76c7829cf8..f193ed010e 100644 --- a/en/application-dev/reference/apis/js-apis-socket.md +++ b/en/application-dev/reference/apis/js-apis-socket.md @@ -1691,7 +1691,7 @@ listen(address: NetAddress, callback: AsyncCallback\): void Binds the IP address and port number. The port number can be specified or randomly allocated by the system. The server listens to and accepts TCP socket connections established over the socket. Multiple threads are used to process client data concurrently. This API uses an asynchronous callback to return the result. -> **NOTE** +> **NOTE**
> The server uses this API to perform the **bind**, **listen**, and **accept** operations. If the **bind** operation fails, the system randomly allocates a port number. **Required permissions**: ohos.permission.INTERNET @@ -1736,7 +1736,7 @@ listen(address: NetAddress): Promise\ Binds the IP address and port number. The port number can be specified or randomly allocated by the system. The server listens to and accepts TCP socket connections established over the socket. Multiple threads are used to process client data concurrently. This API uses a promise to return the result. -> **NOTE** +> **NOTE**
> The server uses this API to perform the **bind**, **listen**, and **accept** operations. If the **bind** operation fails, the system randomly allocates a port number. **Required permissions**: ohos.permission.INTERNET diff --git a/en/application-dev/reference/errorcodes/errorcode-hiappevent.md b/en/application-dev/reference/errorcodes/errorcode-hiappevent.md index e0b7e16e05..11ac6f8288 100644 --- a/en/application-dev/reference/errorcodes/errorcode-hiappevent.md +++ b/en/application-dev/reference/errorcodes/errorcode-hiappevent.md @@ -1,4 +1,4 @@ -# Application Event Logging Error Codes +# Application Event Logging Error Codes > **NOTE** > @@ -63,8 +63,8 @@ This error code is reported if the **write** API is called to perform applicatio The specified event name does not comply with the following rules: -- The event name contains only digits, lowercase letters, and underscores (\_). -- The event name starts with a lowercase letter and does not end with an underscore (\_). +- An event name contains only digits, letters, and underscores (_). +- An event name starts with a letter or dollar sign ($) and does not end with an underscore (_). - The event name is not empty and contains a maximum of 48 characters. **Solution** @@ -119,11 +119,11 @@ This error code is reported if the **write** API is called to perform applicatio **Possible Causes** -The specified event parameter name does not comply with the following rules: +The specified event name does not comply with the following rules: -- The event parameter name contains only digits, lowercase letters, and underscores (\_). -- The event parameter name starts with a lowercase letter and does not end with an underscore (\_). -- The event parameter name is not empty and contains a maximum of 16 characters. +- An event name contains only digits, letters, and underscores (_). +- An event name starts with a letter or dollar sign ($) and does not end with an underscore (_). +- An event parameter name is not empty and contains a maximum of 16 characters. **Solution** @@ -163,7 +163,7 @@ The specified watcher name does not comply with the following rules: - The watcher name can contain only digits, lowercase letters, and underscores (\_). - The watcher name starts with a lowercase letter and does not end with an underscore (\_). -- The watcher name is not empty and contains a maximum of 32 characters. +- A watcher name is not empty and contains a maximum of 32 characters. **Solution** diff --git a/en/device-dev/subsystems/subsys-dfx-hisysevent-listening.md b/en/device-dev/subsystems/subsys-dfx-hisysevent-listening.md index 613c624e1a..95bdd78be0 100644 --- a/en/device-dev/subsystems/subsys-dfx-hisysevent-listening.md +++ b/en/device-dev/subsystems/subsys-dfx-hisysevent-listening.md @@ -4,156 +4,319 @@ ## Overview -### Introduction +### Function Introduction -HiSysEvent supports listening for events across processes. You can register a listener to listen for concerned events on a real-time basis. For example, you can enable the battery module to listen for power consumption events for power usage analysis. +HiSysEvent supports listening for events across processes. You can register a listener to listen for concerned events on a real-time basis. For example, you can enable the battery module to subscribe to power consumption events for power usage analysis. ### Constraints -Before subscribing to system events, you need to configure HiSysEvent logging. For details, see [HiSysEvent Logging Configuration](../subsystems/subsys-dfx-hisysevent-logging-config.md). +Before listening for system events, you need to configure HiSysEvent logging. For details, see [HiSysEvent Logging Configuration](../subsystems/subsys-dfx-hisysevent-logging-config.md). -## Development Guidelines - +## How to Develop ### Available APIs - **Table 1** Description of HiSysEventListener APIs +#### C++ APIs -| API| Description| -| -------- | -------- | -| int32_t HiSysEventManager::AddListener(std::shared_ptr<HiSysEventListener> listener, std::vector<ListenerRule>& rules) | Registers a listener for system events. You can listen for certain events by specifying rules.
Input arguments:
- **listener**: callback object for system events.
- **rules**: rules for event listening.
Return value:
- **0**: Registration is successful.
- A negative value: Registration has failed.| -| int32_t HiSysEventManager::RemoveListener(std::shared_ptr<HiSysEventListener> listener) | Removes the listener for system events.
Input arguments:
- **listener**: callback object for system events.
Return value:
- **0**: Canceling registration is successful.
- A negative value: Canceling registration has failed. | +HiSysEvent is implemented using the APIs provided by the **HiSysEventManager** class. For details, see the [API Header Files](/base/hiviewdfx/hisysevent/interfaces/native/innerkits/hisysevent_manager/include/). - **Table 2** Description of ListenerRule +> **NOTE** +> +> For details about the **RuleType** argument in the constructor of **ListenerRule**, see Table 4 in [HiSysEvent Query](subsys-dfx-hisysevent-query.md). + + **Table 1** Description of C++ HiSysEventManager APIs -| API| Description| +| Name| Description| | -------- | -------- | -| ListenerRule(const std::string& tag, RuleType ruleType = RuleType::WHOLE_WORD) | Constructor used to create a **ListenerRule** object based on the event tag.
Input arguments:
- **tag**: event tag for the **ListenerRule** object. The value is a string of 1 to 16 characters, including uppercase letters, lowercase letters, and digits.
- **ruleType**: type of the **ListenerRule** object. The value is an enum defined by **RuleType**.| -| ListenerRule(const std::string& domain, const std::string& eventName, RuleType ruleType = RuleType::WHOLE_WORD) | Constructor used to create a **ListenerRule** object based on the event domain and event name.
Input arguments:
- **domain**: event domain for the **ListenerRule** object. The value is a string of 1 to 16 characters, including uppercase letters, digits, and underscores.
- **eventName**: event name for the **ListenerRule** object. The value is a string of 1 to 32 characters, including uppercase letters, digits, and underscores.
- **ruleType**: type of the **ListenerRule** object. The value is an enum defined by **RuleType**.| -| ListenerRule(const std::string& domain, const std::string& eventName, const std::string& tag, RuleType ruleType = RuleType::WHOLE_WORD) | Constructor used to create a **ListenerRule** object based on the event domain, event name, and event tag.
Input arguments:
- **tag**: event tag for the **ListenerRule** object. The value is a string of 1 to 16 characters, including uppercase letters, lowercase letters, and digits.
- **domain**: event domain for the **ListenerRule** object. The value is a string of 1 to 16 characters, including uppercase letters, digits, and underscores.
- **eventName**: event name for the **ListenerRule** object. The value is a string of 1 to 32 characters, including uppercase letters, digits, and underscores.
- **ruleType**: type of the **ListenerRule** object. The value is an enum defined by **RuleType**.| +| int32_t HiSysEventManager::AddListener(std::shared_ptr<HiSysEventListener> listener,
 std::vector<ListenerRule>& rules) | Adds a listener to listen for system events based on the specified rules.
Input arguments:
- **listener**: listener for system events.
- **rules**: event listening rules.
Return value:
- **0**: The listener is added successfully.
- A negative value: The listener fails to be added.| +| int32_t HiSysEventManager::RemoveListener(std::shared_ptr<HiSysEventListener> listener) | Removes the listener for system events.
Input arguments:
- **listener**: listener for system events.
Return value:
- **0**: The listener is removed successfully.
- A negative value: The listener fails to be removed. | - **Table 3** Description of RuleType + **Table 2** Description of ListenerRule -| Value| Description| +| Name| Description| | -------- | -------- | -| WHOLE_WORD | Whole word matching| -| PREFIX | Prefix matching| -| REGULAR | Regular expression matching| +| ListenerRule(const std::string& tag,
 RuleType ruleType = RuleType::WHOLE_WORD) | Constructor used to create a **ListenerRule** object based on the event tag.
Input arguments:
- **tag**: event tag for the **ListenerRule** object. The value is a string of 1 to 16 characters, including uppercase letters, lowercase letters, and digits.
- **ruleType**: type of the **ListenerRule** object. The value is an enum defined by **RuleType**.| +| ListenerRule(const std::string& domain,
 const std::string& eventName,
 RuleType ruleType = RuleType::WHOLE_WORD) | Constructor used to create a **ListenerRule** object based on the event domain and event name.
Input arguments:
- **domain**: event domain for the **ListenerRule** object. The value is a string of 1 to 16 characters, including uppercase letters, digits, and underscores.
- **eventName**: event name for the **ListenerRule** object. The value is a string of 1 to 32 characters, including uppercase letters, digits, and underscores.
- **ruleType**: type of the **ListenerRule** object. The value is an enum defined by **RuleType**.| +| ListenerRule(const std::string& domain,
 const std::string& eventName,
 const std::string& tag,
 RuleType ruleType = RuleType::WHOLE_WORD) | Constructor used to create a **ListenerRule** object based on the event domain, event name, and event tag.
Input arguments:
- **tag**: event tag for the **ListenerRule** object. The value is a string of 1 to 16 characters, including uppercase letters, lowercase letters, and digits.
- **domain**: event domain for the **ListenerRule** object. The value is a string of 1 to 16 characters, including uppercase letters, digits, and underscores.
- **eventName**: event name for the **ListenerRule** object. The value is a string of 1 to 32 characters, including uppercase letters, digits, and underscores.
- **ruleType**: type of the **ListenerRule** object. The value is an enum defined by **RuleType**.| - **Table 4** Description of HiSysEventListener + **Table 3** Description of HiSysEventListener -| API| Description| +| Name| Description| | -------- | -------- | -| void HiSysEventListener::OnEvent(std::shared_ptr<HiSysEventRecord> sysEvent) | Callback object for system events.
Input arguments:
- **sysEvent**: real-time system events.
Return value:
None.| -| void HiSysEventListener::OnServiceDied() | Callback object for service exceptions.
Input arguments:
None.
Return value:
None.| +| void HiSysEventListener::OnEvent(std::shared_ptr<HiSysEventRecord> sysEvent) | Callback object for system events.
Input arguments:
- **sysEvent**: real-time system event.
Return value:
None.| +| void HiSysEventListener::OnServiceDied() | Callback object for service exceptions.
Input arguments:
None.
Return value:
None.| -**Table 5** Description of HiSysEventRecord -| API| Description| + **Table 4** Description of HiSysEventRecord +| Name| Description| | -------- | -------- | -|std::string HiSysEventRecord::AsJson()|Obtains the content of a system event.
Input arguments:
None.
Return value:
Content of the system event.| -|std::string HiSysEventRecord::GetDomain()|Obtains the domain name of a system event.
Input arguments:
None.
Return value:
Domain name of the system event.| -|std::string HiSysEventRecord::GetEventName()|Obtains the name of a system event.
Input arguments:
None.
Return value:
Name of the system event.| -|HiSysEvent::EventType HiSysEventRecord::GetEventType()|Obtains the type of a system event.
Input arguments:
None.
Return value:
Type of the system event.| -|std::string HiSysEventRecord::GetLevel()|Obtains the level of a system event.
Input arguments:
None.
Return value:
Level of the system event.| -|std::string HiSysEventRecord::GetTag()|Obtains the tag of a system event.
Input arguments:
None.
Return value:
Tag of the system event.| -|std::string HiSysEventRecord::GetTimeZone()|Obtains the time zone of a system event.
Input arguments:
None.
Return value:
Time zone, in the format of **+0800**.| -|int HiSysEventRecord::GetTraceFlag()|Obtains the distributed call chain tracing flag of a system event.
Input arguments:
None.
Return value:
Distributed call chain tracing flag.| -|int64_t HiSysEventRecord::GetPid()|Obtains the ID of the process that flushes a system event to the disk.
Input arguments:
None.
Return value:
Process ID.| -|int64_t HiSysEventRecord::GetTid()|Obtains the thread ID of the process that flushes a system event to the disk.
Input arguments:
None.
Return value:
Thread ID.| -|int64_t HiSysEventRecord::GetUid()|Obtains the user ID of the process that flushes a system event to the disk.
Input arguments:
None.
Return value:
User ID.| -|uint64_t HiSysEventRecord::GetPspanId()|Obtains the parent span ID of the distributed call chain tracing task.
Input arguments:
None.
Return value:
Parent span ID of the distributed call chain tracing task.| -|uint64_t HiSysEventRecord::GetSpandId()|Obtains the span ID of the distributed call chain tracing task.
Input arguments:
None.
Return value:
Span ID of the distributed call chain tracing task.| -|uint64_t HiSysEventRecord::GetTime()|Obtains the timestamp of a system event.
Input arguments:
None.
Return value:
Timestamp of the system event.| -|uint64_t HiSysEventRecord::GetTraceId()|Obtains the ID of the distributed call chain tracing task.
Input arguments:
None.
Return value:
ID of the distributed call chain tracing task.| -|void HiSysEventRecord::GetParamNames(std::vector<std::string>& params)|Obtains all key names of a system event.
Input arguments:
- **params**: key name array reference.
Return value:
None.| -|int HiSysEventRecord::GetParamValue(const std::string& param, int64_t& value)|Parses the value of the **param** key in a system event into an int64\_t value.
Input arguments:
- **param**: key name.
- **value**: int64\_t reference.
Return value:
- **0**: Parsing is successful.
- **-1**: Parsing failed due to initialization error.
- **-2**: Parsing failed due to nonexistent key name.
- **-3**: Parsing failed due to type mismatch.| -|int HiSysEventRecord::GetParamValue(const std::string& param, uint64_t& value)|Parses the value of the **param** key in a system event into a uint64\_t value.
Input arguments:
- **param**: key name.
- **value**: uint64\_t reference.
Return value:
- **0**: Parsing is successful.
- **-1**: Parsing failed due to initialization error.
- **-2**: Parsing failed due to nonexistent key name.
- **-3**: Parsing failed due to type mismatch.| -|int HiSysEventRecord::GetParamValue(const std::string& param, double& value)|Parses the value of the **param** key in a system event into a double value.
Input arguments:
- **param**: key name.
- **value**: double reference.
Return value:
- **0**: Parsing is successful.
- **-1**: Parsing failed due to initialization error.
- **-2**: Parsing failed due to nonexistent key name.
- **-3**: Parsing failed due to type mismatch.| -|int HiSysEventRecord::GetParamValue(const std::string& param, std::string& value)|Parses the value of the **param** key in a system event into a string value.
Input arguments:
- **param**: key name.
- **value**: std::string reference.
Return value:
- **0**: Parsing is successful.
- **-1**: Parsing failed due to initialization error.
- **-2**: Parsing failed due to nonexistent key name.
- **-3**: Parsing failed due to type mismatch.| -|int HiSysEventRecord::GetParamValue(const std::string& param, std::vector<int64_t>& value)|Parses the value of the **param** key in a system event into an int64\_t array.
Input arguments:
- **param**: key name.
- **value**: int64\_t array reference.
Return value:
- **0**: Parsing is successful.
- **-1**: Parsing failed due to initialization error.
- **-2**: Parsing failed due to nonexistent key name.
- **-3**: Parsing failed due to type mismatch.| -|int HiSysEventRecord::GetParamValue(const std::string& param, std::vector<uint64_t>& value)|Parses the value of the **param** key in a system event into a uint64\_t array.
Input arguments:
- **param**: key name.
- **value**: uint64\_t array reference.
Return value:
- **0**: Parsing is successful.
- **-1**: Parsing failed due to initialization error.
- **-2**: Parsing failed due to nonexistent key name.
- **-3**: Parsing failed due to type mismatch.| -|int HiSysEventRecord::GetParamValue(const std::string& param, std::vector<double>& value)|Parses the value of the **param** key in a system event into a double array.
Input arguments:
- **param**: key name.
- **value**: double array reference.
Return value:
- **0**: Parsing is successful.
- **-1**: Parsing failed due to initialization error.
- **-2**: Parsing failed due to nonexistent key name.
- **-3**: Parsing failed due to type mismatch.| -|int HiSysEventRecord::GetParamValue(const std::string& param, std::vector<std::string>& value)|Parses the value of the **param** key in a system event into a string array.
Input arguments:
- **param**: key name.
- **value**: std::string array reference.
Return value:
- **0**: Parsing is successful.
- **-1**: Parsing failed due to initialization error.
- **-2**: Parsing failed due to nonexistent key name.
- **-3**: Parsing failed due to type mismatch.| - - -## How to Develop - - -### **C++** - -The following provides an example of how to use C++ APIs of **HiSysEvent**. - -1. Develop the source code. - Import the **DemoListener.h** header file, which contains the **DemoListener** class for implementing the custom event callback. - - ``` - #ifndef DEMO_LISTENER_H - #define DEMO_LISTENER_H - - #include "hisysevent_listener.h" - - #include - - class DemoListener : public OHOS::HiviewDFX::HiSysEventListener { - public: - explicit DemoListener() : HiSysEventListener() {} - virtual ~DemoListener() {} - - public: - void OnEvent(std::shared_ptr sysEvent); - void OnServiceDied(); - }; - - #endif // DEMO_LISTENER_H - ``` - - Create the **DemoListener.cpp** file, and add the implementation logic of the custom event callback API in the **DemoListener** class. - - ``` - #include "demo_listener.h" - - #include - - void DemoListener::OnEvent(std::shared_ptr sysEvent) - { - if (sysEvent == nullptr) { - return; +|std::string HiSysEventRecord::AsJson()|Obtains the content of a system event.
Input arguments:
None.
Return value:
Content of the system event.| +|std::string HiSysEventRecord::GetDomain()|Obtains the domain name of a system event.
Input arguments:
None.
Return value:
Domain name of the system event.| +|std::string HiSysEventRecord::GetEventName()|Obtains the name of a system event.
Input arguments:
None.
Return value:
Name of the system event.| +|HiSysEvent::EventType HiSysEventRecord::GetEventType()|Obtains the type of a system event.
Input arguments:
None.
Return value:
Type of the system event.| +|std::string HiSysEventRecord::GetLevel()|Obtains the level of a system event.
Input arguments:
None.
Return value:
Level of the system event.| +|std::string HiSysEventRecord::GetTag()|Obtains the tag of a system event.
Input arguments:
None.
Return value:
Tag of the system event.| +|std::string HiSysEventRecord::GetTimeZone()|Obtains the time zone of a system event.
Input arguments:
None.
Return value:
Time zone, in the format of **+0800**.| +|int HiSysEventRecord::GetTraceFlag()|Obtains the distributed call chain tracing flag of a system event.
Input arguments:
None.
Return value:
Distributed call chain tracing flag.| +|int64_t HiSysEventRecord::GetPid()|Obtains the ID of the process that flushes a system event to the disk.
Input arguments:
None.
Return value:
Process ID.| +|int64_t HiSysEventRecord::GetTid()|Obtains the thread ID of the process that flushes a system event to the disk.
Input arguments:
None.
Return value:
Thread ID.| +|int64_t HiSysEventRecord::GetUid()|Obtains the user ID of the process that flushes a system event to the disk.
Input arguments:
None.
Return value:
User ID.| +|uint64_t HiSysEventRecord::GetPspanId()|Obtains the parent span ID of the distributed call chain tracing task.
Input arguments:
None.
Return value:
Parent span ID of the distributed call chain tracing task.| +|uint64_t HiSysEventRecord::GetSpandId()|Obtains the span ID of the distributed call chain tracing task.
Input arguments:
None.
Return value:
Span ID of the distributed call chain tracing task.| +|uint64_t HiSysEventRecord::GetTime()|Obtains the timestamp of a system event.
Input arguments:
None.
Return value:
Timestamp.| +|uint64_t HiSysEventRecord::GetTraceId()|Obtains the ID of the distributed call chain tracing task.
Input arguments:
None.
Return value:
ID of the distributed call chain tracing task.| +|void HiSysEventRecord::GetParamNames(std::vector<std::string>& params)|Obtains all key names of a system event.
Input arguments:
- **params**: key name array reference.
Return value:
None.| +|int HiSysEventRecord::GetParamValue(const std::string& param, int64_t& value)|Parses the value of the **param** key in a system event into an int64\_t value.
Input arguments:
- **param**: key name.
- **value**: int64\_t reference.
Return value:
- **0**: Parsing is successful.
- **-1**: Parsing failed due to initialization error.
- **-2**: Parsing failed due to nonexistent key name.
- **-3**: Parsing failed due to type mismatch.| +|int HiSysEventRecord::GetParamValue(const std::string& param, uint64_t& value)|Parses the value of the **param** key in a system event into a uint64\_t value.
Input arguments:
- **param**: key name.
- **value**: uint64\_t reference.
Return value:
- **0**: Parsing is successful.
- **-1**: Parsing failed due to initialization error.
- **-2**: Parsing failed due to nonexistent key name.
- **-3**: Parsing failed due to type mismatch.| +|int HiSysEventRecord::GetParamValue(const std::string& param, double& value)|Parses the value of the **param** key in a system event into a double value.
Input arguments:
- **param**: key name.
- **value**: double reference.
Return value:
- **0**: Parsing is successful.
- **-1**: Parsing failed due to initialization error.
- **-2**: Parsing failed due to nonexistent key name.
- **-3**: Parsing failed due to type mismatch.| +|int HiSysEventRecord::GetParamValue(const std::string& param, std::string& value)|Parses the value of the **param** key in a system event into a string value.
Input arguments:
- **param**: key name.
- **value**: std::string reference.
Return value:
- **0**: Parsing is successful.
- **-1**: Parsing failed due to initialization error.
- **-2**: Parsing failed due to nonexistent key name.
- **-3**: Parsing failed due to type mismatch.| +|int HiSysEventRecord::GetParamValue(const std::string& param, std::vector<int64_t>& value)|Parses the value of the **param** key in a system event into an int64\_t array.
Input arguments:
- **param**: key name.
- **value**: int64\_t array reference.
Return value:
- **0**: Parsing is successful.
- **-1**: Parsing failed due to initialization error.
- **-2**: Parsing failed due to nonexistent key name.
- **-3**: Parsing failed due to type mismatch.| +|int HiSysEventRecord::GetParamValue(const std::string& param, std::vector<uint64_t>& value)|Parses the value of the **param** key in a system event into a uint64\_t array.
Input arguments:
- **param**: key name.
- **value**: uint64\_t array reference.
Return value:
- **0**: Parsing is successful.
- **-1**: Parsing failed due to initialization error.
- **-2**: Parsing failed due to nonexistent key name.
- **-3**: Parsing failed due to type mismatch.| +|int HiSysEventRecord::GetParamValue(const std::string& param, std::vector<double>& value)|Parses the value of the **param** key in a system event into a double array.
Input arguments:
- **param**: key name.
- **value**: double array reference.
Return value:
- **0**: Parsing is successful.
- **-1**: Parsing failed due to initialization error.
- **-2**: Parsing failed due to nonexistent key name.
- **-3**: Parsing failed due to type mismatch.| +|int HiSysEventRecord::GetParamValue(const std::string& param, std::vector<std::string>& value)|Parses the value of the **param** key in a system event into a string array.
Input arguments:
- **param**: key name.
- **value**: std::string array reference.
Return value:
- **0**: Parsing is successful.
- **-1**: Parsing failed due to initialization error.
- **-2**: Parsing failed due to nonexistent key name.
- **-3**: Parsing failed due to type mismatch.| + +#### C APIs + +HiSysEvent listening is implemented using the API provided in the following table. For details, see the [API Header Files](/base/hiviewdfx/hisysevent/interfaces/native/innerkits/hisysevent_manager/include/). + +> **NOTE** +> +> For details about the **HiSysEventRecord** argument in the **OnEvent** callback of **HiSysEventWatcher**, see Table 11 and Table 12 in [HiSysEvent Query](subsys-dfx-hisysevent-query.md). + + **Table 5** Description of C HiSysEventManager APIs + +| Name | Description | +| ------------------------------------------------------------ | ------------------------------------------------------------ | +| int OH_HiSysEvent_Add_Watcher(HiSysEventWatcher* watcher,
HiSysEventWatchRule rules[],
size_t ruleSize); | Adds a listener to listen for system events based on the specified rules.
Input arguments:
- **watcher**: watcher for system events.
- **rules**: array of event listening rules.
- **ruleSize**: length of the array of event listening rules.
Return value:
- **0**: The listener is added successfully.
- A negative value: The listener fails to be added.| +| int OH_HiSysEvent_Remove_Watcher(HiSysEventWatcher* watcher); | Remove the watcher for system events.
Input arguments:
- **watcher**: watcher for system events.
Return value:
- **0**: The watcher is removed successfully.
- A negative value: The watcher fails to be removed. | + + + **Table 6** Description of the HiSysEventWatcher structure +| Field | Type | Description | +| ------------- | -------------------------------------------------- | ------------------------------------------------------------ | +| OnEvent | void (*)(HiSysEventRecord record); | Callback object for system events.
Input arguments:
- **record**: real-time system event.
Return value:
None.| +| OnServiceDied | void (*)(); | Callback object for service exceptions.
Input arguments:
None.
Return value:
None. | + + **Table 7** Description of the HiSysEventWatchRule structure +| Field | Type | Description | +| ------------- | --------- | ---------------------------------- | +| domain | char[] | Event domain. | +| name | char[] | Event name. | +| tag | char[] | Event tag. | +| ruleType | int | Event matching rule. For details about the values, see Table 4 in [HiSysEvent Query](subsys-dfx-hisysevent-query.md). | +| eventType | int | Event type. For details about the values, see Table 3 in [HiSysEvent Query](subsys-dfx-hisysevent-query.md). The value **0** indicates all event types. | + +### How to Develop + +#### C++ HiSysEvent Listening + +1. Import the corresponding header file. + + ```c++ + #include "hisysevent_manager.h" + ``` + +2. Implement the callback API for the service domain. + + ```c++ + class TestListener : public OHOS::HiviewDFX::HiSysEventListener { + public: + void OnEvent(std::shared_ptr record) + { + if (record == nullptr) { + return; + } + std::cout << record->AsJson() << std::endl; + } + + void OnServiceDied() + { + std::cout << std::string("service disconnect, exit") << std::endl; + exit(0); + } + }; + ``` + +3. Call the listening API while passing in parameters such as **listener** and **rules**. When the service ends, disable event listening. + + ```c++ + auto testListener = std::make_shared(); + // Add a ListenerRule object based on the event tag, with RuleType left unspecified (in this case, ruleType is defaulted to WHOLE_WORD). + ListenerRule tagRule("dfx"); + // Add a ListenerRule object based on the event tag, with RuleType set as REGULAR. + ListenerRule regRule("dfx.*", RuleType::REGULAR); + // Add a ListenerRule object based on the event domain and event name, with RuleType set as PREFIX. + ListenerRule domainNameRule("HIVIEWDFX", "APP_USAGE", RuleType::PREFIX); + std::vector sysRules; + sysRules.push_back(tagRule); + sysRules.push_back(regRule); + sysRules.push_back(domainNameRule); + // Start event listening. + auto ret = HiSysEventManager::AddEventListener(testListener, sysRules); + // Remove the listener when the service ends. + if (ret == 0) { + HiSysEventManager::RemoveListener(testListener); + } + ``` + +#### C HiSysEvent Listening + +1. Import the corresponding header file. + + ```c++ + #include "hisysevent_manager_c.h" + ``` + +2. Implement the callback API for the service domain. + + ```c++ + void OnEventTest(HiSysEventRecord record) + { + printf("OnEventTest: event=%s", record.jsonStr); + } + + void OnServiceDiedTest() + { + printf("OnServiceDied"); + } + ``` + +3. Call the listening API while passing in parameters such as **watcher** and **rules**. When the service ends, disable event listening. + + ```c++ + HiSysEventWatcher watcher; + watcher.OnEvent = OnEventTest; + watcher.OnServiceDied = OnServiceDiedTest; + // Add a HiSysEventWatchRule object based on the event tag, with RuleType left unspecified (in this case, ruleType is defaulted to WHOLE_WORD). + constexpr char DFX_TAG[] = "dfx"; + HiSysEventWatchRule tagRule; + (void)strcpy_s(tagRule.tag, strlen(DFX_TAG) + 1, DFX_TAG); + tagRule.ruleType = 1; + tagRule.eventType = 0; + // Add a HiSysEventWatchRule object based on the event tag, with RuleType set as REGULAR. + constexpr char DFX_PATTERN_TAG[] = "dfx.*"; + HiSysEventWatchRule regRule; + (void)strcpy_s(regRule.tag, strlen(DFX_PATTERN_TAG) + 1, DFX_PATTERN_TAG); + regRule.ruleType = 3; + regRule.eventType = 0; + // Add a HiSysEventWatchRule object based on the event domain and event name, with RuleType set as PREFIX. + constexpr char DOMAIN[] = "HIVIEWDFX"; + constexpr char NAME[] = "APP_USAGE"; + HiSysEventWatchRule domainNameRule; + (void)strcpy_s(domainNameRule.domain, strlen(DOMAIN) + 1, DOMAIN); + (void)strcpy_s(domainNameRule.name, strlen(NAME) + 1, NAME); + domainNameRule.ruleType = 2; + domainNameRule.eventType = 0; + // Start event listening. + HiSysEventWatchRule rules[] = {tagRule, regRule, domainNameRule}; + int ret = OH_HiSysEvent_Add_Watcher(&watcher, rules, sizeof(rules) / sizeof(HiSysEventWatchRule)); + // Remove the watcher when the service ends. + if (ret == 0) { + ret = OH_HiSysEvent_Remove_Watcher(&watcher); + } + ``` + +### Development Examples + +#### C++ HiSysEvent Listening + +Suppose you want to enable listening for all events whose domain is **HIVIEWDFX** and name is **PLUGIN_LOAD**. The sample code is as follows: + +1. Add the **libhisysevent** and **libhisyseventmanager** dependencies of the **hisysevent** component to the **BUILD.gn** file of the service module. + + ```c++ + external_deps = [ + "hisysevent:libhisysevent", + "hisysevent:libhisyseventmanager", + ] + ``` + +2. Call the listening API in the **TestEventListening()** function. When the service ends, disable event listening. + + ```c++ + #include + + #include "hisysevent_manager.h" + + using namespace OHOS::HiviewDFX; + + class TestListener : public HiSysEventQueryCallback { + public: + void OnEvent(std::shared_ptr record) + { + if (record == nullptr) { + return; + } + std::cout << record->AsJson() << std::endl; + } + + void OnServiceDied() + { + std::cout << std::string("service disconnect, exit") << std::endl; + exit(0); + } + }; + + void TestEventListening() + { + auto testListener = std::make_shared(); + ListenerRule domainNameRule("HIVIEWDFX", "PLUGIN_LOAD", RuleType::WHOLE_WORD); + std::vector sysRules; + sysRules.push_back(domainNameRule); + auto ret = HiSysEventManager::AddEventListener(testListener, sysRules); + if (ret == 0) { + HiSysEventManager::RemoveListener(testListener); + } + } + ``` + +#### C HiSysEvent Listening + +Suppose you want to enable listening for all events whose domain is **HIVIEWDFX** and name is **PLUGIN_LOAD**. The sample code is as follows: + +1. Add the **libhisysevent** and **libhisyseventmanager** dependencies of the **hisysevent** component to the **BUILD.gn** file of the service module. + + ```c++ + external_deps = [ "hisysevent:libhisyseventmanager" ] + + // for strcpy_s + deps = [ "//third_party/bounds_checking_function:libsec_shared" ] + ``` + +2. Call the listening API in the **TestEventListening()** function. When the service ends, disable event listening. + + ```c++ + #include + + #include "hisysevent_manager_c.h" + + void OnEventTest(HiSysEventRecord record) + { + printf("OnEventTest: event=%s", record.jsonStr); + } + + void OnServiceDiedTest() + { + printf("OnServiceDied"); + } + + void TestEventListening() + { + HiSysEventWatcher watcher; + watcher.OnEvent = OnEventTest; + watcher.OnServiceDied = OnServiceDiedTest; + constexpr char DOMAIN[] = "HIVIEWDFX"; + constexpr char NAME[] = "PLUGIN_LOAD"; + HiSysEventWatchRule domainNameRule; + (void)strcpy_s(domainNameRule.domain, strlen(DOMAIN) + 1, DOMAIN); + (void)strcpy_s(domainNameRule.name, strlen(NAME) + 1, NAME); + domainNameRule.ruleType = 1; + domainNameRule.eventType = 0; + HiSysEventWatchRule rules[] = {domainNameRule}; + int ret = OH_HiSysEvent_Add_Watcher(&watcher, rules, sizeof(rules) / sizeof(HiSysEventWatchRule)); + if (ret == 0) { + ret = OH_HiSysEvent_Remove_Watcher(&watcher); } - std::cout << sysEvent.AsJson() << std::endl; - } - - void DemoListener::OnServiceDied() - { - std::cout << std::string("service disconnect, exit") << std::endl; - exit(0); - } - ``` - - Call the **AddEventListener** API of the **HiSysEventManager** class to add a listener for system events. - - ``` - auto demoListener = std::make_shared(); - // Add a ListenerRule object based on the event tag, with RuleType left unspecified (in this case, ruleType is defaulted to WHOLE_WORD). - ListenerRule tagRule("dfx"); - // Add a ListenerRule object based on the event tag, with RuleType set as REGULAR. - ListenerRule regRule("dfx.*", RuleType::REGULAR); - // Add a ListenerRule object based on the event domain and event name, with RuleType set as PREFIX. - ListenerRule domainNameRule("HIVIEWDFX", "APP_USAGE", RuleType::PREFIX); - std::vector sysRules; - sysRules.push_back(tagRule); - sysRules.push_back(regRule); - sysRules.push_back(domainNameRule); - HiSysEventManager::AddEventListener(demoListener, sysRules); - ``` - -2. Configure the **BUILD.gn** file. - In the **BUILD.gn** file, add the **libhisysevent** and **libhisyseventmanager** libraries that depend on the **hisysevent** component. - - ``` - external_deps = [ - "hisysevent:libhisysevent", - "hisysevent:libhisyseventmanager", - ] - ``` + } + ``` diff --git a/en/device-dev/subsystems/subsys-dfx-hisysevent-logging-config.md b/en/device-dev/subsystems/subsys-dfx-hisysevent-logging-config.md index 940b818894..0e50997085 100644 --- a/en/device-dev/subsystems/subsys-dfx-hisysevent-logging-config.md +++ b/en/device-dev/subsystems/subsys-dfx-hisysevent-logging-config.md @@ -33,10 +33,11 @@ Constraints on the event domain, event name, and parameter | Field| Description| | -------- | -------- | - | type | Event type. This field is mandatory.
Value:
- FAULT: fault
- STATISTIC: statistics
- SECURITY: security
- BEHAVIOR: user behavior| + | type | Event type. This field is mandatory.
Value:
- **FAULT**: fault
- STATISTIC: statistics
- **SECURITY**: security
- **BEHAVIOR**: behavior| | level | Event level. This field is mandatory.
Value:
- CRITICAL: critical
- MINOR: minor| | tag | Event tag. This field is mandatory.
Rule:
- You can define a maximum of five tags, separated with a space.
- A single tag can contain a maximum of 16 characters, including a to z, A to Z, and 0 to 9.| - | desc | Event name. This field is mandatory.
Rule:
The description contains 3 to 128 characters, including a to z, A to Z, 0 to 9, and underscores (_).| + | desc | Event name. This field is mandatory.
Rule:
- A string of 3 to 128 characters.| + | preserve | Whether events need to be logged in the event file. This field is optional. The default value is **true**.
Value:
- **true**: Events need to be logged in the event file.
- **false**: Events do not need to be logged in the event file.| **Table 2** Description of custom parameters @@ -44,7 +45,7 @@ Constraints on the event domain, event name, and parameter | -------- | -------- | | type | Parameter type. This field is mandatory.
Value:
- BOOL
- INT8
- UINT8
- INT16
- UINT16
- INT32
- UINT32
- INT64
- UINT64
- FLOAT
- DOUBLE
- STRING | | arrsize | Length of the parameter of the array type. This field is optional.
Value:
1-100| - | desc | Parameter description. This field is mandatory.
Rule:
The description contains 3 to 128 characters, including a to z, A to Z, 0 to 9, and underscores (_).| + | desc | Parameter description. This field is mandatory.
Rule:
- A string of 3 to 128 characters.| ## How to Develop diff --git a/en/device-dev/subsystems/subsys-dfx-hisysevent-query.md b/en/device-dev/subsystems/subsys-dfx-hisysevent-query.md index 88fd95fd4a..fe4151d04c 100644 --- a/en/device-dev/subsystems/subsys-dfx-hisysevent-query.md +++ b/en/device-dev/subsystems/subsys-dfx-hisysevent-query.md @@ -10,99 +10,119 @@ HiSysEvent allows you to query system events by specifying search criteria. For ### Available APIs -#### C++ Event Query API +#### C++ APIs HiSysEvent query is implemented using the API provided by the **HiSysEventManager** class. For details, see the [API Header Files](/base/hiviewdfx/hisysevent/interfaces/native/innerkits/hisysevent_manager/include/). > **NOTE** > -> For details about **HiSysEventRecord** in the **OnQuery()** API of **HiSysEventQueryCallback**, see Table 5 in [HiSysEvent Listening](subsys-dfx-hisysevent-listening.md). +> For details about **HiSysEventRecord** in the **OnQuery()** API of **HiSysEventQueryCallback**, see Table 4 in [HiSysEvent Listening](subsys-dfx-hisysevent-listening.md). - **Table 1** Description of the HiSysEvent query API + **Table 1** Description of the C++ HiSysEvent query API -| API| Description| +| Name| Description| | -------- | -------- | -| int32_t Query(struct QueryArg& arg,
std::vector<QueryRule>& rules,
std::shared_ptr<HiSysEventQueryCallback> callback) | Queries system events by search criteria such as the time segment, event domain, and event name.
Input arguments:
- **arg**: event query parameter.
- **rules**: rules for event filtering.
- **callback**: callback object for event query.
Return value:
- **0**: Query is successful.
- A negative value: Query has failed.| +| int32_t Query(struct QueryArg& arg,
std::vector<QueryRule>& rules,
std::shared_ptr<HiSysEventQueryCallback> callback) | Queries system events by search criteria such as the time segment, event domain, and event name.
Input arguments:
- **arg**: event query parameter.
- **rules**: event filtering rules.
- **callback**: callback object for event query.
Return value:
- **0**: Query is successful.
- A negative value: Query has failed.| **Table 2** Description of QueryArg objects -| Attribute| Type| Description| +| Field| Type| Description| | -------- | -------- | -------- | | beginTime | long long | Start time for query. The value is a Unix timestamp, in milliseconds.| | endTime | long long | End time for query. The value is a Unix timestamp, in milliseconds.| | maxEvents | int | Maximum number of returned events.| - **Table 3** Description of QueryRule objects + **Table 3** Description of EventType enums -| API| Description| +| Event Type| Value| Description| +| ------------ | ---- | ------------------ | +| FAULT | 1 | Fault type. | +| STATISTIC | 2 | Statistical type. | +| SECURITY | 3 | Security type. | +| BEHAVIOR | 4 | User behavior type.| + + **Table 4** RuleType enum values + +| Rule Type| Value| Description| +| ------------ | ---- | ------------------ | +| WHOLE_WORD | 1 | Whole word matching. | +| PREFIX | 2 | Prefix matching. | +| REGULAR | 3 | Regular expression matching. | + + **Table 5** Description of QueryRule objects + +| Name| Description| | -------- | -------- | -| QueryRule(const std::string& domain,
const std::vector<std::string>& eventList) | Constructor used to create a **QueryRule** object.
Input arguments:
- **domain**: domain to which the event of the **QueryRule** object belongs, in the string format. By default, an empty string indicates that the domain is successfully matched.
**eventList**: event name list, in the **std::vector<std::string>** format. By default, an empty string indicates that the event names on the list are successfully matched.| +| QueryRule(const std::string& domain,
const std::vector<std::string>& eventList,
RuleType ruleType,
uint32_t eventType,
const std::string& cond) | Constructor used to create a **QueryRule** object.
Input arguments:
- **domain**: domain to which the event of the **QueryRule** object belongs, in the string format. By default, an empty string indicates that the domain is successfully matched.
**eventList**: event name list, in the **std::vector<std::string>** format. By default, an empty string indicates that the event names on the list are successfully matched.
- **ruleType**: rule type. For details, see Table 4.
- **eventType**: system event type. The value is of the uint32_t type. For details about the system event types, see Table 3. When **eventType** is set to **0**, all types of events are queried.
- **cond**: query criteria. The value is of the string type.| + +The **condition** parameter must be in the specified JSON string format. For example: + + ```json + { + "version":"V1", + "condition":{ + "and":[ + {"param":"type_","op":">","value":0}, + {"param":"uid_","op":"=","value":1201} + ] + } + } + ``` +- The **version** field is mandatory, indicating the supported version of the input condition. Currently, only **V1** is supported. +- The **condition** field is mandatory, indicating the input condition. + - The **and** field is optional, indicating the AND relationship between conditions. + - The **param** field is mandatory, indicating the parameter name for condition matching. The value must be a string. + - The **op** field is mandatory, indicating the parameter comparison operator for condition matching. The value must be a string. Supported comparison operators include the following: =, >, <, >=, and <=. + - The **value** field is mandatory, indicating the parameter value for condition matching. The value must be a string or an integer. - **Table 4** Description of HiSysEventQueryCallback objects -| API| Description| + + + +**Table 6** Description of HiSysEventQueryCallback objects + +| Name| Description| | -------- | -------- | | void HiSysEventQueryCallback::OnQuery(std::shared_ptr<std::vector<HiSysEventRecord>> sysEvents) | Callback object for event query.
Input arguments:
- **sysEvents**: event list.| | void HiSysEventQueryCallback::OnComplete(int32_t reason, int32_t total) | Callback object for completion of event query.
Input arguments:
- **reason**: reason for completion of event query. The value **0** indicates that the query is normal, and any other value indicates that the query has failed.
- **total**: total number of events returned in this query.| -#### C Event Query API +#### C APIs HiSysEvent query is implemented using the API provided in the following table. For details, see the [API Header Files](/base/hiviewdfx/hisysevent/interfaces/native/innerkits/hisysevent_manager/include/). - **Table 5** Description of the HiSysEvent query API + **Table 7** Description of the C HiSysEvent query API -| API | Description | +| Name | Description | | ------------------------------------------------------------ | ------------------------------------------------------------ | -| int OH_HiSysEvent_Query(const HiSysEventQueryArg& arg, HiSysEventQueryRule rules[], size_t ruleSize, HiSysEventQueryCallback& callback); | Queries system events by search criteria such as the time segment, event domain, event name, and event parameter.
Input arguments:
- **arg**: event query parameter.
- **rules**: rules for event filtering.
- **ruleSize**: number of event filtering rules.
- **callback**: callback object for event query.
Return value:
- **0**: Query is successful.
- A negative value: Query has failed.| +| int OH_HiSysEvent_Query(const HiSysEventQueryArg& arg, HiSysEventQueryRule rules[], size_t ruleSize, HiSysEventQueryCallback& callback); | Queries system events by search criteria such as the time segment, event domain, event name, and event parameter.
Input arguments:
- **arg**: event query parameter.
- **rules**: event filtering rules.
- **ruleSize**: number of event filtering rules.
- **callback**: callback object for event query.
Return value:
- **0**: Query is successful.
- A negative value: Query has failed.| - **Table 6** Description of the HiSysEventQueryArg structure + **Table 8** Description of the HiSysEventQueryArg structure -| Attribute | Type| Description | +| Field | Type| Description | | --------- | -------- | ---------------------------------------------------- | | beginTime | int64_t | Start time for query. The value is a Unix timestamp, in milliseconds.| | endTime | int64_t | End time for query. The value is a Unix timestamp, in milliseconds.| | maxEvents | int32_t | Maximum number of returned events. | -**Table 7** Description of the HiSysEventQueryRule structure + **Table 9** Description of the HiSysEventQueryRule structure -| Attribute | Type | Description | +| Field | Type | Description | | ------------- | --------- | ---------------------------------- | | domain | char[] | Event domain. | | eventList | char\[][] | Event name list. | | eventListSize | size_t | Size of the event name list. | | condition | char* | Custom event parameter conditions for the query.| -The **condition** parameter must be in the specified JSON string format. For example: - -```json -{ - "version":"V1", - "condition":{ - "and":[ - {"param":"type_","op":">","value":0}, - {"param":"uid_","op":"=","value":1201} - ] - } -} -``` - -- The **version** field is mandatory, indicating the supported version of the input condition. Currently, only **V1** is supported. -- The **condition** field is mandatory, indicating the input condition. - - The **and** field is optional, indicating the AND relationship between conditions. - - The **param** field is mandatory, indicating the parameter name for condition matching. The value must be a string. - - The **op** field is mandatory, indicating the parameter comparison operator for condition matching. The value must be a string. Supported comparison operators include the following: =, >, <, >=, and <=. - - The **value** field is mandatory, indicating the parameter value for condition matching. The value must be a string or an integer. - -**Table 8** Description of the HiSysEventQueryCallback structure + **Table 10** Description of the HiSysEventQueryCallback structure -| Attribute | Type | Description | +| Field | Type | Description | | ---------- | -------------------------------------------------- | ------------------------------------------------------------ | | OnQuery | void (*)(HiSysEventRecord records[], size_t size); | Callback object for event query.
Input arguments:
- **records**: event list.
- **size**: size of the event list.| | OnComplete | void (*)(int32_t reason, int32_t total); | Callback object for completion of event query.
Input arguments:
- **reason**: reason for completion of event query. The value **0** indicates that the query is normal, and any other value indicates that the query has failed.
- **total**: total number of events returned in this query.| -**Table 9** Description of the HiSysEventRecord event structure + **Table 11** Description of the HiSysEventRecord event structure -| Attribute | Type | Description | +| Field | Type | Description | | --------- | ------------------- | -------------------------- | | domain | char[] | Event domain. | | eventName | char\[] | Event name. | @@ -120,13 +140,13 @@ The **condition** parameter must be in the specified JSON string format. For exa | tag | char* | Event tag. | | jsonStr | char* | Event content. | -**Table 10** Description of HiSysEventRecord APIs + **Table 12** Description of HiSysEventRecord APIs -| API | | +| Name | | | ------------------------------------------------------------ | ------------------------------------------------------------ | | void OH_HiSysEvent_GetParamNames(const HiSysEventRecord& record, char*** params, size_t& len); | Obtains all parameter names of an event.
Input arguments:
- **record**: event structure.
- **params**: parameter name array.
- **len**: size of the parameter name array.| | int OH_HiSysEvent_GetParamInt64Value(const HiSysEventRecord& record, const char* name, int64_t& value); | Parses the parameter value in the event to an int64_t value and assigns the value to **value**.
Input arguments:
- **record**: event structure.
- **name**: parameter name.
- **value**: parameter value of the int64_t type.| -| int OH_HiSysEvent_GetParamUint64Value(const HiSysEventRecord& record, const char* name, uint64_t& value); | Parses the parameter value in the event to an uint64_t value and assigns the value to **value**.
Input arguments:
- **record**: event structure.
- **name**: parameter name.
- **value**: parameter value of the uint64_t type.| +| int OH_HiSysEvent_GetParamUint64Value(const HiSysEventRecord& record, const char* name, uint64_t& value); | Parses the parameter value in the event to a uint64_t value and assigns the value to **value**.
Input arguments:
- **record**: event structure.
- **name**: parameter name.
- **value**: parameter value of the uint64_t type.| | int OH_HiSysEvent_GetParamDoubleValue(const HiSysEventRecord& record, const char* name, double& value); | Parses the parameter value in the event to a double value and assigns the value to **value**.
Input arguments:
- **record**: event structure.
- **name**: parameter name.
- **value**: parameter value of the double type.| | int OH_HiSysEvent_GetParamStringValue(const HiSysEventRecord& record, const char* name, char** value); | Parses the parameter value in the event to a char array value and assigns the value to **value**. You need to release the memory manually after usage.
Input arguments:
- **record**: event structure.
- **name**: parameter name.
- **value**: char\* reference.| | int OH_HiSysEvent_GetParamInt64Values(const HiSysEventRecord& record, const char* name, int64_t** value, size_t& len); | Parses the parameter value in the event to a int64_t array value and assigns the value to **value**. You need to release the memory manually after usage.
Input arguments:
- **record**: event structure.
- **name**: parameter name.
- **value**: int64_t\* reference.
- **len**: array size.| @@ -143,240 +163,226 @@ The return values of the HiSysEventRecord APIs are described as follows: ### How to Develop -#### C++ HiSysEvent Query API - -1. Import the corresponding header file: - - ```c++ - #include "hisysevent_manager.h" - ``` - -2. Implement the callback API. - - ```c++ - class TestQueryCallback : public HiSysEventQueryCallback { - public: - void OnQuery(std::shared_ptr> sysEvents) override - { - if (sysEvents == nullptr) { - return; - } - for_each((*sysEvents).cbegin(), (*sysEvents).cend(), [](const HiSysEventRecord& event) { - std::cout << event.AsJson() << std::endl; - }); - } - - void OnComplete(int32_t reason, int32_t total) override - { - std::cout << "Query completed" << std::endl; - return; - } - }; - ``` - -3. Call the query API while passing in the query parameter, rule, and callback object. - - ```c++ - // Create a query parameter object. - long long startTime = 0; - long long endTime = 1668245644000; //2022-11-12 09:34:04 - int queryCount = 10; - QueryArg arg(startTime, endTime, queryCount); - - // Create a query rule object. - QueryRule rule("HIVIEWDFX", { "PLUGIN_LOAD" }); - std::vector queryRules = { rule }; - - // Create a query callback object. - auto queryCallback = std::make_shared(); - - // Call the query API. - HiSysEventManager::Query(arg, queryRules, queryCallback); - ``` - -#### C HiSysEvent Query API - -1. Import the corresponding header file: - - ```c++ - #include "hisysevent_manager_c.h" - ``` - -2. Implement the callback API. - - ```c++ - void OnQueryTest(HiSysEventRecord records[], size_t size) - { - for (size_t i = 0; i < size; i++) { - printf("OnQuery: event=%s", records[i].jsonStr); - } - } - - void OnCompleteTest(int32_t reason, int32_t total) - { - printf("OnCompleted, res=%d, total=%d\n", reason, total); - } - ``` - -3. Call the query API while passing in the query parameter, rule, and callback object. - - ```c++ - // Create a query parameter object. - HiSysEventQueryArg arg; - arg.beginTime = 0; - arg.endTime = 1668245644000; //2022-11-12 09:34:04 - arg.maxEvents = 10; - - // Create a query rule object. - constexpr char TEST_DOMAIN[] = "HIVIEWDFX"; - constexpr char TEST_NAME[] = "PLUGIN_LOAD"; - HiSysEventQueryRule rule; - (void)strcpy_s(rule.domain, strlen(TEST_DOMAIN) + 1, TEST_DOMAIN); - (void)strcpy_s(rule.eventList[0], strlen(TEST_NAME) + 1, TEST_NAME); - rule.eventListSize = 1; - rule.condition = nullptr; - HiSysEventQueryRule rules[] = { rule }; - - // Create a query callback object. - HiSysEventQueryCallback callback; - callback.OnQuery = OnQueryTest; - callback.OnComplete = OnCompleteTest; - - // Call the query API. - OH_HiSysEvent_Query(arg, rules, sizeof(rules) / sizeof(HiSysEventQueryRule), callback); - ``` - -### Development Example +#### C++ HiSysEvent Query + +1. Import the corresponding header file. + + ```c++ + #include "hisysevent_manager.h" + ``` + +2. Implement the callback API for the service domain. + + ```c++ + class TestQueryCallback : public HiSysEventQueryCallback { + public: + void OnQuery(std::shared_ptr> sysEvents) override + { + if (sysEvents == nullptr) { + return; + } + for_each((*sysEvents).cbegin(), (*sysEvents).cend(), [](const HiSysEventRecord& event) { + std::cout << event.AsJson() << std::endl; + }); + } + + void OnComplete(int32_t reason, int32_t total) override + { + std::cout << "Query completed" << std::endl; + return; + } + }; + ``` + +3. Call the query API while passing in **QueryArg**, **QueryRule**, and **QueryCallback**. + + ```c++ + // Create a QueryArg object. + long long startTime = 0; + long long endTime = 1668245644000; //2022-11-12 09:34:04 + int queryCount = 10; + QueryArg arg(startTime, endTime, queryCount); + + // Create a QueryRule object. + QueryRule rule("HIVIEWDFX", { "PLUGIN_LOAD" }); + std::vector queryRules = { rule }; + + // Create a QueryCallback object. + auto queryCallback = std::make_shared(); + + // Call the query API. + HiSysEventManager::Query(arg, queryRules, queryCallback); + ``` + +#### C HiSysEvent Query + +1. Import the corresponding header file. + + ```c++ + #include "hisysevent_manager_c.h" + ``` + +2. Implement the callback API for the service domain. + + ```c++ + void OnQueryTest(HiSysEventRecord records[], size_t size) + { + for (size_t i = 0; i < size; i++) { + printf("OnQuery: event=%s", records[i].jsonStr); + } + } + + void OnCompleteTest(int32_t reason, int32_t total) + { + printf("OnCompleted, res=%d, total=%d\n", reason, total); + } + ``` + +3. Call the query API while passing in **HiSysEventQueryArg**, **HiSysEventQueryRule**, and **HiSysEventQueryCallback**. + + ```c++ + // Create a HiSysEventQueryArg object. + HiSysEventQueryArg arg; + arg.beginTime = 0; + arg.endTime = 1668245644000; //2022-11-12 09:34:04 + arg.maxEvents = 10; + + // Create a HiSysEventQueryRule object. + constexpr char TEST_DOMAIN[] = "HIVIEWDFX"; + constexpr char TEST_NAME[] = "PLUGIN_LOAD"; + HiSysEventQueryRule rule; + (void)strcpy_s(rule.domain, strlen(TEST_DOMAIN) + 1, TEST_DOMAIN); + (void)strcpy_s(rule.eventList[0], strlen(TEST_NAME) + 1, TEST_NAME); + rule.eventListSize = 1; + rule.condition = nullptr; + HiSysEventQueryRule rules[] = { rule }; + + // Create a HiSysEventQueryCallback object. + HiSysEventQueryCallback callback; + callback.OnQuery = OnQueryTest; + callback.OnComplete = OnCompleteTest; + + // Call the query API. + OH_HiSysEvent_Query(arg, rules, sizeof(rules) / sizeof(HiSysEventQueryRule), callback); + ``` + +### Development Examples #### C++ HiSysEvent Query -Assume that you need to query all **PLUGIN_LOAD** events that are generated for the **HIVIEWDFX** domain until the current time on a service module. The development procedure is as follows: +Suppose you want to query all events generated up to the current time with domain being **HIVIEWDFX** and name being **PLUGIN_LOAD**. The sample code is as follows: -1. Add the **libhisysevent** and **libhisyseventmanager** dependencies of the **hisysevent** component to **BUILD.gn** of the service module. +1. Add the **libhisysevent** and **libhisyseventmanager** dependencies of the **hisysevent** component to the **BUILD.gn** file of the service module. - ```c++ - external_deps = [ - "hisysevent:libhisysevent", - "hisysevent:libhisyseventmanager", - ] - ``` + ```c++ + external_deps = [ + "hisysevent:libhisysevent", + "hisysevent:libhisyseventmanager", + ] + ``` 2. Call the query API in the **TestQuery()** function of the service module. - - ```c++ - #include "hisysevent_manager.h" - #include - #include - - using namespace OHOS::HiviewDFX; - - class TestQueryCallback : public HiSysEventQueryCallback { - public: - void OnQuery(std::shared_ptr> sysEvents) override - { - if (sysEvents == nullptr) { - return; - } - for_each((*sysEvents).cbegin(), (*sysEvents).cend(), [](const HiSysEventRecord& event) { - std::cout << event.AsJson() << std::endl; - }); - } - - void OnComplete(int32_t reason, int32_t total) override - { - std::cout << "Query completed" << std::endl; - return; - } - }; - - int64_t GetMilliseconds() - { - auto now = std::chrono::system_clock::now(); - auto millisecs = std::chrono::duration_cast(now.time_since_epoch()); - return millisecs.count(); - } - - void TestQuery() - { - // Create a query parameter object. - long long startTime = 0; - long long endTime = GetMilliseconds(); - int maxEvents = 100; - QueryArg arg(startTime, endTime, maxEvents); - - // Create a query rule object. - QueryRule rule("HIVIEWDFX", { "PLUGIN_LOAD" }); - std::vector queryRules = { rule }; - - // Create a query callback object. - auto queryCallback = std::make_shared(); - - // Call the query API. - int ret = HiSysEventManager::Query(arg, queryRules, queryCallback); - } - ``` + + ```c++ + #include "hisysevent_manager.h" + #include + #include + + using namespace OHOS::HiviewDFX; + + class TestQueryCallback : public HiSysEventQueryCallback { + public: + void OnQuery(std::shared_ptr> sysEvents) override + { + if (sysEvents == nullptr) { + return; + } + for_each((*sysEvents).cbegin(), (*sysEvents).cend(), [](const HiSysEventRecord& event) { + std::cout << event.AsJson() << std::endl; + }); + } + + void OnComplete(int32_t reason, int32_t total) override + { + std::cout << "Query completed" << std::endl; + return; + } + }; + + int64_t GetMilliseconds() + { + auto now = std::chrono::system_clock::now(); + auto millisecs = std::chrono::duration_cast(now.time_since_epoch()); + return millisecs.count(); + } + + void TestQuery() + { + long long startTime = 0; + long long endTime = GetMilliseconds(); + int maxEvents = 100; + QueryArg arg(startTime, endTime, maxEvents); + QueryRule rule("HIVIEWDFX", { "PLUGIN_LOAD" }); + std::vector queryRules = { rule }; + auto queryCallback = std::make_shared(); + int ret = HiSysEventManager::Query(arg, queryRules, queryCallback); + } + ``` #### C HiSysEvent Query -Assume that you need to query all **PLUGIN_LOAD** events that are generated for the **HIVIEWDFX** domain until the current time on a service module. The development procedure is as follows: +Suppose you want to query all events generated up to the current time with domain being **HIVIEWDFX** and name being **PLUGIN_LOAD**. The sample code is as follows: 1. Add the **libhisyseventmanager** dependency of the **hisysevent** component to the **BUILD.gn** file of the service module. - ```c++ - external_deps = [ "hisysevent:libhisyseventmanager" ] - - // for strcpy_s - deps = [ "//third_party/bounds_checking_function:libsec_shared" ] - ``` +```c++ + external_deps = [ "hisysevent:libhisyseventmanager" ] + + // for strcpy_s + deps = [ "//third_party/bounds_checking_function:libsec_shared" ] +``` 2. Call the query API in the **TestQuery()** function of the service module. - ```c++ - #include "hisysevent_manager_c.h" - #include - #include + ```c++ + #include "hisysevent_manager_c.h" + #include + #include - void OnQueryTest(HiSysEventRecord records[], size_t size) - { - for (size_t i = 0; i < size; i++) { - printf("OnQuery: event=%s", records[i].jsonStr); - } - } - - void OnCompleteTest(int32_t reason, int32_t total) - { - printf("OnCompleted, res=%d, total=%d\n", reason, total); - } - - int64_t GetMilliseconds() - { - return time(NULL); - } - - void TestQuery() - { - // Create a query parameter object. - HiSysEventQueryArg arg; - arg.beginTime = 0; - arg.endTime = GetMilliseconds(); - arg.maxEvents = 100; - - // Create a query rule object. - constexpr char TEST_DOMAIN[] = "HIVIEWDFX"; - constexpr char TEST_NAME[] = "PLUGIN_LOAD"; - HiSysEventQueryRule rule; - (void)strcpy_s(rule.domain, strlen(TEST_DOMAIN) + 1, TEST_DOMAIN); - (void)strcpy_s(rule.eventList[0], strlen(TEST_NAME) + 1, TEST_NAME); - rule.eventListSize = 1; - rule.condition = nullptr; - HiSysEventQueryRule rules[] = { rule }; - - // Create a query callback object. - HiSysEventQueryCallback callback; - callback.OnQuery = OnQueryTest; - callback.OnComplete = OnCompleteTest; - - // Call the query API. - int ret = OH_HiSysEvent_Query(arg, rules, sizeof(rules) / sizeof(HiSysEventQueryRule), callback); - } - ``` + void OnQueryTest(HiSysEventRecord records[], size_t size) + { + for (size_t i = 0; i < size; i++) { + printf("OnQuery: event=%s", records[i].jsonStr); + } + } + + void OnCompleteTest(int32_t reason, int32_t total) + { + printf("OnCompleted, res=%d, total=%d\n", reason, total); + } + + int64_t GetMilliseconds() + { + return time(NULL); + } + + void TestQuery() + { + HiSysEventQueryArg arg; + arg.beginTime = 0; + arg.endTime = GetMilliseconds(); + arg.maxEvents = 100; + constexpr char TEST_DOMAIN[] = "HIVIEWDFX"; + constexpr char TEST_NAME[] = "PLUGIN_LOAD"; + HiSysEventQueryRule rule; + (void)strcpy_s(rule.domain, strlen(TEST_DOMAIN) + 1, TEST_DOMAIN); + (void)strcpy_s(rule.eventList[0], strlen(TEST_NAME) + 1, TEST_NAME); + rule.eventListSize = 1; + rule.condition = nullptr; + HiSysEventQueryRule rules[] = { rule }; + HiSysEventQueryCallback callback; + callback.OnQuery = OnQueryTest; + callback.OnComplete = OnCompleteTest; + int ret = OH_HiSysEvent_Query(arg, rules, sizeof(rules) / sizeof(HiSysEventQueryRule), callback); + } + ``` diff --git a/en/release-notes/changelogs/OpenHarmony_4.0.10.2/changelogs-netstack.md b/en/release-notes/changelogs/OpenHarmony_4.0.10.2/changelogs-netstack.md new file mode 100644 index 0000000000..4f431b9699 --- /dev/null +++ b/en/release-notes/changelogs/OpenHarmony_4.0.10.2/changelogs-netstack.md @@ -0,0 +1,43 @@ +# Network Management Subsystem Changelog + +## request2 API Name Change + +Changed the name of the HTTP streaming request from **request2** to **requestInStream**. The original name **request2** does not clearly express the intent of the API and may cause ambiguity, which does not comply with the OpenHarmony API specifications. + + - + +## dataProgress Event Name Change + +Changed the name of the streaming data receiving event from **dataProgress** to **dataReceiveProgress**. The original name **dataProgress** does not clearly express the meaning of the event, which does not comply with the OpenHarmony API specifications. + + - + +**Change Impact** + +For applications developed based on earlier versions, the corresponding API and event names must be updated. Otherwise, API calls may fail, affecting the service logic. + +**Key API/Component Changes** + +Involved APIs: + + - request2; + - on(type: "dataProgress", callback: Callback<{ receiveSize: number, totalSize: number }>): void; + - off(type: "dataProgress", callback: Callback<{ receiveSize: number, totalSize: number }>): void; + +Before change: + - request2(url: string, callback: AsyncCallback): void; + - request2(url: string, options: HttpRequestOptions, callback: AsyncCallback): void; + - request2(url: string, options?: HttpRequestOptions): Promise; + - on(type: "dataProgress", callback: Callback<{ receiveSize: number, totalSize: number }>): void; + - off(type: 'dataProgress', callback?: Callback<{ receiveSize: number, totalSize: number }>): void; + +After change: + - requestInStream(url: string, callback: AsyncCallback): void; + - requestInStream(url: string, options: HttpRequestOptions, callback: AsyncCallback): void; + - requestInStream(url: string, options?: HttpRequestOptions): Promise; + - on(type: "dataReceiveProgress", callback: Callback<{ receiveSize: number, totalSize: number }>): void; + - off(type: 'dataReceiveProgress', callback?: Callback<{ receiveSize: number, totalSize: number }>): void; + +**Adaptation Guide** + +Replace the API name **request2** and event name **dataProgress** in the original service code with **requestInStream** and **dataReceiveProgress**, respectively. diff --git a/en/release-notes/changelogs/OpenHarmony_4.0.10.3/changelogs-dfx.md b/en/release-notes/changelogs/OpenHarmony_4.0.10.3/changelogs-dfx.md new file mode 100644 index 0000000000..06f477d67e --- /dev/null +++ b/en/release-notes/changelogs/OpenHarmony_4.0.10.3/changelogs-dfx.md @@ -0,0 +1,22 @@ +# DFX Subsystem Changelog + +## cl.hiviewdfx.1 Event Verification Specification Change for the write Method of the HiAppEvent Module + +Extended the event verification specifications for the **write** method of the HiAppEvent module to support predefined events of HUAWEI Analytics. Specific changes are as follows: + + - The event name can start with a dollar sign ($) and can contain uppercase letters, lowercase letters, digits, and underscores (_). Before the change, the event name can contain lowercase letters, digits, and underscores (_). + - The event parameter name can start with a dollar sign ($) and can contain uppercase letters, lowercase letters, digits, and underscores (_). Before the change, the event parameter name can contain lowercase letters, digits, and underscores (_). + +**Change Impact** + +More event definition formats are supported for event logging. + +**Key API/Component Changes** + +Involved APIs: + + - hiAppEvent.write; + +**Adaptation Guide** + +The event verification specifications are downward compatible. No additional adaptation is required. diff --git a/en/release-notes/changelogs/OpenHarmony_4.0.7.2/changelogs-telephoy.md b/en/release-notes/changelogs/OpenHarmony_4.0.7.2/changelogs-telephoy.md new file mode 100644 index 0000000000..91b9d4fa88 --- /dev/null +++ b/en/release-notes/changelogs/OpenHarmony_4.0.7.2/changelogs-telephoy.md @@ -0,0 +1,122 @@ +# Telephony Subsystem Changelog + + + +## cl.telephony.1 VoNRState Enum Value Change of setVoNState + +Changed the **VoNRState** enum values of the **setVoNState** API. The values value of **VONR_STATE_ON** is changed from **0** to **1** and that of **VONR_STATE_OFF** is defined as **0** to keep consistency with boolean values. + +**Change Impact** + +The new **VoNRState** enum values need to be used when **setVoNState** is called. The API function remains unchanged. + +**Key API/Component Changes** + +Before change: + +```js +function setVoNRState(slotId: number, state: VoNRState, callback: AsyncCallback): void; + +/** + * @systemapi Hide this for inner system use. + * @since 10 + */ +export enum VoNRState { + /** Indicates the VoNR switch is on */ + VONR_STATE_ON = 0, +} +``` + +After change: + +```js +function setVoNRState(slotId: number, state: VoNRState, callback: AsyncCallback): void; + +/** + * Indicates the VoNR state. + * + * @enum { number } + * @syscap SystemCapability.Telephony.CallManager + * @systemapi Hide this for inner system use. + * @since 10 + */ +export enum VoNRState { + /** + * Indicates the VoNR switch is off. + * + * @syscap SystemCapability.Telephony.CallManager + * @systemapi Hide this for inner system use. + * @since 10 + */ + VONR_STATE_OFF = 0, + + /** + * Indicates the VoNR switch is on. + * + * @syscap SystemCapability.Telephony.CallManager + * @systemapi Hide this for inner system use. + * @since 10 + */ + VONR_STATE_ON = 1, +} +``` + + +**Adaptation Guide** + +When calling **setVoNState**, use the new **VoNRState** enum values. The sample code is as follows: + + +```js +call.setVoNRState( 0, VONR_STATE_ON, (err) => { + if (err) { + console.log(`callback: err->${JSON.stringify(err)}`); + } + +}); +call.setVoNRState( 0, VONR_STATE_OFF, (err) => { + console.log(`callback: err->${JSON.stringify(err)}`); +}); +``` + + +## cl.telephony.2 Callback Value Change of setVoNState + +Changed the callback value of **setVoNState** from a boolean value to **void**. + +**Change Impact** + +The callback value needs to be set to **void** when **setVoNState** is called. + +**Key API/Component Changes** + +Before change: + +```js +function setVoNRState(slotId: number, state: VoNRState, callback: AsyncCallback): void; +function setVoNRState(slotId: number, state: VoNRState): Promise; + +``` + +After change: + +```js +function setVoNRState(slotId: number, state: VoNRState, callback: AsyncCallback): void; +function setVoNRState(slotId: number, state: VoNRState): Promise; +``` + +**Adaptation Guide** + +Set the callback value to **void** when calling **setVoNState**. The sample code is as follows: + +```js +call.setVoNRState( 0, VONR_STATE_ON, (err) => { + if (err) { + console.log(`callback: err->${JSON.stringify(err)}`); + } + +}); +call.setVoNRState( 0, VONR_STATE_OFF, (err) => { + console.log(`callback: err->${JSON.stringify(err)}`); +}); +``` -- GitLab