js-apis-featureAbility.md 23.5 KB
Newer Older
W
wusongqing 已提交
1 2
# FeatureAbility Module (JavaScript)

W
wusongqing 已提交
3
## Constraints
W
wusongqing 已提交
4 5 6

APIs of the **FeatureAbility** module can be called only by Page abilities.

W
wusongqing 已提交
7
## Modules to Import
W
wusongqing 已提交
8 9 10 11 12

```
import featureAbility from '@ohos.ability.featureAbility'
```

W
wusongqing 已提交
13
## featureAbility.startAbility
W
wusongqing 已提交
14

W
wusongqing 已提交
15
startAbility(parameter: StartAbilityParameter, callback: AsyncCallback\<number>): void
W
wusongqing 已提交
16

W
wusongqing 已提交
17
Starts an ability. This method uses a callback to return the result.
W
wusongqing 已提交
18

W
wusongqing 已提交
19
**Parameters**
W
wusongqing 已提交
20

W
wusongqing 已提交
21 22 23 24
| Name| Type| Mandatory| Description|
| --------- | --------------------- | ---- | ------------------- |
| parameter | [StartAbilityParameter](#startabilityparameter) | Yes| Ability to start.|
| callback  | AsyncCallback\<number>         | Yes| Callback used to return the result.|
W
wusongqing 已提交
25

W
wusongqing 已提交
26
**Example**
W
wusongqing 已提交
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49

```javascript
import featureAbility from '@ohos.ability.featureAbility'
featureAbility.startAbility(
        {
        want:
        {
            action: "",
            entities: [""],
            type: "",
            flags: FLAG_AUTH_READ_URI_PERMISSION,
            deviceId: "",
            bundleName: "com.example.startability",
            abilityName: "com.example.startability.MainAbility",
            uri: ""
        },
    },
  );
)
```



W
wusongqing 已提交
50
## featureAbility.startAbility
W
wusongqing 已提交
51

W
wusongqing 已提交
52
startAbility(parameter: StartAbilityParameter): Promise\<number>
W
wusongqing 已提交
53

W
wusongqing 已提交
54
Starts an ability. This method uses a promise to return the result.
W
wusongqing 已提交
55

W
wusongqing 已提交
56
**Parameters**
W
wusongqing 已提交
57

W
wusongqing 已提交
58 59 60
| Name| Type| Mandatory| Description|
| --------- | ----------------------------------------------- | ---- | --------------------- |
| parameter | [StartAbilityParameter](#startabilityparameter) | Yes| Ability to start.|
W
wusongqing 已提交
61

W
wusongqing 已提交
62
**Example**
W
wusongqing 已提交
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84

```javascript
import featureAbility from '@ohos.ability.featureAbility'
featureAbility.startAbility(
    {
        want:
        {
            action: "action.system.home",
            entities: ["entity.system.home"],
            type: "MIMETYPE",
			flags: FLAG_AUTH_READ_URI_PERMISSION,
            deviceId: deviceId,
            bundleName: "com.example.startability",
            abilityName: "com.example.startability.MainAbility",
            uri: ""
        },
    }
   ).then((void) => {
	console.info("==========================>startAbility=======================>");
});
```

W
wusongqing 已提交
85
## featureAbility.acquireDataAbilityHelper
W
wusongqing 已提交
86

W
wusongqing 已提交
87
acquireDataAbilityHelper(uri: string): DataAbilityHelper
W
wusongqing 已提交
88

W
wusongqing 已提交
89
Obtains a **dataAbilityHelper** object.
W
wusongqing 已提交
90

W
wusongqing 已提交
91
**Parameters**
W
wusongqing 已提交
92

W
wusongqing 已提交
93 94 95
| Name| Type| Mandatory| Description|
| ---- | ------ | ---- | ------------------------ |
| uri  | string | Yes| URI of the file to open.|
W
wusongqing 已提交
96

W
wusongqing 已提交
97
**Return value**
W
wusongqing 已提交
98 99

| Type| Description|
W
wusongqing 已提交
100
| ----------------- | -------------------------------------------- |
W
wusongqing 已提交
101 102
| DataAbilityHelper | A utility class used to help other abilities access the Data ability.|

W
wusongqing 已提交
103
**Example**
W
wusongqing 已提交
104 105 106 107 108 109 110 111

```javascript
import featureAbility from '@ohos.ability.featureAbility'
featureAbility.acquireDataAbilityHelper(
    "dataability:///com.exmaple.DataAbility"
)
```

W
wusongqing 已提交
112
## featureAbility.startAbilityForResult
W
wusongqing 已提交
113

W
wusongqing 已提交
114
startAbilityForResult(parameter: StartAbilityParameter, callback: AsyncCallback\<AbilityResult>): void
W
wusongqing 已提交
115

W
wusongqing 已提交
116
Starts an ability. This method uses a callback to return the execution result when the ability is destroyed.
W
wusongqing 已提交
117

W
wusongqing 已提交
118
**Parameters**
W
wusongqing 已提交
119

W
wusongqing 已提交
120 121 122 123
| Name| Type| Mandatory| Description|
| --------- | ----------------------------------------------- | ---- | --------------------- |
| parameter | [StartAbilityParameter](#startabilityparameter) | Yes| Ability to start.|
| callback  | AsyncCallback\<[AbilityResult](#abilityresult)> | Yes| Callback used to return the result.|
W
wusongqing 已提交
124

W
wusongqing 已提交
125
**Example**
W
wusongqing 已提交
126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145

```javascript
import featureAbility from '@ohos.ability.featureability';
featureAbility.startAbilityForResult(
   {
        want:
        {
            action: "action.system.home",
            entities: ["entity.system.home"],
            type: "MIMETYPE",
            flags: FLAG_AUTH_READ_URI_PERMISSION,
            deviceId: "",
            bundleName: "com.example.featureabilitytest",
            abilityName: "com.example.featureabilitytest.MainAbility",
            uri:""
        },
    },
)
```

W
wusongqing 已提交
146
## featureAbility.startAbilityForResult
W
wusongqing 已提交
147

W
wusongqing 已提交
148
startAbilityForResult(parameter: StartAbilityParameter): Promise\<AbilityResult>
W
wusongqing 已提交
149

W
wusongqing 已提交
150
Starts an ability. This method uses a promise to return the execution result when the ability is destroyed.
W
wusongqing 已提交
151

W
wusongqing 已提交
152
**Parameters**
W
wusongqing 已提交
153

W
wusongqing 已提交
154 155 156
| Name| Type| Mandatory| Description|
| --------- | ----------------------------------------------- | ---- | ------------------- |
| parameter | [StartAbilityParameter](#startabilityparameter) | Yes| Ability to start.|
W
wusongqing 已提交
157

W
wusongqing 已提交
158 159 160 161
**Return value**
| Type| Description|
| ----------------------------------------- | -------------- |
| Promise\<[AbilityResult](#abilityresult)> | Promised returned with the execution result.|
W
wusongqing 已提交
162

W
wusongqing 已提交
163
**Example**
W
wusongqing 已提交
164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197

```javascript
import featureAbility from '@ohos.ability.featureability';
featureAbility.startAbilityForResult(
    {
        want:
        {
            action: "action.system.home",
            entities: ["entity.system.home"],
            type: "MIMETYPE",
            flags: FLAG_AUTH_READ_URI_PERMISSION,
            deviceId: "",
            bundleName: "com.example.featureabilitytest",
            abilityName: "com.example.featureabilitytest.MainAbility",
            uri:"",
            parameters:
            {
                mykey0: 1111,
                mykey1: [1, 2, 3],
                mykey2: "[1, 2, 3]",
                mykey3: "xxxxxxxxxxxxxxxxxxxxxx",
                mykey4: [1, 15],
                mykey5: [false, true, false],
                mykey6: ["aaaaaa", "bbbbb", "ccccccccccc"],
                mykey7: true,
            },
        },
        requestCode: 2,
    },
).then((void) => {
    console.info("==========================>startAbilityForResult=======================>");
});
```

W
wusongqing 已提交
198
## featureAbility.terminateSelfWithResult
W
wusongqing 已提交
199

W
wusongqing 已提交
200
terminateSelfWithResult(parameter: AbilityResult, callback: AsyncCallback\<void>): void
W
wusongqing 已提交
201

W
wusongqing 已提交
202
Destroys this Page ability, with the result code and data sent to the caller. This method uses a callback to return the result.
W
wusongqing 已提交
203

W
wusongqing 已提交
204
**Parameters**
W
wusongqing 已提交
205

W
wusongqing 已提交
206 207 208 209
| Name| Type| Mandatory| Description|
| --------- | ------------- | ---- | ------------------- |
| parameter | [AbilityResult](#abilityresult) | Yes| Ability to start.|
| callback  | AsyncCallback\<void> | Yes| Callback used to return the result.|
W
wusongqing 已提交
210

W
wusongqing 已提交
211
**Example**
W
wusongqing 已提交
212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242

```javascript
import featureAbility from '@ohos.ability.featureAbility'
featureAbility.terminateSelfWithResult(
    {
        resultCode: 1,
        want:
        {
            action: "action.system.home",
            entities: ["entity.system.home"],
            type: "MIMETYPE",
            flags: FLAG_AUTH_READ_URI_PERMISSION,
            deviceId: "",
            bundleName: "com.example.featureabilitytest",
            abilityName: "com.example.featureabilitytest.MainAbility",
            uri:"",
            parameters: {
                mykey0: 2222,
                mykey1: [1, 2, 3],
                mykey2: "[1, 2, 3]",
                mykey3: "ssssssssssssssssssssssssss",
                mykey4: [1, 15],
                mykey5: [false, true, false],
                mykey6: ["qqqqq", "wwwwww", "aaaaaaaaaaaaaaaaa"],
                mykey7: true,
            }
        },
    },
);
```

W
wusongqing 已提交
243
## featureAbility.terminateSelfWithResult
W
wusongqing 已提交
244

W
wusongqing 已提交
245
terminateSelfWithResult(parameter: AbilityResult): Promise\<void>
W
wusongqing 已提交
246

W
wusongqing 已提交
247
Destroys this Page ability, with the result code and data sent to the caller. This method uses a promise to return the result.
W
wusongqing 已提交
248

W
wusongqing 已提交
249
**Parameters**
W
wusongqing 已提交
250

W
wusongqing 已提交
251 252 253
| Name| Type| Mandatory| Description|
| --------- | ------------------------------- | ---- | ------------------- |
| parameter | [AbilityResult](#abilityresult) | Yes| Ability to start.|
W
wusongqing 已提交
254

W
wusongqing 已提交
255 256 257 258
**Return value**
| Type| Description|
| -------------- | ----------------------- |
| Promise\<void> | Promise returned with the result.|
W
wusongqing 已提交
259

W
wusongqing 已提交
260
**Example**
W
wusongqing 已提交
261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295

```javascript
import featureAbility from '@ohos.ability.featureability';
featureAbility.terminateSelfWithResult(
    {
        resultCode: 1,
        want:
        {
            action: "action.system.home",
            entities: ["entity.system.home"],
            type: "MIMETYPE",
            flags: FLAG_AUTH_READ_URI_PERMISSION,
            deviceId: "",
            bundleName: "com.example.featureabilitytest",
            abilityName: "com.example.featureabilitytest.MainAbility",
            uri:"",
            parameters: {
                mykey0: 2222,
                mykey1: [1, 2, 3],
                mykey2: "[1, 2, 3]",
                mykey3: "ssssssssssssssssssssssssss",
                mykey4: [1, 15],
                mykey5: [false, true, false],
                mykey6: ["qqqqq", "wwwwww", "aaaaaaaaaaaaaaaaa"],
                mykey7: true,
            }
        },
    }
).then((void) => {
    console.info("==========================>terminateSelfWithResult=======================>");
});
```



W
wusongqing 已提交
296
## featureAbility.hasWindowFocus
W
wusongqing 已提交
297

W
wusongqing 已提交
298
hasWindowFocus(callback: AsyncCallback\<boolean>): void
W
wusongqing 已提交
299

W
wusongqing 已提交
300
Checks whether the main window of this ability has the focus. This method uses a callback to return the result.
W
wusongqing 已提交
301

W
wusongqing 已提交
302
**Parameters**
W
wusongqing 已提交
303

W
wusongqing 已提交
304 305 306
| Name| Type| Mandatory| Description|
| -------- | ----------------------- | ---- | ------------------------------------------------------------ |
| callback | AsyncCallback\<boolean> | Yes| Callback used to return the result. <br>Returns **true** if the main window of this ability has the focus; returns **false** otherwise.|
W
wusongqing 已提交
307

W
wusongqing 已提交
308
**Example**
W
wusongqing 已提交
309 310 311 312 313 314 315 316

```javascript
import featureAbility from '@ohos.ability.featureability';
featureAbility.hasWindowFocus()
```



W
wusongqing 已提交
317
## featureAbility.hasWindowFocus
W
wusongqing 已提交
318

W
wusongqing 已提交
319
hasWindowFocus(): Promise\<boolean>
W
wusongqing 已提交
320

W
wusongqing 已提交
321
Checks whether the main window of this ability has the focus. This method uses a promise to return the result.
W
wusongqing 已提交
322

W
wusongqing 已提交
323
**Return value**
W
wusongqing 已提交
324

W
wusongqing 已提交
325 326 327
| Type| Description|
| ----------------- | ---------------------------------------------------------- |
| Promise\<boolean> | Returns **true** if the main window of this ability has the focus; returns **false** otherwise.|
W
wusongqing 已提交
328

W
wusongqing 已提交
329
**Example**
W
wusongqing 已提交
330 331 332 333 334 335 336 337 338 339

```javascript
import featureAbility from '@ohos.ability.featureability';
featureAbility.hasWindowFocus().then((void) => {
    console.info("==========================>hasWindowFocus=======================>");
});
```



W
wusongqing 已提交
340
## featureAbility.getWant
W
wusongqing 已提交
341

W
wusongqing 已提交
342
getWant(callback: AsyncCallback\<Want>): void
W
wusongqing 已提交
343

W
wusongqing 已提交
344
Obtains the **Want** object sent from this ability. This method uses a callback to return the result.
W
wusongqing 已提交
345

W
wusongqing 已提交
346
**Parameters**
W
wusongqing 已提交
347

W
wusongqing 已提交
348 349 350
| Name| Type| Mandatory| Description|
| -------- | ----------------------------- | ---- | ------------------ |
| callback | AsyncCallback\<[Want](#want)> | Yes| Callback used to return the result.|
W
wusongqing 已提交
351

W
wusongqing 已提交
352
**Example**
W
wusongqing 已提交
353 354 355 356 357 358 359 360

```javascript
import featureAbility from '@ohos.ability.featureability';
featureAbility.getWant()
```



W
wusongqing 已提交
361
## featureAbility.getWant
W
wusongqing 已提交
362

W
wusongqing 已提交
363
getWant(): Promise\<Want>
W
wusongqing 已提交
364

W
wusongqing 已提交
365
Obtains the **Want** object sent from this ability. This method uses a promise to return the result.
W
wusongqing 已提交
366

W
wusongqing 已提交
367 368 369 370
**Return value**
| Type| Description|
| ----------------------- | ------------------------- |
| Promise\<[Want](#want)> | Promise returned with the result.|
W
wusongqing 已提交
371

W
wusongqing 已提交
372
**Example**
W
wusongqing 已提交
373 374 375 376 377 378 379 380

```javascript
import featureAbility from '@ohos.ability.featureability';
featureAbility.getWant().then((void) => {
		console.info("==========================>getWantCallBack=======================>");
});
```

W
wusongqing 已提交
381
## featureAbility.getContext
W
wusongqing 已提交
382

W
wusongqing 已提交
383
getContext(): Context
W
wusongqing 已提交
384

W
wusongqing 已提交
385
Obtains the application context.
W
wusongqing 已提交
386

W
wusongqing 已提交
387 388 389 390
**Return value**
| Type| Description|
| ------- | -------------------- |
| Context | Application context returned.|
W
wusongqing 已提交
391

W
wusongqing 已提交
392
**Example**
W
wusongqing 已提交
393 394 395 396 397 398 399 400 401

```javascript
import featureAbility from '@ohos.ability.featureability';
var context = featureAbility.getContext()
context.getBundleName()
```



W
wusongqing 已提交
402
## featureAbility.terminateSelf
W
wusongqing 已提交
403

W
wusongqing 已提交
404
terminateSelf(callback: AsyncCallback\<void>): void
W
wusongqing 已提交
405

W
wusongqing 已提交
406
Destroys this Page ability, with the result code and data sent to the caller. This method uses a callback to return the result.
W
wusongqing 已提交
407

W
wusongqing 已提交
408
**Parameters**
W
wusongqing 已提交
409

W
wusongqing 已提交
410 411 412
| Name| Type| Mandatory| Description|
| -------- | -------------------- | ---- | ---------------- |
| callback | AsyncCallback\<void> | Yes| Callback used to return the result.|
W
wusongqing 已提交
413

W
wusongqing 已提交
414
**Example**
W
wusongqing 已提交
415 416 417 418 419 420 421 422

```javascript
import featureAbility from '@ohos.ability.featureability';
featureAbility.terminateSelf()
```



W
wusongqing 已提交
423
## featureAbility.terminateSelf
W
wusongqing 已提交
424

W
wusongqing 已提交
425
terminateSelf(): Promise\<void>
W
wusongqing 已提交
426

W
wusongqing 已提交
427
Destroys this Page ability, with the result code and data sent to the caller. This method uses a promise to return the result.
W
wusongqing 已提交
428

W
wusongqing 已提交
429 430 431 432
**Return value**
| Type| Description|
| -------------- | ------------------------- |
| Promise\<void> | Promise returned with the result.|
W
wusongqing 已提交
433

W
wusongqing 已提交
434
**Example**
W
wusongqing 已提交
435 436 437 438 439 440 441

```javascript
import featureAbility from '@ohos.ability.featureability';
featureAbility.terminateSelf().then((void) => {		    console.info("==========================>terminateSelfCallBack=======================>");
});
```

W
wusongqing 已提交
442
## featureAbility.connectAbility
W
wusongqing 已提交
443

W
wusongqing 已提交
444
connectAbility(request: Want, options:ConnectOptions): number
W
wusongqing 已提交
445

W
wusongqing 已提交
446
Connects this ability to a specific Service ability. This method uses a callback to return the result.
W
wusongqing 已提交
447

W
wusongqing 已提交
448
**Parameters**
W
wusongqing 已提交
449

W
wusongqing 已提交
450 451 452 453
| Name| Type| Mandatory| Description|
| ------- | -------------- | ---- | ---------------------------- |
| request | [Want](#want)           | Yes| Service ability to connect.|
| options | ConnectOptions | Yes| Callback used to return the result.|
W
wusongqing 已提交
454

W
wusongqing 已提交
455
Want
W
wusongqing 已提交
456 457 458 459 460 461 462

| Name| Readable/Writable| Type| Mandatory| Description|
| ------------ | -------- | -------- | ---- | ----------------------------------                               |
| deviceId     | Read-only| string   | No| Device ID of the Service ability to connect. The default value is the local device ID.|
| bundleName   | Read-only| string   | Yes| Bundle name of the Service ability to connect.|
| abilityName  | Read-only| string   | Yes| Class name of the Service ability to connect.|

W
wusongqing 已提交
463
ConnectOptions
W
wusongqing 已提交
464 465 466 467 468 469 470

| Name| Readable/Writable| Type| Mandatory| Description|
| ------------ | -------- | -------- | ---- | ---------------------------------- |
| onConnect    | Read-only| function | Yes| Callback invoked when the connection is successful.|
| onDisconnect | Read-only| function | Yes| Callback invoked when the connection fails.|
| onFailed     | Read-only| function | Yes| Callback invoked when **connectAbility** fails to be called.|

W
wusongqing 已提交
471 472 473 474
**Return value**
| Type| Description|
| ------ | ------------------------ |
| number | Returns the ID of the Service ability connected.|
W
wusongqing 已提交
475

W
wusongqing 已提交
476
**Example**
W
wusongqing 已提交
477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502

```javascript
import featureAbility from '@ohos.ability.featureAbility'
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('featureAbilityTest ConnectAbility onFailed errCode : ' + code)
}
var connId = featureAbility.connectAbility(
    {
        deviceId: deviceId,
        bundleName: "com.ix.ServiceAbility",
        abilityName: "ServiceAbilityA",
    },
    {
        onConnect: onConnectCallback,
        onDisconnect: onDisconnectCallback,
        onFailed: onFailedCallback,
    },
);
```

W
wusongqing 已提交
503
## featureAbility.disconnectAbility
W
wusongqing 已提交
504

W
wusongqing 已提交
505
disconnectAbility(connection: number, callback:AsyncCallback\<void>): void
W
wusongqing 已提交
506

W
wusongqing 已提交
507
Disconnects this ability from a specific Service ability. This method uses a callback to return the result.
W
wusongqing 已提交
508

W
wusongqing 已提交
509
**Parameters**
W
wusongqing 已提交
510

W
wusongqing 已提交
511 512 513 514
| Name| Type| Mandatory| Description|
| ---------- | ------------- | ---- | ------------------------------ |
| connection | number        | Yes| ID of the Service ability to disconnect.|
| callback   | AsyncCallback\<void> | Yes| Callback used to return the result.|
W
wusongqing 已提交
515

W
wusongqing 已提交
516
**Example**
W
wusongqing 已提交
517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546

```javascript
import featureAbility from '@ohos.ability.featureAbility'
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('featureAbilityTest ConnectAbility onFailed errCode : ' + code)
}
var connId = featureAbility.connectAbility(
    {
        bundleName: "com.ix.ServiceAbility",
        abilityName: "ServiceAbilityA",
    },
    {
        onConnect: onConnectCallback,
        onDisconnect: onDisconnectCallback,
        onFailed: onFailedCallback,
    },
);
var result = featureAbility.disconnectAbility(connId,
    (error,data) => {
    console.log('featureAbilityTest DisConnectJsSameBundleName result errCode : ' + error.code + " data: " + data)
    },
);
```

W
wusongqing 已提交
547
## featureAbility.disconnectAbility
W
wusongqing 已提交
548

W
wusongqing 已提交
549
disconnectAbility(connection: number): Promise\<void>
W
wusongqing 已提交
550

W
wusongqing 已提交
551
Disconnects this ability from a specific Service ability. This method uses a promise to return the result.
W
wusongqing 已提交
552

W
wusongqing 已提交
553
**Parameters**
W
wusongqing 已提交
554

W
wusongqing 已提交
555 556 557 558 559 560 561 562
| Name| Type| Mandatory| Description|
| ---------- | ------ | ---- | ------------------------------ |
| connection | number | Yes| ID of the Service ability to disconnect.|

**Return value**
| Type| Description|
| -------------- | ----------------------- |
| Promise\<void> | Promise returned with the result.|
W
wusongqing 已提交
563

W
wusongqing 已提交
564
**Example**
W
wusongqing 已提交
565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590

```javascript
import featureAbility from '@ohos.ability.featureAbility'
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('featureAbilityTest ConnectAbility onFailed errCode : ' + code)
}
var connId = featureAbility.connectAbility(
    {
        bundleName: "com.ix.ServiceAbility",
        abilityName: "ServiceAbilityA",
    },
    {
        onConnect: onConnectCallback,
        onDisconnect: onDisconnectCallback,
        onFailed: onFailedCallback,
    },
);
var result = await featureAbility.disconnectAbility(connId);
```

W
wusongqing 已提交
591
## featureAbility.continueAbility
W
wusongqing 已提交
592

W
wusongqing 已提交
593
continueAbility(options: ContinueAbilityOptions, callback: AsyncCallback\<void>): void
W
wusongqing 已提交
594

W
wusongqing 已提交
595
Migrates an ability to another device. This method uses a callback to return the execution result.
W
wusongqing 已提交
596

W
wusongqing 已提交
597
**Parameters**
W
wusongqing 已提交
598

W
wusongqing 已提交
599 600 601 602
| Name| Type| Mandatory| Description|
| -------- | ---------------------- | ---- | ------------------- |
| options  | ContinueAbilityOptions | Yes| Ability to migrate.|
| callback | AsyncCallback\<void>   | Yes| Callback used to return the result.|
W
wusongqing 已提交
603

W
wusongqing 已提交
604
ContinueAbilityOptions
W
wusongqing 已提交
605 606

| Name| Readable/Writable| Type| Mandatory| Description|
W
wusongqing 已提交
607
| ---------- | -------- | ------- | ---- | ------------------------------------------------------------ |
W
wusongqing 已提交
608 609 610
| deviceId   | Read-only| string  | Yes| Information about the ability to migrate.|
| reversible | Read-only| boolean | Yes| Whether migration back is supported. Currently, this feature is not supported. This parameter is reserved and can be set to **false**.|

W
wusongqing 已提交
611
**Example**
W
wusongqing 已提交
612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630

```javascript
import featureAbility from '@ohos.ability.featureAbility'

async StartContinueAbility(deviceId) {
    let continueAbilityOptions = {
        reversible: false,
        deviceId: deviceId,
    }
    function ContinueAbilityCallback(err, data) {
        console.info("[Demo] ContinueAbilityCallback, result err = " + JSON.stringify(err));
        console.info("[Demo] ContinueAbilityCallback, result data= " + JSON.stringify(data));
    }
    await featureAbility.continueAbility(continueAbilityOptions, ContinueAbilityCallback);
    console.info('[Demo] featureAbility.StartContinueAbility end');
}
this.StartContinueAbility(remoteDeviceId); //remoteDeviceId is acquired from DeviceManager
```

W
wusongqing 已提交
631
## AbilityResult
W
wusongqing 已提交
632 633 634 635

| Name| Readable/Writable| Type| Mandatory| Description|
| ---------- | -------- | --------------------- | ---- | ------------------------------------------------------------ |
| resultCode | Read-only| number                | Yes| Result code returned after the ability is destroyed. The feature for defining error-specific result codes is coming soon.|
W
wusongqing 已提交
636
| want       | Read-only| [Want](#want) | No| Data returned after the ability is destroyed. You can define the data to be returned. This parameter can be **null**.|
W
wusongqing 已提交
637

W
wusongqing 已提交
638
## StartAbilityParameter
W
wusongqing 已提交
639 640

| Name| Readable/Writable| Type| Mandatory| Description|
W
wusongqing 已提交
641 642 643
| ------------------- | -------- | -------------------- | ---- | ------------------------------------------------------------ |
| want                | Read-only| [Want](#want)        | Yes| Information about the ability to start.|
| abilityStartSetting | Read-only| {[key: string]: any} | No| Special attribute of the ability to start. This attribute can be passed in the method call.|
W
wusongqing 已提交
644

W
wusongqing 已提交
645
## Want
W
wusongqing 已提交
646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662

| Name| Readable/Writable| Type| Mandatory| Description|
| ----------- | -------- | -------------------- | ---- | ------------------------------------------------------------ |
| deviceId    | Read-only| string               | No| ID of the device that runs the ability.|
| bundleName  | Read-only| string               | No| Bundle name of the ability to start. If both **bundleName** and **abilityName** are specified in a **Want** object, the **Want** object can directly match the specified ability.|
| abilityName | Read-only| string               | No| Name of the ability to start. If both **bundleName** and **abilityName** are specified in a **Want** object, the **Want** object can directly match the specified ability.|
| uri         | Read-only| string               | No| URI information to match. If **uri** is specified in a **Want** object, the **Want** object will match the specified URI information, including **scheme**, **schemeSpecificPart**, **authority**, and **path**.|
| type        | Read-only| string               | No| MIME type, for example, text/plain or image/*.|
| flags       | Read-only| number               | No| How the **Want** object will be handled. By default, a number is passed. For details, see [flags](#flags).|
| action      | Read-only| string               | No| Action option.|
| parameters  | Read-only| {[key: string]: any} | No| List of parameters in a **Want** object.|
| entities    | Read-only| Array\<string>       | No| List of entities.|

## flags

| Name| Name| Description|
| ------------------------------------ | ---------- | ------------------------------------------------------------ |
W
wusongqing 已提交
663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678
| FLAG_AUTH_READ_URI_PERMISSION        | 0x00000001 | Indicates the permission to read the URI.|
| FLAG_AUTH_WRITE_URI_PERMISSION       | 0x00000002 | Indicates the permission to write the URI.|
| FLAG_ABILITY_FORWARD_RESULT          | 0x00000004 | Returns the result to the ability.|
| FLAG_ABILITY_CONTINUATION            | 0x00000008 | Indicates whether the ability on the local device can be migrated to a remote device.|
| FLAG_NOT_OHOS_COMPONENT              | 0x00000010 | Indicates that a component does not belong to OHOS.|
| FLAG_ABILITY_FORM_ENABLED            | 0x00000020 | Indicates whether to enable an ability.|
| FLAG_AUTH_PERSISTABLE_URI_PERMISSION | 0x00000040 | Indicates the permission to make the URI persistent.|
| FLAG_AUTH_PREFIX_URI_PERMISSION      | 0x00000080 | Indicates the permission to verify URIs by prefix matching.|
| FLAG_ABILITYSLICE_MULTI_DEVICE       | 0x00000100 | Supports cross-device startup in a distributed scheduler.|
| FLAG_START_FOREGROUND_ABILITY        | 0x00000200 | Indicates that the Service ability is started regardless of whether the host application has been started.|
| FLAG_ABILITY_CONTINUATION_REVERSIBLE | 0x00000400 | Indicates that the migration is reversible.|
| FLAG_INSTALL_ON_DEMAND               | 0x00000800 | Indicates that the specific ability will be installed if it has not been installed.|
| FLAG_INSTALL_WITH_BACKGROUND_MODE    | 0x80000000 | Indicates that the specific ability will be installed in the background if it has not been installed.|
| FLAG_ABILITY_CLEAR_MISSION           | 0x00008000 | Clears other operation missions. This flag can be set for the **Want** object passed to **ohos.app.Context#startAbility** and must be used together with **flag_ABILITY_NEW_MISSION**.|
| FLAG_ABILITY_NEW_MISSION             | 0x10000000 | Creates a mission on the historical mission stack.|
| FLAG_ABILITY_MISSION_TOP             | 0x20000000 | Starts the mission on the top of the existing mission stack; creates an ability instance if no mission exists.|