提交 d973f3f6 编写于 作者: W wanchengzhen

Documentation modification featureability

Signed-off-by: Nwanchengzhen <wanchengzhen@huawei.com>
上级 bf87c6e6
...@@ -63,8 +63,8 @@ getOrCreateLocalDir(): Promise\<string> ...@@ -63,8 +63,8 @@ getOrCreateLocalDir(): Promise\<string>
```js ```js
import featureAbility from '@ohos.ability.featureAbility' import featureAbility from '@ohos.ability.featureAbility'
var context = featureAbility.getContext(); var context = featureAbility.getContext();
context.getOrCreateLocalDir().then(() => { context.getOrCreateLocalDir().then((data) => {
console.info("==========================>getOrCreateLocalDirCallback=======================>"); console.info("data=" + data);
}); });
``` ```
...@@ -146,8 +146,9 @@ verifyPermission(permission: string, options?: PermissionOptions): Promise\<numb ...@@ -146,8 +146,9 @@ verifyPermission(permission: string, options?: PermissionOptions): Promise\<numb
import featureAbility from '@ohos.ability.featureAbility' import featureAbility from '@ohos.ability.featureAbility'
var context = featureAbility.getContext(); var context = featureAbility.getContext();
var Permission = context.PermissionOptions(1,1); var Permission = context.PermissionOptions(1,1);
context.getOrCreateLocalDir('com.context.permission',Permission).then(() => { context.verifyPermission('com.context.permission',Permission).then((data) => {
console.info("==========================>verifyPermissionCallback=======================>"); console.info("======================>verifyPermissionCallback====================>");
console.info("====>data====>" + JSON.stringify(data));
}); });
``` ```
...@@ -172,13 +173,16 @@ requestPermissionsFromUser(permissions: Array\<string>, requestCode: number, res ...@@ -172,13 +173,16 @@ requestPermissionsFromUser(permissions: Array\<string>, requestCode: number, res
```js ```js
import featureAbility from '@ohos.ability.featureAbility' import featureAbility from '@ohos.ability.featureAbility'
var context = featureAbility.getContext(); var context = featureAbility.getContext();
context.getOrCreateLocalDir( context.requestPermissionsFromUser(
["com.example.permission1", ["com.example.permission1",
"com.example.permission2", "com.example.permission2",
"com.example.permission3", "com.example.permission3",
"com.example.permission4", "com.example.permission4",
"com.example.permission5"], "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> ...@@ -223,8 +227,9 @@ getApplicationInfo(): Promise\<ApplicationInfo>
```js ```js
import featureAbility from '@ohos.ability.featureAbility' import featureAbility from '@ohos.ability.featureAbility'
var context = featureAbility.getContext(); var context = featureAbility.getContext();
context.getApplicationInfo().then(() => { context.getApplicationInfo().then((data) => {
console.info("==========================>getApplicationInfoCallback=======================>"); console.info("=====================>getApplicationInfoCallback===================>");
console.info("====>data====>" + JSON.stringify(data));
}); });
``` ```
...@@ -269,8 +274,9 @@ getBundleName(): Promise\<string> ...@@ -269,8 +274,9 @@ getBundleName(): Promise\<string>
```js ```js
import featureAbility from '@ohos.ability.featureAbility' import featureAbility from '@ohos.ability.featureAbility'
var context = featureAbility.getContext(); var context = featureAbility.getContext();
context.getBundleName().then(() => { context.getBundleName().then((data) => {
console.info("==========================>getBundleNameCallback=======================>"); console.info("=======================>getBundleNameCallback====================>");
console.info("====>data====>" + JSON.stringify(data));
}); });
``` ```
...@@ -315,8 +321,9 @@ getProcessInfo(): Promise\<ProcessInfo> ...@@ -315,8 +321,9 @@ getProcessInfo(): Promise\<ProcessInfo>
```js ```js
import featureAbility from '@ohos.ability.featureAbility' import featureAbility from '@ohos.ability.featureAbility'
var context = featureAbility.getContext(); var context = featureAbility.getContext();
context.getProcessInfo().then(() => { context.getProcessInfo().then((data) => {
console.info("==========================>getProcessInfoCallback=======================>"); console.info("=======================>getProcessInfoCallback====================>");
console.info("====>data====>" + JSON.stringify(data));
}); });
``` ```
...@@ -365,8 +372,9 @@ getElementName(): Promise\<ElementName> ...@@ -365,8 +372,9 @@ getElementName(): Promise\<ElementName>
```js ```js
import featureAbility from '@ohos.ability.featureAbility' import featureAbility from '@ohos.ability.featureAbility'
var context = featureAbility.getContext(); var context = featureAbility.getContext();
context.getElementName().then(() => { context.getElementName().then((data) => {
console.info("==========================>getElementNameCallback=======================>"); console.info("=======================>getElementNameCallback====================>");
console.info("====>data====>" + JSON.stringify(data));
}); });
``` ```
...@@ -407,8 +415,9 @@ getProcessName(): Promise\<string> ...@@ -407,8 +415,9 @@ getProcessName(): Promise\<string>
```js ```js
import featureAbility from '@ohos.ability.featureAbility' import featureAbility from '@ohos.ability.featureAbility'
var context = featureAbility.getContext(); var context = featureAbility.getContext();
context.getProcessName().then(() => { context.getProcessName().then((data) => {
console.info("==========================>getProcessNameCallback=======================>"); console.info("=======================>getProcessNameCallback====================>");
console.info("====>data====>" + JSON.stringify(data));
}); });
``` ```
...@@ -453,8 +462,9 @@ getCallingBundle(): Promise\<string> ...@@ -453,8 +462,9 @@ getCallingBundle(): Promise\<string>
```js ```js
import featureAbility from '@ohos.ability.featureAbility' import featureAbility from '@ohos.ability.featureAbility'
var context = featureAbility.getContext(); var context = featureAbility.getContext();
context.getCallingBundle().then(() => { context.getCallingBundle().then((data) => {
console.info("==========================>getCallingBundleCallback=======================>"); console.info("======================>getCallingBundleCallback====================>");
console.info("====>data====>" + JSON.stringify(data));
}); });
``` ```
......
...@@ -27,6 +27,7 @@ startAbility(parameter: StartAbilityParameter, callback: AsyncCallback\<number>) ...@@ -27,6 +27,7 @@ startAbility(parameter: StartAbilityParameter, callback: AsyncCallback\<number>)
```javascript ```javascript
import featureAbility from '@ohos.ability.featureAbility' import featureAbility from '@ohos.ability.featureAbility'
import wantConstant from '@ohos.ability.wantConstant'
featureAbility.startAbility( featureAbility.startAbility(
{ {
want: want:
...@@ -34,15 +35,14 @@ featureAbility.startAbility( ...@@ -34,15 +35,14 @@ featureAbility.startAbility(
action: "", action: "",
entities: [""], entities: [""],
type: "", type: "",
flags: FLAG_AUTH_READ_URI_PERMISSION, flags: wantConstant.Flags.FLAG_AUTH_READ_URI_PERMISSION,
deviceId: "", deviceId: "",
bundleName: "com.example.startability", bundleName: "com.example.startability",
abilityName: "com.example.startability.MainAbility", abilityName: "com.example.startability.MainAbility",
uri: "" uri: ""
}, },
}, },
); );
)
``` ```
...@@ -63,6 +63,7 @@ startAbility(parameter: StartAbilityParameter): Promise\<number> ...@@ -63,6 +63,7 @@ startAbility(parameter: StartAbilityParameter): Promise\<number>
```javascript ```javascript
import featureAbility from '@ohos.ability.featureAbility' import featureAbility from '@ohos.ability.featureAbility'
import wantConstant from '@ohos.ability.wantConstant'
featureAbility.startAbility( featureAbility.startAbility(
{ {
want: want:
...@@ -70,14 +71,14 @@ featureAbility.startAbility( ...@@ -70,14 +71,14 @@ featureAbility.startAbility(
action: "action.system.home", action: "action.system.home",
entities: ["entity.system.home"], entities: ["entity.system.home"],
type: "MIMETYPE", type: "MIMETYPE",
flags: FLAG_AUTH_READ_URI_PERMISSION, flags: wantConstant.Flags.FLAG_AUTH_READ_URI_PERMISSION,
deviceId: deviceId, deviceId: "",
bundleName: "com.example.startability", bundleName: "com.example.startability",
abilityName: "com.example.startability.MainAbility", abilityName: "com.example.startability.MainAbility",
uri: "" uri: ""
}, },
} }
).then((void) => { ).then((data) => {
console.info("==========================>startAbility=======================>"); console.info("==========================>startAbility=======================>");
}); });
``` ```
...@@ -126,6 +127,7 @@ startAbilityForResult(parameter: StartAbilityParameter, callback: AsyncCallback\ ...@@ -126,6 +127,7 @@ startAbilityForResult(parameter: StartAbilityParameter, callback: AsyncCallback\
```javascript ```javascript
import featureAbility from '@ohos.ability.featureability'; import featureAbility from '@ohos.ability.featureability';
import wantConstant from '@ohos.ability.wantConstant'
featureAbility.startAbilityForResult( featureAbility.startAbilityForResult(
{ {
want: want:
...@@ -133,7 +135,7 @@ featureAbility.startAbilityForResult( ...@@ -133,7 +135,7 @@ featureAbility.startAbilityForResult(
action: "action.system.home", action: "action.system.home",
entities: ["entity.system.home"], entities: ["entity.system.home"],
type: "MIMETYPE", type: "MIMETYPE",
flags: FLAG_AUTH_READ_URI_PERMISSION, flags: wantConstant.Flags.FLAG_AUTH_READ_URI_PERMISSION,
deviceId: "", deviceId: "",
bundleName: "com.example.featureabilitytest", bundleName: "com.example.featureabilitytest",
abilityName: "com.example.featureabilitytest.MainAbility", abilityName: "com.example.featureabilitytest.MainAbility",
...@@ -164,6 +166,7 @@ startAbilityForResult(parameter: StartAbilityParameter): Promise\<AbilityResult> ...@@ -164,6 +166,7 @@ startAbilityForResult(parameter: StartAbilityParameter): Promise\<AbilityResult>
```javascript ```javascript
import featureAbility from '@ohos.ability.featureability'; import featureAbility from '@ohos.ability.featureability';
import wantConstant from '@ohos.ability.wantConstant'
featureAbility.startAbilityForResult( featureAbility.startAbilityForResult(
{ {
want: want:
...@@ -171,7 +174,7 @@ featureAbility.startAbilityForResult( ...@@ -171,7 +174,7 @@ featureAbility.startAbilityForResult(
action: "action.system.home", action: "action.system.home",
entities: ["entity.system.home"], entities: ["entity.system.home"],
type: "MIMETYPE", type: "MIMETYPE",
flags: FLAG_AUTH_READ_URI_PERMISSION, flags: wantConstant.Flags.FLAG_AUTH_READ_URI_PERMISSION,
deviceId: "", deviceId: "",
bundleName: "com.example.featureabilitytest", bundleName: "com.example.featureabilitytest",
abilityName: "com.example.featureabilitytest.MainAbility", abilityName: "com.example.featureabilitytest.MainAbility",
...@@ -190,7 +193,7 @@ featureAbility.startAbilityForResult( ...@@ -190,7 +193,7 @@ featureAbility.startAbilityForResult(
}, },
requestCode: 2, requestCode: 2,
}, },
).then((void) => { ).then((data) => {
console.info("==========================>startAbilityForResult=======================>"); console.info("==========================>startAbilityForResult=======================>");
}); });
``` ```
...@@ -212,6 +215,7 @@ terminateSelfWithResult(parameter: AbilityResult, callback: AsyncCallback\<void> ...@@ -212,6 +215,7 @@ terminateSelfWithResult(parameter: AbilityResult, callback: AsyncCallback\<void>
```javascript ```javascript
import featureAbility from '@ohos.ability.featureAbility' import featureAbility from '@ohos.ability.featureAbility'
import wantConstant from '@ohos.ability.wantConstant'
featureAbility.terminateSelfWithResult( featureAbility.terminateSelfWithResult(
{ {
resultCode: 1, resultCode: 1,
...@@ -220,7 +224,7 @@ featureAbility.terminateSelfWithResult( ...@@ -220,7 +224,7 @@ featureAbility.terminateSelfWithResult(
action: "action.system.home", action: "action.system.home",
entities: ["entity.system.home"], entities: ["entity.system.home"],
type: "MIMETYPE", type: "MIMETYPE",
flags: FLAG_AUTH_READ_URI_PERMISSION, flags: wantConstant.Flags.FLAG_AUTH_READ_URI_PERMISSION,
deviceId: "", deviceId: "",
bundleName: "com.example.featureabilitytest", bundleName: "com.example.featureabilitytest",
abilityName: "com.example.featureabilitytest.MainAbility", abilityName: "com.example.featureabilitytest.MainAbility",
...@@ -261,6 +265,7 @@ terminateSelfWithResult(parameter: AbilityResult): Promise\<void> ...@@ -261,6 +265,7 @@ terminateSelfWithResult(parameter: AbilityResult): Promise\<void>
```javascript ```javascript
import featureAbility from '@ohos.ability.featureability'; import featureAbility from '@ohos.ability.featureability';
import wantConstant from '@ohos.ability.wantConstant'
featureAbility.terminateSelfWithResult( featureAbility.terminateSelfWithResult(
{ {
resultCode: 1, resultCode: 1,
...@@ -269,7 +274,7 @@ featureAbility.terminateSelfWithResult( ...@@ -269,7 +274,7 @@ featureAbility.terminateSelfWithResult(
action: "action.system.home", action: "action.system.home",
entities: ["entity.system.home"], entities: ["entity.system.home"],
type: "MIMETYPE", type: "MIMETYPE",
flags: FLAG_AUTH_READ_URI_PERMISSION, flags: wantConstant.Flags.FLAG_AUTH_READ_URI_PERMISSION,
deviceId: "", deviceId: "",
bundleName: "com.example.featureabilitytest", bundleName: "com.example.featureabilitytest",
abilityName: "com.example.featureabilitytest.MainAbility", abilityName: "com.example.featureabilitytest.MainAbility",
...@@ -286,7 +291,7 @@ featureAbility.terminateSelfWithResult( ...@@ -286,7 +291,7 @@ featureAbility.terminateSelfWithResult(
} }
}, },
} }
).then((void) => { ).then((data) => {
console.info("==========================>terminateSelfWithResult=======================>"); console.info("==========================>terminateSelfWithResult=======================>");
}); });
``` ```
...@@ -330,7 +335,7 @@ hasWindowFocus(): Promise\<boolean> ...@@ -330,7 +335,7 @@ hasWindowFocus(): Promise\<boolean>
```javascript ```javascript
import featureAbility from '@ohos.ability.featureability'; import featureAbility from '@ohos.ability.featureability';
featureAbility.hasWindowFocus().then((void) => { featureAbility.hasWindowFocus().then((data) => {
console.info("==========================>hasWindowFocus=======================>"); console.info("==========================>hasWindowFocus=======================>");
}); });
``` ```
...@@ -373,7 +378,7 @@ getWant(): Promise\<Want> ...@@ -373,7 +378,7 @@ getWant(): Promise\<Want>
```javascript ```javascript
import featureAbility from '@ohos.ability.featureability'; import featureAbility from '@ohos.ability.featureability';
featureAbility.getWant().then((void) => { featureAbility.getWant().then((data) => {
console.info("==========================>getWantCallBack=======================>"); console.info("==========================>getWantCallBack=======================>");
}); });
``` ```
...@@ -435,7 +440,7 @@ terminateSelf(): Promise\<void> ...@@ -435,7 +440,7 @@ terminateSelf(): Promise\<void>
```javascript ```javascript
import featureAbility from '@ohos.ability.featureability'; 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){ ...@@ -488,7 +493,7 @@ function onFailedCallback(code){
} }
var connId = featureAbility.connectAbility( var connId = featureAbility.connectAbility(
{ {
deviceId: deviceId, deviceId: "",
bundleName: "com.ix.ServiceAbility", bundleName: "com.ix.ServiceAbility",
abilityName: "ServiceAbilityA", abilityName: "ServiceAbilityA",
}, },
...@@ -611,21 +616,156 @@ continueAbility(options: ContinueAbilityOptions, callback: AsyncCallback\<void>) ...@@ -611,21 +616,156 @@ continueAbility(options: ContinueAbilityOptions, callback: AsyncCallback\<void>)
**示例:** **示例:**
```javascript ```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) { async ContinueAbility(){
let continueAbilityOptions = { function ContinueAbilityCallback(err) {
reversible: false, console.info("=============>ContinueAbilityCallback============>");
deviceId: deviceId, }
} var continueAbilityOptions = {
function ContinueAbilityCallback(err, data) { reversible: false,
console.info("[Demo] ContinueAbilityCallback, result err = " + JSON.stringify(err)); deviceId: this.deviceId,
console.info("[Demo] ContinueAbilityCallback, result data= " + JSON.stringify(data)); }
} //continueAbility callback
await featureAbility.continueAbility(continueAbilityOptions, ContinueAbilityCallback); await ability.continueAbility(continueAbilityOptions, ContinueAbilityCallback);
console.info('[Demo] featureAbility.StartContinueAbility end'); },
}
```
## 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,
};
}
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 ## AbilityResult
......
...@@ -28,7 +28,7 @@ startAbility(parameter: StartAbilityParameter, callback: AsyncCallback\<void>: v ...@@ -28,7 +28,7 @@ startAbility(parameter: StartAbilityParameter, callback: AsyncCallback\<void>: v
```js ```js
import particleAbility from '@ohos.ability.particleAbility' import particleAbility from '@ohos.ability.particleAbility'
import wantConstant from "@ohos.ability.wantConstant" import wantConstant from '@ohos.ability.wantConstant'
particleAbility.startAbility( particleAbility.startAbility(
{ {
want: want:
...@@ -71,7 +71,7 @@ startAbility(parameter: StartAbilityParameter): Promise\<number> ...@@ -71,7 +71,7 @@ startAbility(parameter: StartAbilityParameter): Promise\<number>
```js ```js
import particleAbility from '@ohos.ability.particleAbility' import particleAbility from '@ohos.ability.particleAbility'
import wantConstant from "@ohos.ability.wantConstant" import wantConstant from '@ohos.ability.wantConstant'
particleAbility.startAbility( particleAbility.startAbility(
{ {
want: want:
...@@ -86,7 +86,7 @@ particleAbility.startAbility( ...@@ -86,7 +86,7 @@ particleAbility.startAbility(
uri:"" uri:""
}, },
}, },
).then(() => { ).then((data) => {
console.info("particleAbility startAbility"); console.info("particleAbility startAbility");
}); });
``` ```
...@@ -133,7 +133,7 @@ terminateSelf(): Promise\<void> ...@@ -133,7 +133,7 @@ terminateSelf(): Promise\<void>
```js ```js
import particleAbility from '@ohos.ability.particleAbility' import particleAbility from '@ohos.ability.particleAbility'
particleAbility.terminateSelf().then(() => { particleAbility.terminateSelf().then((data) => {
console.info("particleAbility terminateSelf"); console.info("particleAbility terminateSelf");
}); });
``` ```
...@@ -166,148 +166,6 @@ var uri = ""; ...@@ -166,148 +166,6 @@ var uri = "";
particleAbility.acquireDataAbilityHelper(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 ## StartAbilityParameter
| 名称 | 读写属性 | 类型 | 必填 | 描述 | | 名称 | 读写属性 | 类型 | 必填 | 描述 |
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册