| registerErrorObserver(observer: ErrorObserver): number | Registers an observer for application errors. A callback will be invoked when an application error is detected. This API works in a synchronous manner. The return value is the SN of the registered observer.|
| on(type: "error", observer: ErrorObserver): number | Registers an observer for application errors. A callback will be invoked when an application error is detected. This API works in a synchronous manner. The return value is the SN of the registered observer.|
| unregisterErrorObserver(observerId: number, callback: AsyncCallback\<void\>): void | Unregisters an observer in callback mode. The number passed to this API is the SN of the registered observer. |
| off(type: "error", observerId: number, callback: AsyncCallback\<void\>): void | Unregisters an observer in callback mode. The number passed to this API is the SN of the registered observer. |
| unregisterErrorObserver(observerId: number): Promise\<void\> | Unregisters an observer in promise mode. The number passed to this API is the SN of the registered observer. |
| off(type: "error", observerId: number): Promise\<void\> | Unregisters an observer in promise mode. The number passed to this API is the SN of the registered observer. |
When an asynchronous callback is used, the return value can be processed directly in the callback. If a promise is used, the return value can also be processed in the promise in a similar way. For details about the result codes, see [Result Codes for Unregistering an Observer](#result-codes-for-unregistering-an-observer).
When an asynchronous callback is used, the return value can be processed directly in the callback. If a promise is used, the return value can also be processed in the promise in a similar way. For details about the result codes, see [Result Codes for Unregistering an Observer](#resultcodes-for-unregistering-an-observer).
@@ -13,14 +13,15 @@ The Resource Manager module provides APIs to obtain information about applicatio
...
@@ -13,14 +13,15 @@ The Resource Manager module provides APIs to obtain information about applicatio
importresourceManagerfrom'@ohos.resourceManager';
importresourceManagerfrom'@ohos.resourceManager';
```
```
## Instruction
## How to Use
Since API version 9, the stage model allows an application to obtain a **ResourceManager** object based on **context** and call its resource management APIs without first importing the required bundle. This approach, however, is not applicable to the FA model.
Since API version 9, the stage model allows an application to obtain a **ResourceManager** object based on **context** and call its resource management APIs without first importing the required bundle. This approach, however, is not applicable to the FA model. For the FA model, you need to import the required bundle and then call the [getResourceManager](#resourcemanagergetresourcemanager) API to obtain a **ResourceManager** object.
For details about how to reference **context** in the stage model, see [Context in the Stage Model](../../application-models/application-context-stage.md).
For details about how to reference context in the stage model, see [Context in the Stage Model](../../application-models/application-context-stage.md).
```ts
```ts
importAbilityfrom'@ohos.application.Ability';
importUIAbilityfrom'@ohos.app.ability.UIAbility';
classMainAbilityextendsAbility{
exportdefaultclassEntryAbilityextendsUIAbility{
onWindowStageCreate(windowStage){
onWindowStageCreate(windowStage){
letcontext=this.context;
letcontext=this.context;
letresourceManager=context.resourceManager;
letresourceManager=context.resourceManager;
...
@@ -60,6 +61,7 @@ Obtains the **ResourceManager** object of this application. This API uses an asy
...
@@ -60,6 +61,7 @@ Obtains the **ResourceManager** object of this application. This API uses an asy
});
});
});
});
```
```
> **NOTE**<br>In the sample code, **0x1000000** indicates the resource ID, which can be found in the compiled **ResourceTable.txt** file.
## resourceManager.getResourceManager
## resourceManager.getResourceManager
...
@@ -76,7 +78,7 @@ Obtains the **ResourceManager** object of an application based on the specified
...
@@ -76,7 +78,7 @@ Obtains the **ResourceManager** object of an application based on the specified
| bundleName | string | Yes | Bundle name of the application. |
| bundleName | string | Yes | Bundle name of the target application. |
| callback | AsyncCallback<[ResourceManager](#resourcemanager)> | Yes | Callback used to return the result.|
| callback | AsyncCallback<[ResourceManager](#resourcemanager)> | Yes | Callback used to return the result.|
**Example**
**Example**
...
@@ -116,6 +118,7 @@ Obtains the **ResourceManager** object of this application. This API uses a prom
...
@@ -116,6 +118,7 @@ Obtains the **ResourceManager** object of this application. This API uses a prom
console.log("error is "+error);
console.log("error is "+error);
});
});
```
```
> **NOTE**<br>> In the sample code, **0x1000000** indicates the resource ID, which can be found in the compiled **ResourceTable.txt** file.
## resourceManager.getResourceManager
## resourceManager.getResourceManager
...
@@ -132,7 +135,7 @@ Obtains the **ResourceManager** object of an application based on the specified
...
@@ -132,7 +135,7 @@ Obtains the **ResourceManager** object of an application based on the specified
| Name | Type | Mandatory | Description |
| Name | Type | Mandatory | Description |
| ---------- | ------ | ---- | ------------- |
| ---------- | ------ | ---- | ------------- |
| bundleName | string | Yes | Bundle name of the application.|
| bundleName | string | Yes | Bundle name of the target application.|
**Return value**
**Return value**
...
@@ -168,12 +171,12 @@ Enumerates the device types.
...
@@ -168,12 +171,12 @@ Enumerates the device types.
| Name | Value | Description |
| Name | Value | Description |
| -------------------- | ---- | ---- |
| -------------------- | ---- | ---- |
| DEVICE_TYPE_PHONE | 0x00 | Phone |
| DEVICE_TYPE_PHONE | 0x00 | Phone. |
| DEVICE_TYPE_TABLET | 0x01 | Tablet |
| DEVICE_TYPE_TABLET | 0x01 | Tablet. |
| DEVICE_TYPE_CAR | 0x02 | Head unit |
| DEVICE_TYPE_CAR | 0x02 | Head unit. |
| DEVICE_TYPE_PC | 0x03 | PC |
| DEVICE_TYPE_PC | 0x03 | PC. |
| DEVICE_TYPE_TV | 0x04 | TV |
| DEVICE_TYPE_TV | 0x04 | TV. |
| DEVICE_TYPE_WEARABLE | 0x06 | Wearable |
| DEVICE_TYPE_WEARABLE | 0x06 | Wearable. |
## ScreenDensity
## ScreenDensity
...
@@ -275,7 +278,7 @@ Defines the capability of accessing application resources.
...
@@ -275,7 +278,7 @@ Defines the capability of accessing application resources.
> **NOTE**
> **NOTE**
>
>
> - The APIs involved in **ResourceManager** are applicable only to the TypeScript-based declarative development paradigm.
> - The methods involved in **ResourceManager** are applicable only to the TypeScript-based declarative development paradigm.
>
>
> - 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**.
> - 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**.
...
@@ -642,7 +645,7 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco
...
@@ -642,7 +645,7 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco