Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenHarmony
Docs
提交
bf9170d5
D
Docs
项目概览
OpenHarmony
/
Docs
1 年多 前同步成功
通知
159
Star
292
Fork
28
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
D
Docs
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
未验证
提交
bf9170d5
编写于
2月 24, 2023
作者:
O
openharmony_ci
提交者:
Gitee
2月 24, 2023
浏览文件
操作
浏览文件
下载
差异文件
!15022 翻译完成:13893 context文档描述修复 (Cherry-Pick到beta5)
Merge pull request !15022 from wusongqing/cherry-pick-1677050772
上级
86706dc7
861cf4bf
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
8 addition
and
57 deletion
+8
-57
en/application-dev/reference/apis/js-apis-inner-application-context.md
...n-dev/reference/apis/js-apis-inner-application-context.md
+8
-57
未找到文件。
en/application-dev/reference/apis/js-apis-inner-application-context.md
浏览文件 @
bf9170d5
...
...
@@ -20,19 +20,18 @@ The **Context** module provides context for abilities or applications. It allows
| filesDir | string | Yes | No | File directory.|
| databaseDir | string | Yes | No | Database 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.|
| 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.|
## Context.createBundleContext
createBundleContext(bundleName: string): Context;
Creates the context based on the bundle name.
**Required permissions**
: ohos.permission.GET_BUNDLE_INFO_PRIVILEGED
**System capability**
: SystemCapability.Ability.AbilityRuntime.Core
**Parameters**
...
...
@@ -47,24 +46,10 @@ Creates the context based on the bundle name.
| -------- | -------- |
| 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**
```
ts
let
bundleContext
;
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
));
}
let
bundleContext
=
this
.
context
.
createBundleContext
(
"
com.example.test
"
);
```
## Context.createModuleContext
...
...
@@ -87,24 +72,10 @@ Creates the context based on the module name.
| -------- | -------- |
| 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**
```
ts
let
moduleContext
;
try
{
moduleContext
=
this
.
context
.
createModuleContext
(
"
entry
"
);
}
catch
(
error
)
{
console
.
log
(
'
createModuleContext failed, error.code:
'
+
JSON
.
stringify
(
error
.
code
)
+
'
error.message:
'
+
JSON
.
stringify
(
error
.
message
));
}
let
moduleContext
=
this
.
context
.
createModuleContext
(
"
entry
"
);
```
createModuleContext(bundleName: string, moduleName: string): Context;
...
...
@@ -126,24 +97,10 @@ Creates the context based on the bundle name and module name.
| -------- | -------- |
| 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**
```
ts
let
moduleContext
;
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
));
}
let
moduleContext
=
this
.
context
.
createModuleContext
(
"
com.example.test
"
,
"
entry
"
);
```
## Context.getApplicationContext
...
...
@@ -158,18 +115,12 @@ Obtains the context of this application.
| Type| Description|
| -------- | -------- |
|
[
ApplicationContext
](
js-apis-inner-application-applicationContext.md
)
| Application context obtained.|
|
Context
| Application context obtained.|
**Example**
```
ts
let
applicationContext
;
try
{
applicationContext
=
this
.
context
.
getApplicationContext
();
}
catch
(
error
)
{
console
.
log
(
'
getApplicationContext failed, error.code:
'
+
JSON
.
stringify
(
error
.
code
)
+
'
error.message:
'
+
JSON
.
stringify
(
error
.
message
));
}
let
applicationContext
=
this
.
context
.
getApplicationContext
();
```
## AreaMode
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录