Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenHarmony
Docs
提交
d973f3f6
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看板
提交
d973f3f6
编写于
2月 25, 2022
作者:
W
wanchengzhen
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Documentation modification featureability
Signed-off-by:
N
wanchengzhen
<
wanchengzhen@huawei.com
>
上级
bf87c6e6
变更
3
显示空白变更内容
内联
并排
Showing
3 changed file
with
201 addition
and
193 deletion
+201
-193
zh-cn/application-dev/reference/apis/js-apis-Context.md
zh-cn/application-dev/reference/apis/js-apis-Context.md
+28
-18
zh-cn/application-dev/reference/apis/js-apis-featureAbility.md
.../application-dev/reference/apis/js-apis-featureAbility.md
+169
-29
zh-cn/application-dev/reference/apis/js-apis-particleAbility.md
...application-dev/reference/apis/js-apis-particleAbility.md
+4
-146
未找到文件。
zh-cn/application-dev/reference/apis/js-apis-Context.md
浏览文件 @
d973f3f6
...
...
@@ -63,8 +63,8 @@ getOrCreateLocalDir(): Promise\<string>
```
js
import
featureAbility
from
'
@ohos.ability.featureAbility
'
var
context
=
featureAbility
.
getContext
();
context
.
getOrCreateLocalDir
().
then
(()
=>
{
console
.
info
(
"
==========================>getOrCreateLocalDirCallback=======================>
"
);
context
.
getOrCreateLocalDir
().
then
((
data
)
=>
{
console
.
info
(
"
data=
"
+
data
);
});
```
...
...
@@ -146,8 +146,9 @@ verifyPermission(permission: string, options?: PermissionOptions): Promise\<numb
import
featureAbility
from
'
@ohos.ability.featureAbility
'
var
context
=
featureAbility
.
getContext
();
var
Permission
=
context
.
PermissionOptions
(
1
,
1
);
context
.
getOrCreateLocalDir
(
'
com.context.permission
'
,
Permission
).
then
(()
=>
{
console
.
info
(
"
==========================>verifyPermissionCallback=======================>
"
);
context
.
verifyPermission
(
'
com.context.permission
'
,
Permission
).
then
((
data
)
=>
{
console
.
info
(
"
======================>verifyPermissionCallback====================>
"
);
console
.
info
(
"
====>data====>
"
+
JSON
.
stringify
(
data
));
});
```
...
...
@@ -172,13 +173,16 @@ requestPermissionsFromUser(permissions: Array\<string>, requestCode: number, res
```
js
import
featureAbility
from
'
@ohos.ability.featureAbility
'
var
context
=
featureAbility
.
getContext
();
context
.
getOrCreateLocalDir
(
context
.
requestPermissionsFromUser
(
[
"
com.example.permission1
"
,
"
com.example.permission2
"
,
"
com.example.permission3
"
,
"
com.example.permission4
"
,
"
com.example.permission5
"
],
1
,
1
,(
err
,
data
)
=>
{
console
.
info
(
"
====>requestdata====>
"
+
JSON
.
stringify
(
data
));
console
.
info
(
"
====>requesterrcode====>
"
+
JSON
.
stringify
(
err
.
code
));
}
)
```
...
...
@@ -223,8 +227,9 @@ getApplicationInfo(): Promise\<ApplicationInfo>
```
js
import
featureAbility
from
'
@ohos.ability.featureAbility
'
var
context
=
featureAbility
.
getContext
();
context
.
getApplicationInfo
().
then
(()
=>
{
console
.
info
(
"
==========================>getApplicationInfoCallback=======================>
"
);
context
.
getApplicationInfo
().
then
((
data
)
=>
{
console
.
info
(
"
=====================>getApplicationInfoCallback===================>
"
);
console
.
info
(
"
====>data====>
"
+
JSON
.
stringify
(
data
));
});
```
...
...
@@ -269,8 +274,9 @@ getBundleName(): Promise\<string>
```
js
import
featureAbility
from
'
@ohos.ability.featureAbility
'
var
context
=
featureAbility
.
getContext
();
context
.
getBundleName
().
then
(()
=>
{
console
.
info
(
"
==========================>getBundleNameCallback=======================>
"
);
context
.
getBundleName
().
then
((
data
)
=>
{
console
.
info
(
"
=======================>getBundleNameCallback====================>
"
);
console
.
info
(
"
====>data====>
"
+
JSON
.
stringify
(
data
));
});
```
...
...
@@ -315,8 +321,9 @@ getProcessInfo(): Promise\<ProcessInfo>
```
js
import
featureAbility
from
'
@ohos.ability.featureAbility
'
var
context
=
featureAbility
.
getContext
();
context
.
getProcessInfo
().
then
(()
=>
{
console
.
info
(
"
==========================>getProcessInfoCallback=======================>
"
);
context
.
getProcessInfo
().
then
((
data
)
=>
{
console
.
info
(
"
=======================>getProcessInfoCallback====================>
"
);
console
.
info
(
"
====>data====>
"
+
JSON
.
stringify
(
data
));
});
```
...
...
@@ -365,8 +372,9 @@ getElementName(): Promise\<ElementName>
```
js
import
featureAbility
from
'
@ohos.ability.featureAbility
'
var
context
=
featureAbility
.
getContext
();
context
.
getElementName
().
then
(()
=>
{
console
.
info
(
"
==========================>getElementNameCallback=======================>
"
);
context
.
getElementName
().
then
((
data
)
=>
{
console
.
info
(
"
=======================>getElementNameCallback====================>
"
);
console
.
info
(
"
====>data====>
"
+
JSON
.
stringify
(
data
));
});
```
...
...
@@ -407,8 +415,9 @@ getProcessName(): Promise\<string>
```
js
import
featureAbility
from
'
@ohos.ability.featureAbility
'
var
context
=
featureAbility
.
getContext
();
context
.
getProcessName
().
then
(()
=>
{
console
.
info
(
"
==========================>getProcessNameCallback=======================>
"
);
context
.
getProcessName
().
then
((
data
)
=>
{
console
.
info
(
"
=======================>getProcessNameCallback====================>
"
);
console
.
info
(
"
====>data====>
"
+
JSON
.
stringify
(
data
));
});
```
...
...
@@ -453,8 +462,9 @@ getCallingBundle(): Promise\<string>
```
js
import
featureAbility
from
'
@ohos.ability.featureAbility
'
var
context
=
featureAbility
.
getContext
();
context
.
getCallingBundle
().
then
(()
=>
{
console
.
info
(
"
==========================>getCallingBundleCallback=======================>
"
);
context
.
getCallingBundle
().
then
((
data
)
=>
{
console
.
info
(
"
======================>getCallingBundleCallback====================>
"
);
console
.
info
(
"
====>data====>
"
+
JSON
.
stringify
(
data
));
});
```
...
...
zh-cn/application-dev/reference/apis/js-apis-featureAbility.md
浏览文件 @
d973f3f6
...
...
@@ -27,6 +27,7 @@ startAbility(parameter: StartAbilityParameter, callback: AsyncCallback\<number>)
```
javascript
import
featureAbility
from
'
@ohos.ability.featureAbility
'
import
wantConstant
from
'
@ohos.ability.wantConstant
'
featureAbility
.
startAbility
(
{
want
:
...
...
@@ -34,15 +35,14 @@ featureAbility.startAbility(
action
:
""
,
entities
:
[
""
],
type
:
""
,
flags
:
FLAG_AUTH_READ_URI_PERMISSION
,
flags
:
wantConstant
.
Flags
.
FLAG_AUTH_READ_URI_PERMISSION
,
deviceId
:
""
,
bundleName
:
"
com.example.startability
"
,
abilityName
:
"
com.example.startability.MainAbility
"
,
uri
:
""
},
},
);
)
);
```
...
...
@@ -63,6 +63,7 @@ startAbility(parameter: StartAbilityParameter): Promise\<number>
```
javascript
import
featureAbility
from
'
@ohos.ability.featureAbility
'
import
wantConstant
from
'
@ohos.ability.wantConstant
'
featureAbility
.
startAbility
(
{
want
:
...
...
@@ -70,14 +71,14 @@ featureAbility.startAbility(
action
:
"
action.system.home
"
,
entities
:
[
"
entity.system.home
"
],
type
:
"
MIMETYPE
"
,
flags
:
FLAG_AUTH_READ_URI_PERMISSION
,
deviceId
:
deviceId
,
flags
:
wantConstant
.
Flags
.
FLAG_AUTH_READ_URI_PERMISSION
,
deviceId
:
""
,
bundleName
:
"
com.example.startability
"
,
abilityName
:
"
com.example.startability.MainAbility
"
,
uri
:
""
},
}
).
then
((
void
)
=>
{
).
then
((
data
)
=>
{
console
.
info
(
"
==========================>startAbility=======================>
"
);
});
```
...
...
@@ -126,6 +127,7 @@ startAbilityForResult(parameter: StartAbilityParameter, callback: AsyncCallback\
```
javascript
import
featureAbility
from
'
@ohos.ability.featureability
'
;
import
wantConstant
from
'
@ohos.ability.wantConstant
'
featureAbility
.
startAbilityForResult
(
{
want
:
...
...
@@ -133,7 +135,7 @@ featureAbility.startAbilityForResult(
action
:
"
action.system.home
"
,
entities
:
[
"
entity.system.home
"
],
type
:
"
MIMETYPE
"
,
flags
:
FLAG_AUTH_READ_URI_PERMISSION
,
flags
:
wantConstant
.
Flags
.
FLAG_AUTH_READ_URI_PERMISSION
,
deviceId
:
""
,
bundleName
:
"
com.example.featureabilitytest
"
,
abilityName
:
"
com.example.featureabilitytest.MainAbility
"
,
...
...
@@ -164,6 +166,7 @@ startAbilityForResult(parameter: StartAbilityParameter): Promise\<AbilityResult>
```
javascript
import
featureAbility
from
'
@ohos.ability.featureability
'
;
import
wantConstant
from
'
@ohos.ability.wantConstant
'
featureAbility
.
startAbilityForResult
(
{
want
:
...
...
@@ -171,7 +174,7 @@ featureAbility.startAbilityForResult(
action
:
"
action.system.home
"
,
entities
:
[
"
entity.system.home
"
],
type
:
"
MIMETYPE
"
,
flags
:
FLAG_AUTH_READ_URI_PERMISSION
,
flags
:
wantConstant
.
Flags
.
FLAG_AUTH_READ_URI_PERMISSION
,
deviceId
:
""
,
bundleName
:
"
com.example.featureabilitytest
"
,
abilityName
:
"
com.example.featureabilitytest.MainAbility
"
,
...
...
@@ -190,7 +193,7 @@ featureAbility.startAbilityForResult(
},
requestCode
:
2
,
},
).
then
((
void
)
=>
{
).
then
((
data
)
=>
{
console
.
info
(
"
==========================>startAbilityForResult=======================>
"
);
});
```
...
...
@@ -212,6 +215,7 @@ terminateSelfWithResult(parameter: AbilityResult, callback: AsyncCallback\<void>
```
javascript
import
featureAbility
from
'
@ohos.ability.featureAbility
'
import
wantConstant
from
'
@ohos.ability.wantConstant
'
featureAbility
.
terminateSelfWithResult
(
{
resultCode
:
1
,
...
...
@@ -220,7 +224,7 @@ featureAbility.terminateSelfWithResult(
action
:
"
action.system.home
"
,
entities
:
[
"
entity.system.home
"
],
type
:
"
MIMETYPE
"
,
flags
:
FLAG_AUTH_READ_URI_PERMISSION
,
flags
:
wantConstant
.
Flags
.
FLAG_AUTH_READ_URI_PERMISSION
,
deviceId
:
""
,
bundleName
:
"
com.example.featureabilitytest
"
,
abilityName
:
"
com.example.featureabilitytest.MainAbility
"
,
...
...
@@ -261,6 +265,7 @@ terminateSelfWithResult(parameter: AbilityResult): Promise\<void>
```
javascript
import
featureAbility
from
'
@ohos.ability.featureability
'
;
import
wantConstant
from
'
@ohos.ability.wantConstant
'
featureAbility
.
terminateSelfWithResult
(
{
resultCode
:
1
,
...
...
@@ -269,7 +274,7 @@ featureAbility.terminateSelfWithResult(
action
:
"
action.system.home
"
,
entities
:
[
"
entity.system.home
"
],
type
:
"
MIMETYPE
"
,
flags
:
FLAG_AUTH_READ_URI_PERMISSION
,
flags
:
wantConstant
.
Flags
.
FLAG_AUTH_READ_URI_PERMISSION
,
deviceId
:
""
,
bundleName
:
"
com.example.featureabilitytest
"
,
abilityName
:
"
com.example.featureabilitytest.MainAbility
"
,
...
...
@@ -286,7 +291,7 @@ featureAbility.terminateSelfWithResult(
}
},
}
).
then
((
void
)
=>
{
).
then
((
data
)
=>
{
console
.
info
(
"
==========================>terminateSelfWithResult=======================>
"
);
});
```
...
...
@@ -330,7 +335,7 @@ hasWindowFocus(): Promise\<boolean>
```
javascript
import
featureAbility
from
'
@ohos.ability.featureability
'
;
featureAbility
.
hasWindowFocus
().
then
((
void
)
=>
{
featureAbility
.
hasWindowFocus
().
then
((
data
)
=>
{
console
.
info
(
"
==========================>hasWindowFocus=======================>
"
);
});
```
...
...
@@ -373,7 +378,7 @@ getWant(): Promise\<Want>
```
javascript
import
featureAbility
from
'
@ohos.ability.featureability
'
;
featureAbility
.
getWant
().
then
((
void
)
=>
{
featureAbility
.
getWant
().
then
((
data
)
=>
{
console
.
info
(
"
==========================>getWantCallBack=======================>
"
);
});
```
...
...
@@ -435,7 +440,7 @@ terminateSelf(): Promise\<void>
```
javascript
import
featureAbility
from
'
@ohos.ability.featureability
'
;
featureAbility
.
terminateSelf
().
then
((
void
)
=>
{
console
.
info
(
"
==========================>terminateSelfCallBack=======================>
"
);
featureAbility
.
terminateSelf
().
then
((
data
)
=>
{
console
.
info
(
"
==========================>terminateSelfCallBack=======================>
"
);
});
```
...
...
@@ -488,7 +493,7 @@ function onFailedCallback(code){
}
var
connId
=
featureAbility
.
connectAbility
(
{
deviceId
:
deviceId
,
deviceId
:
""
,
bundleName
:
"
com.ix.ServiceAbility
"
,
abilityName
:
"
ServiceAbilityA
"
,
},
...
...
@@ -611,21 +616,156 @@ continueAbility(options: ContinueAbilityOptions, callback: AsyncCallback\<void>)
**示例:**
```
javascript
import
featureAbility
from
'
@ohos.ability.featureAbility
'
import
device
from
'
@system.device
'
import
ability
from
'
@ohos.ability.featureability
'
var
DEVICE_LIST_LOCALHOST
export
default
{
data
:
{
title
:
""
,
deviceId
:
''
,
deviceList
:
[],
remoteDeviceModel
:
new
RemoteDeviceModel
()
},
onInit
()
{
DEVICE_LIST_LOCALHOST
=
{
id
:
'
localhost
'
,
};
this
.
deviceList
=
[
DEVICE_LIST_LOCALHOST
];
},
onShow
()
{
const
core
=
Core
.
getInstance
()
const
expectExtend
=
new
ExpectExtend
({
'
id
'
:
'
extend
'
})
const
reportExtend
=
new
ReportExtend
(
file
)
core
.
addService
(
'
expect
'
,
expectExtend
)
core
.
addService
(
'
report
'
,
reportExtend
)
core
.
init
()
const
configService
=
core
.
getDefaultService
(
'
config
'
)
configService
.
setConfig
(
this
)
core
.
execute
()
},
onReady
()
{
},
GetNetWorkId
(){
let
self
=
this
;
this
.
remoteDeviceModel
.
registerDeviceListCallback
(()
=>
{
var
list
=
[];
list
[
0
]
=
DEVICE_LIST_LOCALHOST
;
var
deviceList
=
self
.
remoteDeviceModel
.
deviceList
;
for
(
var
i
=
0
;
i
<
deviceList
.
length
;
i
++
)
{
list
[
i
]
=
{
id
:
deviceList
[
i
].
deviceId
,
};
}
self
.
deviceList
=
list
;
});
},
ShowNetWorkId
(){
this
.
deviceId
=
this
.
deviceList
[
0
].
id
;
},
async
StartContinueAbility
(
deviceId
)
{
let
continueAbilityOptions
=
{
async
ContinueAbility
(){
function
ContinueAbilityCallback
(
err
)
{
console
.
info
(
"
=============>ContinueAbilityCallback============>
"
);
}
var
continueAbilityOptions
=
{
reversible
:
false
,
deviceId
:
deviceId
,
deviceId
:
this
.
deviceId
,
}
function
ContinueAbilityCallback
(
err
,
data
)
{
console
.
info
(
"
[Demo] ContinueAbilityCallback, result err =
"
+
JSON
.
stringify
(
err
));
console
.
info
(
"
[Demo] ContinueAbilityCallback, result data=
"
+
JSON
.
stringify
(
data
));
//continueAbility callback
await
ability
.
continueAbility
(
continueAbilityOptions
,
ContinueAbilityCallback
);
},
}
```
## featureAbility.continueAbility
continueAbility(options: ContinueAbilityOptions): Promise
\<
void>;
迁移一个ability到目标设备,并返回执行结果(Promise形式)。
**参数:**
| 名称 | 类型 | 必填 | 描述 |
| ------- | ---------------------- | ---- | ------------------- |
| options | ContinueAbilityOptions | 是 | 表示被启动的Ability |
**ContinueAbilityOptions类型说明:**
| 名称 | 读写属性 | 类型 | 必填 | 描述 |
| ---------- | -------- | ------- | ---- | ------------------------------------------------------------ |
| deviceId | 只读 | string | 是 | 表示需要包含有关目标启动能力的信息。 |
| reversible | 只读 | boolean | 是 | 是否支持回迁的标志,目前不支持该功能,为保留字段,可填false。 |
**示例:**
```
javascript
import
device
from
'
@system.device
'
import
ability
from
'
@ohos.ability.featureability
'
var
DEVICE_LIST_LOCALHOST
export
default
{
data
:
{
title
:
""
,
deviceId
:
''
,
deviceList
:
[],
remoteDeviceModel
:
new
RemoteDeviceModel
()
},
onInit
()
{
DEVICE_LIST_LOCALHOST
=
{
id
:
'
localhost
'
,
};
this
.
deviceList
=
[
DEVICE_LIST_LOCALHOST
];
},
onShow
()
{
const
core
=
Core
.
getInstance
()
const
expectExtend
=
new
ExpectExtend
({
'
id
'
:
'
extend
'
})
const
reportExtend
=
new
ReportExtend
(
file
)
core
.
addService
(
'
expect
'
,
expectExtend
)
core
.
addService
(
'
report
'
,
reportExtend
)
core
.
init
()
const
configService
=
core
.
getDefaultService
(
'
config
'
)
configService
.
setConfig
(
this
)
core
.
execute
()
},
onReady
()
{
},
GetNetWorkId
(){
let
self
=
this
;
this
.
remoteDeviceModel
.
registerDeviceListCallback
(()
=>
{
var
list
=
[];
list
[
0
]
=
DEVICE_LIST_LOCALHOST
;
var
deviceList
=
self
.
remoteDeviceModel
.
deviceList
;
for
(
var
i
=
0
;
i
<
deviceList
.
length
;
i
++
)
{
list
[
i
]
=
{
id
:
deviceList
[
i
].
deviceId
,
};
}
await
featureAbility
.
continueAbility
(
continueAbilityOptions
,
ContinueAbilityCallback
);
console
.
info
(
'
[Demo] featureAbility.StartContinueAbility end
'
);
self
.
deviceList
=
list
;
});
},
ShowNetWorkId
(){
this
.
deviceId
=
this
.
deviceList
[
0
].
id
;
},
async
ContinueAbility
(){
function
ContinueAbilityCallback
(
err
)
{
console
.
info
(
"
=============>ContinueAbilityCallback============>
"
);
}
var
continueAbilityOptions
=
{
reversible
:
false
,
deviceId
:
this
.
deviceId
,
}
//continueAbility promise
await
ability
.
continueAbility
(
continueAbilityOptions
).
then
(()
=>
{
console
.
info
(
"
=======>continueAbilityCallback=========>
"
);
});
},
}
this
.
StartContinueAbility
(
remoteDeviceId
);
//remoteDeviceId is acquired from DeviceManager
```
## AbilityResult
...
...
zh-cn/application-dev/reference/apis/js-apis-particleAbility.md
浏览文件 @
d973f3f6
...
...
@@ -28,7 +28,7 @@ startAbility(parameter: StartAbilityParameter, callback: AsyncCallback\<void>: v
```
js
import
particleAbility
from
'
@ohos.ability.particleAbility
'
import
wantConstant
from
"
@ohos.ability.wantConstant
"
import
wantConstant
from
'
@ohos.ability.wantConstant
'
particleAbility
.
startAbility
(
{
want
:
...
...
@@ -71,7 +71,7 @@ startAbility(parameter: StartAbilityParameter): Promise\<number>
```
js
import
particleAbility
from
'
@ohos.ability.particleAbility
'
import
wantConstant
from
"
@ohos.ability.wantConstant
"
import
wantConstant
from
'
@ohos.ability.wantConstant
'
particleAbility
.
startAbility
(
{
want
:
...
...
@@ -86,7 +86,7 @@ particleAbility.startAbility(
uri
:
""
},
},
).
then
(()
=>
{
).
then
((
data
)
=>
{
console
.
info
(
"
particleAbility startAbility
"
);
});
```
...
...
@@ -133,7 +133,7 @@ terminateSelf(): Promise\<void>
```
js
import
particleAbility
from
'
@ohos.ability.particleAbility
'
particleAbility
.
terminateSelf
().
then
(()
=>
{
particleAbility
.
terminateSelf
().
then
((
data
)
=>
{
console
.
info
(
"
particleAbility terminateSelf
"
);
});
```
...
...
@@ -166,148 +166,6 @@ var uri = "";
particleAbility
.
acquireDataAbilityHelper
(
uri
)
```
## particleAbility.connectAbility
connectAbility(request: Want, options:ConnectOptions): number
将当前ability连接到指定ServiceAbility(callback形式)。
**参数:**
| 名称 | 类型 | 必填 | 描述 |
| ------- | -------------- | ---- | -------------------------- |
| request |
[
Want
](
#want
)
| 是 | 表示被连接的ServiceAbility |
| options | ConnectOptions | 是 | 被指定的回调方法 |
**ConnectOptions类型说明:**
| 名称 | 读写属性 | 类型 | 必填 | 描述 |
| ------------ | -------- | -------- | ---- | ---------------------------------- |
| onConnect | 只读 | function | 是 | 连接成功时的回调函数 |
| onDisconnect | 只读 | function | 是 | 断开连接时的回调函数 |
| onFailed | 只读 | function | 是 | ConnectAbility调用失败时的回调函数 |
**返回值:**
| 类型 | 说明 |
| ------ | -------------------------- |
| number | 标识客户端与服务端的连接。 |
**示例:**
```
javascript
import
particleAbility
from
'
@ohos.ability.particleAbility
'
function
onConnectCallback
(
element
,
remote
){
console
.
log
(
'
ConnectAbility onConnectCallback
'
);
}
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
:
"
com.ix.ServiceAbility.ServiceAbilityA
"
,
},
{
onConnect
:
onConnectCallback
,
onDisconnect
:
onDisconnectCallback
,
onFailed
:
onFailedCallback
,
},
);
```
## particleAbility.disconnectAbility
disconnectAbility(connection: number, callback:AsyncCallback
\<
void>): void
断开与指定ServiceAbility的连接(callback形式)。
**参数:**
| 名称 | 类型 | 必填 | 描述 |
| ---------- | ------------- | ---- | ------------------------------ |
| connection | number | 是 | 指定断开连接的ServiceAbilityID |
| callback | AsyncCallback
\<
void> | 是 | 被指定的回调方法 |
**示例:**
```
javascript
import
particleAbility
from
'
@ohos.ability.particleAbility
'
function
onConnectCallback
(
element
,
remote
){
console
.
log
(
'
ConnectAbility onConnectCallback
'
);
}
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
:
"
com.ix.ServiceAbility.ServiceAbilityA
"
,
},
{
onConnect
:
onConnectCallback
,
onDisconnect
:
onDisconnectCallback
,
onFailed
:
onFailedCallback
,
},
);
var
result
=
particleAbility
.
disconnectAbility
(
connId
,
(
error
,
data
)
=>
{
console
.
log
(
'
particleAbilityTest DisConnectAbility result errCode :
'
+
error
.
code
+
"
data:
"
+
data
);
}
);
```
## particleAbility.disconnectAbility
disconnectAbility(connection: number): Promise
\<
void>
断开与指定ServiceAbility的连接(Promise形式)。
**参数:**
| 名称 | 类型 | 必填 | 描述 |
| ---------- | ------ | ---- | ------------------------------ |
| connection | number | 是 | 指定断开连接的ServiceAbilityID |
**返回值:**
| 类型 | 说明 |
| -------------- | ------------------------- |
| Promise
\<
void> | 使用Promise形式返回结果。 |
**示例:**
```
javascript
import
particleAbility
from
'
@ohos.ability.particleAbility
'
function
onConnectCallback
(
element
,
remote
){
console
.
log
(
'
ConnectAbility onConnect onConnectCallback
'
);
}
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
:
"
com.ix.ServiceAbility.ServiceAbilityA
"
,
},
{
onConnect
:
onConnectCallback
,
onDisconnect
:
onDisconnectCallback
,
onFailed
:
onFailedCallback
,
},
);
var
result
=
particleAbility
.
disconnectAbility
(
connId
).
then
(()
=>
{
console
.
info
(
"
particleAbilityTest disconnectAbility
"
);
});
```
## StartAbilityParameter
| 名称 | 读写属性 | 类型 | 必填 | 描述 |
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录