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

!15022 翻译完成:13893 context文档描述修复 (Cherry-Pick到beta5)

Merge pull request !15022 from wusongqing/cherry-pick-1677050772
...@@ -20,19 +20,18 @@ The **Context** module provides context for abilities or applications. It allows ...@@ -20,19 +20,18 @@ The **Context** module provides context for abilities or applications. It allows
| filesDir | string | Yes | No | File directory.| | filesDir | string | Yes | No | File directory.|
| databaseDir | string | Yes | No | Database directory.| | databaseDir | string | Yes | No | Database directory.|
| preferencesDir | string | Yes | No | Preferences directory.| | preferencesDir | string | Yes | No | Preferences directory.|
| bundleCodeDir | string | Yes | No | Bundle code directory.| | bundleCodeDir | string | Yes | No | Bundle code directory. A resource file cannot be accessed by combining paths. Use [Resource Manager](js-apis-resource-manager.md) to access it. |
| distributedFilesDir | string | Yes | No | Distributed file directory.| | distributedFilesDir | string | Yes | No | Distributed file directory.|
| eventHub | string | Yes | No | Event hub that implements event subscription, unsubscription, and triggering.| | eventHub | [EventHub](js-apis-inner-application-eventHub.md) | Yes | No | Event hub that implements event subscription, unsubscription, and triggering.|
| area | [AreaMode](#areamode) | Yes | No | Area in which the file to be access is located.| | area | [AreaMode](#areamode) | Yes | No | Area in which the file to be access is located.|
## Context.createBundleContext ## Context.createBundleContext
createBundleContext(bundleName: string): Context; createBundleContext(bundleName: string): Context;
Creates the context based on the bundle name. Creates the context based on the bundle name.
**Required permissions**: ohos.permission.GET_BUNDLE_INFO_PRIVILEGED
**System capability**: SystemCapability.Ability.AbilityRuntime.Core **System capability**: SystemCapability.Ability.AbilityRuntime.Core
**Parameters** **Parameters**
...@@ -47,24 +46,10 @@ Creates the context based on the bundle name. ...@@ -47,24 +46,10 @@ Creates the context based on the bundle name.
| -------- | -------- | | -------- | -------- |
| Context | Context created.| | Context | Context created.|
**Error codes**
| ID| Error Message|
| ------- | -------------------------------- |
| 401 | If the input parameter is not valid parameter. |
For details about the error codes, see [Ability Error Codes](../errorcodes/errorcode-ability.md).
**Example** **Example**
```ts ```ts
let bundleContext; let bundleContext = this.context.createBundleContext("com.example.test");
try {
bundleContext = this.context.createBundleContext("com.example.test");
} catch (error) {
console.log('createBundleContext failed, error.code: ' + JSON.stringify(error.code) +
' error.message: ' + JSON.stringify(error.message));
}
``` ```
## Context.createModuleContext ## Context.createModuleContext
...@@ -87,24 +72,10 @@ Creates the context based on the module name. ...@@ -87,24 +72,10 @@ Creates the context based on the module name.
| -------- | -------- | | -------- | -------- |
| Context | Context created.| | Context | Context created.|
**Error codes**
| ID| Error Message|
| ------- | -------------------------------- |
| 401 | If the input parameter is not valid parameter. |
For details about the error codes, see [Ability Error Codes](../errorcodes/errorcode-ability.md).
**Example** **Example**
```ts ```ts
let moduleContext; let moduleContext = this.context.createModuleContext("entry");
try {
moduleContext = this.context.createModuleContext("entry");
} catch (error) {
console.log('createModuleContext failed, error.code: ' + JSON.stringify(error.code) +
' error.message: ' + JSON.stringify(error.message));
}
``` ```
createModuleContext(bundleName: string, moduleName: string): Context; createModuleContext(bundleName: string, moduleName: string): Context;
...@@ -126,24 +97,10 @@ Creates the context based on the bundle name and module name. ...@@ -126,24 +97,10 @@ Creates the context based on the bundle name and module name.
| -------- | -------- | | -------- | -------- |
| Context | Context created.| | Context | Context created.|
**Error codes**
| ID| Error Message|
| ------- | -------------------------------- |
| 401 | If the input parameter is not valid parameter. |
For details about the error codes, see [Ability Error Codes](../errorcodes/errorcode-ability.md).
**Example** **Example**
```ts ```ts
let moduleContext; let moduleContext = this.context.createModuleContext("com.example.test", "entry");
try {
moduleContext = this.context.createModuleContext("com.example.test", "entry");
} catch (error) {
console.log('createModuleContext failed, error.code: ' + JSON.stringify(error.code) +
' error.message: ' + JSON.stringify(error.message));
}
``` ```
## Context.getApplicationContext ## Context.getApplicationContext
...@@ -158,18 +115,12 @@ Obtains the context of this application. ...@@ -158,18 +115,12 @@ Obtains the context of this application.
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| [ApplicationContext](js-apis-inner-application-applicationContext.md) | Application context obtained.| | Context | Application context obtained.|
**Example** **Example**
```ts ```ts
let applicationContext; let applicationContext = this.context.getApplicationContext();
try {
applicationContext = this.context.getApplicationContext();
} catch (error) {
console.log('getApplicationContext failed, error.code: ' + JSON.stringify(error.code) +
' error.message: ' + JSON.stringify(error.message));
}
``` ```
## AreaMode ## AreaMode
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册