Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenHarmony
Docs
提交
702833ca
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看板
未验证
提交
702833ca
编写于
11月 24, 2022
作者:
O
openharmony_ci
提交者:
Gitee
11月 24, 2022
浏览文件
操作
浏览文件
下载
差异文件
!11459 Fix error sample code of ability
Merge pull request !11459 from yuyaozhi/master
上级
9271b2cc
f77cc6f7
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
147 addition
and
133 deletion
+147
-133
zh-cn/application-dev/reference/apis/js-apis-application-abilityManager.md
...-dev/reference/apis/js-apis-application-abilityManager.md
+2
-2
zh-cn/application-dev/reference/apis/js-apis-application-context.md
...ication-dev/reference/apis/js-apis-application-context.md
+44
-39
zh-cn/application-dev/reference/apis/js-apis-particleAbility.md
...application-dev/reference/apis/js-apis-particleAbility.md
+101
-92
未找到文件。
zh-cn/application-dev/reference/apis/js-apis-application-abilityManager.md
浏览文件 @
702833ca
...
...
@@ -43,7 +43,7 @@ updateConfiguration(config: Configuration, callback: AsyncCallback\<void>): void
| 名称 | 类型 | 必填 | 描述 |
| --------- | ---------------------------------------- | ---- | -------------- |
| config |
Configuration
| 是 | 新的配置项。 |
| config |
[
Configuration
](
js-apis-configuration.md
)
| 是 | 新的配置项。 |
| callback | AsyncCallback
\<
void> | 是 | 被指定的回调方法。 |
**示例**
:
...
...
@@ -74,7 +74,7 @@ updateConfiguration(config: Configuration): Promise\<void>
| 名称 | 类型 | 必填 | 描述 |
| --------- | ---------------------------------------- | ---- | -------------- |
| config |
Configuration
| 是 | 新的配置项。 |
| config |
[
Configuration
](
js-apis-configuration.md
)
| 是 | 新的配置项。 |
**返回值:**
...
...
zh-cn/application-dev/reference/apis/js-apis-application-context.md
浏览文件 @
702833ca
...
...
@@ -11,14 +11,15 @@ Context模块提供开发者运行代码的上下文环境的能力,包括查
通过AbilityContext等继承实现。
```
js
import
AbilityContext
from
'
@ohos.application.Ability
'
class
MainAbility
extends
AbilityContext
{
```
js
import
Ability
from
'
@ohos.application.Ability
'
class
MainAbility
extends
Ability
{
onWindowStageCreate
(
windowStage
)
{
let
test
=
"
com.example.test
"
;
let
context
=
this
.
context
.
createBundleContext
(
test
);
let
test
=
"
com.example.test
"
;
let
context
=
this
.
context
.
createBundleContext
(
test
);
}
}
}
```
## 属性
...
...
@@ -65,16 +66,16 @@ createBundleContext(bundleName: string): Context;
**示例:**
```
js
import
AbilityContext
from
'
@ohos.application.Ability
'
class
MainAbility
extends
AbilityContext
{
onWindowStageCreate
(
windowStage
)
{
let
test
=
"
com.example.test
"
;
let
context
=
this
.
context
.
createBundleContext
(
test
);
}
}
```
js
import
Ability
from
'
@ohos.application.Ability
'
```
class
MainAbility
extends
Ability
{
onWindowStageCreate
(
windowStage
)
{
let
test
=
"
com.example.test
"
;
let
context
=
this
.
context
.
createBundleContext
(
test
);
}
}
```
## Context.createModuleContext
...
...
@@ -99,16 +100,16 @@ createModuleContext(moduleName: string): Context;
**示例:**
```
js
import
AbilityContext
from
'
@ohos.application.Ability
'
class
MainAbility
extends
AbilityContext
{
onWindowStageCreate
(
windowStage
)
{
let
moduleName
=
"
module
"
;
let
context
=
this
.
context
.
createModuleContext
(
moduleName
);
}
}
```
js
import
Ability
from
'
@ohos.application.Ability
'
```
class
MainAbility
extends
Ability
{
onWindowStageCreate
(
windowStage
)
{
let
moduleName
=
"
module
"
;
let
context
=
this
.
context
.
createModuleContext
(
moduleName
);
}
}
```
## Context.createModuleContext
...
...
@@ -136,18 +137,17 @@ createModuleContext(bundleName: string, moduleName: string): Context;
**示例:**
```
js
import
AbilityContext
from
'
@ohos.application.Ability
'
class
MainAbility
extends
AbilityContext
{
onWindowStageCreate
(
windowStage
)
{
let
bundleName
=
"
com.example.bundle
"
;
let
moduleName
=
"
module
"
;
let
context
=
this
.
context
.
createModuleContext
(
bundleName
,
moduleName
);
}
}
```
```
js
import
Ability
from
'
@ohos.application.Ability
'
class
MainAbility
extends
Ability
{
onWindowStageCreate
(
windowStage
)
{
let
bundleName
=
"
com.example.bundle
"
;
let
moduleName
=
"
module
"
;
let
context
=
this
.
context
.
createModuleContext
(
bundleName
,
moduleName
);
}
}
```
## Context.getApplicationContext
...
...
@@ -165,10 +165,15 @@ getApplicationContext(): ApplicationContext;
**示例:**
```
js
// 必选项。
let
applicationContext
=
this
.
context
.
getApplicationContext
();
```
```
js
import
Ability
from
'
@ohos.application.Ability
'
class
MainAbility
extends
Ability
{
onWindowStageCreate
(
windowStage
)
{
let
applicationContext
=
this
.
context
.
getApplicationContext
();
}
}
```
## AreaMode
...
...
zh-cn/application-dev/reference/apis/js-apis-particleAbility.md
浏览文件 @
702833ca
...
...
@@ -38,8 +38,9 @@ startAbility(parameter: StartAbilityParameter, callback: AsyncCallback\<void>):
```
js
import
particleAbility
from
'
@ohos.ability.particleAbility
'
import
wantConstant
from
'
@ohos.ability.wantConstant
'
particleAbility
.
startAbility
(
{
{
want
:
{
action
:
"
action.system.home
"
,
...
...
@@ -49,11 +50,11 @@ particleAbility.startAbility(
deviceId
:
""
,
bundleName
:
"
com.example.Data
"
,
abilityName
:
"
com.example.Data.MainAbility
"
,
uri
:
""
uri
:
""
},
},
(
error
,
result
)
=>
{
console
.
log
(
'
particleAbility startAbility errCode:
'
+
error
+
'
result:
'
+
result
)
console
.
log
(
'
particleAbility startAbility errCode:
'
+
error
+
'
result:
'
+
result
)
},
)
```
...
...
@@ -86,8 +87,9 @@ startAbility(parameter: StartAbilityParameter): Promise\<void>;
```
js
import
particleAbility
from
'
@ohos.ability.particleAbility
'
import
wantConstant
from
'
@ohos.ability.wantConstant
'
particleAbility
.
startAbility
(
{
{
want
:
{
action
:
"
action.system.home
"
,
...
...
@@ -97,7 +99,7 @@ particleAbility.startAbility(
deviceId
:
""
,
bundleName
:
"
com.example.Data
"
,
abilityName
:
"
com.example. Data.MainAbility
"
,
uri
:
""
uri
:
""
},
},
).
then
((
data
)
=>
{
...
...
@@ -105,8 +107,6 @@ particleAbility.startAbility(
});
```
## particleAbility.terminateSelf
terminateSelf(callback: AsyncCallback
\<
void>): void
...
...
@@ -125,15 +125,14 @@ terminateSelf(callback: AsyncCallback\<void>): void
```
js
import
particleAbility
from
'
@ohos.ability.particleAbility
'
particleAbility
.
terminateSelf
(
(
error
,
result
)
=>
{
console
.
log
(
'
particleAbility terminateSelf errCode:
'
+
error
+
'
result:
'
+
result
)
console
.
log
(
'
particleAbility terminateSelf errCode:
'
+
error
+
'
result:
'
+
result
)
}
)
```
## particleAbility.terminateSelf
terminateSelf(): Promise
\<
void>
...
...
@@ -152,6 +151,7 @@ terminateSelf(): Promise\<void>
```
js
import
particleAbility
from
'
@ohos.ability.particleAbility
'
particleAbility
.
terminateSelf
().
then
((
data
)
=>
{
console
.
info
(
"
particleAbility terminateSelf
"
);
});
...
...
@@ -182,7 +182,8 @@ acquireDataAbilityHelper(uri: string): DataAbilityHelper
**示例:**
```
js
import
particleAbility
from
'
@ohos.ability.particleAbility
'
import
particleAbility
from
'
@ohos.ability.particleAbility
'
var
uri
=
""
;
particleAbility
.
acquireDataAbilityHelper
(
uri
)
```
...
...
@@ -375,7 +376,6 @@ particleAbility.cancelBackgroundRunning().then(() => {
```
## particleAbility.connectAbility
connectAbility(request: Want, options:ConnectOptions): number
...
...
@@ -405,37 +405,39 @@ connectAbility(request: Want, options:ConnectOptions): number
**示例**
:
```
js
import
rpc
from
'
@ohos.rpc
'
function
onConnectCallback
(
element
,
remote
){
console
.
log
(
'
ConnectAbility onConnect remote is proxy:
'
+
(
remote
instanceof
rpc
.
RemoteProxy
));
}
function
onDisconnectCallback
(
element
){
console
.
log
(
'
ConnectAbility onDisconnect element.deviceId :
'
+
element
.
deviceId
)
}
function
onFailedCallback
(
code
){
console
.
log
(
'
particleAbilityTest ConnectAbility onFailed errCode :
'
+
code
)
}
var
connectId
=
particleAbility
.
connectAbility
(
{
bundleName
:
"
com.ix.ServiceAbility
"
,
abilityName
:
"
ServiceAbilityA
"
,
},
{
onConnect
:
onConnectCallback
,
onDisconnect
:
onDisconnectCallback
,
onFailed
:
onFailedCallback
,
},
);
particleAbility
.
disconnectAbility
(
connectId
).
then
((
data
)
=>
{
console
.
log
(
"
data:
"
+
data
);
}).
catch
((
error
)
=>
{
console
.
log
(
'
particleAbilityTest result errCode :
'
+
error
.
code
)
});
import
rpc
from
'
@ohos.rpc
'
```
function
onConnectCallback
(
element
,
remote
)
{
console
.
log
(
'
ConnectAbility onConnect remote is proxy:
'
+
(
remote
instanceof
rpc
.
RemoteProxy
));
}
function
onDisconnectCallback
(
element
)
{
console
.
log
(
'
ConnectAbility onDisconnect element.deviceId :
'
+
element
.
deviceId
)
}
function
onFailedCallback
(
code
)
{
console
.
log
(
'
particleAbilityTest ConnectAbility onFailed errCode :
'
+
code
)
}
var
connId
=
particleAbility
.
connectAbility
(
{
bundleName
:
"
com.ix.ServiceAbility
"
,
abilityName
:
"
ServiceAbilityA
"
,
},
{
onConnect
:
onConnectCallback
,
onDisconnect
:
onDisconnectCallback
,
onFailed
:
onFailedCallback
,
},
);
particleAbility
.
disconnectAbility
(
connId
).
then
((
data
)
=>
{
console
.
log
(
"
data:
"
+
data
);
}).
catch
((
error
)
=>
{
console
.
log
(
'
particleAbilityTest result errCode :
'
+
error
.
code
)
});
```
## particleAbility.disconnectAbility
...
...
@@ -455,32 +457,35 @@ disconnectAbility(connection: number, callback:AsyncCallback\<void>): void;
```
js
import
rpc
from
'
@ohos.rpc
'
function
onConnectCallback
(
element
,
remote
){
console
.
log
(
'
ConnectAbility onConnect remote is proxy:
'
+
(
remote
instanceof
rpc
.
RemoteProxy
));
}
function
onDisconnectCallback
(
element
){
console
.
log
(
'
ConnectAbility onDisconnect element.deviceId :
'
+
element
.
deviceId
)
}
function
onFailedCallback
(
code
){
console
.
log
(
'
particleAbilityTest ConnectAbility onFailed errCode :
'
+
code
)
}
var
connectId
=
particleAbility
.
connectAbility
(
{
bundleName
:
"
com.ix.ServiceAbility
"
,
abilityName
:
"
ServiceAbilityA
"
,
},
{
onConnect
:
onConnectCallback
,
onDisconnect
:
onDisconnectCallback
,
onFailed
:
onFailedCallback
,
},
);
var
result
=
particleAbility
.
disconnectAbility
(
connectId
).
then
((
data
)
=>
{
console
.
log
(
"
data:
"
+
data
);
}).
catch
((
error
)
=>
{
console
.
log
(
'
particleAbilityTest result errCode :
'
+
error
.
code
)
});
function
onConnectCallback
(
element
,
remote
)
{
console
.
log
(
'
ConnectAbility onConnect remote is proxy:
'
+
(
remote
instanceof
rpc
.
RemoteProxy
));
}
function
onDisconnectCallback
(
element
)
{
console
.
log
(
'
ConnectAbility onDisconnect element.deviceId :
'
+
element
.
deviceId
)
}
function
onFailedCallback
(
code
)
{
console
.
log
(
'
particleAbilityTest ConnectAbility onFailed errCode :
'
+
code
)
}
var
connId
=
particleAbility
.
connectAbility
(
{
bundleName
:
"
com.ix.ServiceAbility
"
,
abilityName
:
"
ServiceAbilityA
"
,
},
{
onConnect
:
onConnectCallback
,
onDisconnect
:
onDisconnectCallback
,
onFailed
:
onFailedCallback
,
},
);
var
result
=
particleAbility
.
disconnectAbility
(
connId
).
then
((
data
)
=>
{
console
.
log
(
"
data:
"
+
data
);
}).
catch
((
error
)
=>
{
console
.
log
(
'
particleAbilityTest result errCode :
'
+
error
.
code
)
});
```
...
...
@@ -502,32 +507,36 @@ disconnectAbility(connection: number): Promise\<void>;
```
js
import
rpc
from
'
@ohos.rpc
'
function
onConnectCallback
(
element
,
remote
){
console
.
log
(
'
ConnectAbility onConnect remote is proxy:
'
+
(
remote
instanceof
rpc
.
RemoteProxy
));
}
function
onDisconnectCallback
(
element
){
console
.
log
(
'
ConnectAbility onDisconnect element.deviceId :
'
+
element
.
deviceId
)
}
function
onFailedCallback
(
code
){
console
.
log
(
'
particleAbilityTest ConnectAbility onFailed errCode :
'
+
code
)
}
var
connectId
=
particleAbility
.
connectAbility
(
{
bundleName
:
"
com.ix.ServiceAbility
"
,
abilityName
:
"
ServiceAbilityA
"
,
},
{
onConnect
:
onConnectCallback
,
onDisconnect
:
onDisconnectCallback
,
onFailed
:
onFailedCallback
,
},
);
particleAbility
.
disconnectAbility
(
connectId
).
then
((
data
)
=>
{
console
.
log
(
"
data:
"
+
data
);
}).
catch
((
error
)
=>
{
console
.
log
(
'
particleAbilityTest result errCode :
'
+
error
.
code
)
});
function
onConnectCallback
(
element
,
remote
)
{
console
.
log
(
'
ConnectAbility onConnect remote is proxy:
'
+
(
remote
instanceof
rpc
.
RemoteProxy
));
}
function
onDisconnectCallback
(
element
)
{
console
.
log
(
'
ConnectAbility onDisconnect element.deviceId :
'
+
element
.
deviceId
)
}
function
onFailedCallback
(
code
)
{
console
.
log
(
'
particleAbilityTest ConnectAbility onFailed errCode :
'
+
code
)
}
var
connId
=
particleAbility
.
connectAbility
(
{
bundleName
:
"
com.ix.ServiceAbility
"
,
abilityName
:
"
ServiceAbilityA
"
,
},
{
onConnect
:
onConnectCallback
,
onDisconnect
:
onDisconnectCallback
,
onFailed
:
onFailedCallback
,
},
);
particleAbility
.
disconnectAbility
(
connId
).
then
((
data
)
=>
{
console
.
log
(
"
data:
"
+
data
);
}).
catch
((
error
)
=>
{
console
.
log
(
'
particleAbilityTest result errCode :
'
+
error
.
code
)
});
```
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录