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

W
wusongqing 已提交
3 4 5
> ![icon-note.gif](public_sys-resources/icon-note.gif) **NOTE**
> The initial APIs of this module are supported since API version 6. Newly added APIs will be marked with a superscript to indicate their earliest API version.

W
wusongqing 已提交
6
## Constraints
W
wusongqing 已提交
7 8 9

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

W
wusongqing 已提交
10
## Modules to Import
W
wusongqing 已提交
11 12 13 14 15

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

W
wusongqing 已提交
16
## featureAbility.startAbility
W
wusongqing 已提交
17

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

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

W
wusongqing 已提交
22
**System capability**: SystemCapability.Ability.AbilityRuntime.FAModel
W
wusongqing 已提交
23

W
wusongqing 已提交
24
**Parameters**
W
wusongqing 已提交
25

W
wusongqing 已提交
26 27 28 29
| Name       | Type                                      | Mandatory  | Description            |
| --------- | ---------------------------------------- | ---- | -------------- |
| parameter | [StartAbilityParameter](#startabilityparameter) | Yes   | Ability to start.|
| callback  | AsyncCallback\<number>                   | Yes   | Callback used to return the result.     |
W
wusongqing 已提交
30

W
wusongqing 已提交
31
**Example**
W
wusongqing 已提交
32 33 34

```javascript
import featureAbility from '@ohos.ability.featureAbility'
W
wusongqing 已提交
35
import wantConstant from '@ohos.ability.wantConstant'
W
wusongqing 已提交
36
featureAbility.startAbility(
W
wusongqing 已提交
37
    {
W
wusongqing 已提交
38 39 40 41 42
        want:
        {
            action: "",
            entities: [""],
            type: "",
W
wusongqing 已提交
43
            flags: wantConstant.Flags.FLAG_AUTH_READ_URI_PERMISSION,
W
wusongqing 已提交
44 45 46 47 48 49
            deviceId: "",
            bundleName: "com.example.startability",
            abilityName: "com.example.startability.MainAbility",
            uri: ""
        },
    },
W
wusongqing 已提交
50
);
W
wusongqing 已提交
51 52 53 54
```



W
wusongqing 已提交
55
## featureAbility.startAbility
W
wusongqing 已提交
56

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

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

W
wusongqing 已提交
61
**System capability**: SystemCapability.Ability.AbilityRuntime.FAModel
W
wusongqing 已提交
62

W
wusongqing 已提交
63
**Parameters**
W
wusongqing 已提交
64

W
wusongqing 已提交
65 66 67
| Name       | Type                                      | Mandatory  | Description            |
| --------- | ---------------------------------------- | ---- | -------------- |
| parameter | [StartAbilityParameter](#startabilityparameter) | Yes   | Ability to start.|
W
wusongqing 已提交
68

W
wusongqing 已提交
69
**Example**
W
wusongqing 已提交
70 71 72

```javascript
import featureAbility from '@ohos.ability.featureAbility'
W
wusongqing 已提交
73
import wantConstant from '@ohos.ability.wantConstant'
W
wusongqing 已提交
74 75 76 77 78 79 80
featureAbility.startAbility(
    {
        want:
        {
            action: "action.system.home",
            entities: ["entity.system.home"],
            type: "MIMETYPE",
W
wusongqing 已提交
81 82
			flags: wantConstant.Flags.FLAG_AUTH_READ_URI_PERMISSION,
            deviceId: "",
W
wusongqing 已提交
83 84 85 86 87
            bundleName: "com.example.startability",
            abilityName: "com.example.startability.MainAbility",
            uri: ""
        },
    }
W
wusongqing 已提交
88
).then((data) => {
W
wusongqing 已提交
89 90 91 92
	console.info("==========================>startAbility=======================>");
});
```

W
wusongqing 已提交
93
## featureAbility.acquireDataAbilityHelper<sup>7+</sup>
W
wusongqing 已提交
94

W
wusongqing 已提交
95
acquireDataAbilityHelper(uri: string): DataAbilityHelper
W
wusongqing 已提交
96

W
wusongqing 已提交
97
Obtains a **dataAbilityHelper** object.
W
wusongqing 已提交
98

W
wusongqing 已提交
99
**System capability**: SystemCapability.Ability.AbilityRuntime.FAModel
W
wusongqing 已提交
100

W
wusongqing 已提交
101
**Parameters**
W
wusongqing 已提交
102

W
wusongqing 已提交
103 104 105
| Name  | Type    | Mandatory  | Description          |
| ---- | ------ | ---- | ------------ |
| uri  | string | Yes   | URI of the file to open.|
W
wusongqing 已提交
106

W
wusongqing 已提交
107
**Return value**
W
wusongqing 已提交
108

W
wusongqing 已提交
109 110
| Type               | Description                             |
| ----------------- | ------------------------------- |
W
wusongqing 已提交
111 112
| DataAbilityHelper | A utility class used to help other abilities access the Data ability.|

W
wusongqing 已提交
113
**Example**
W
wusongqing 已提交
114 115 116 117

```javascript
import featureAbility from '@ohos.ability.featureAbility'
featureAbility.acquireDataAbilityHelper(
Y
yuyaozhi 已提交
118
    "dataability:///com.example.DataAbility"
W
wusongqing 已提交
119 120 121
)
```

W
wusongqing 已提交
122
## featureAbility.startAbilityForResult<sup>7+</sup>
W
wusongqing 已提交
123

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

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

W
wusongqing 已提交
128
**System capability**: SystemCapability.Ability.AbilityRuntime.FAModel
W
wusongqing 已提交
129

W
wusongqing 已提交
130
**Parameters**
W
wusongqing 已提交
131

W
wusongqing 已提交
132 133 134 135
| Name       | Type                                      | Mandatory  | Description            |
| --------- | ---------------------------------------- | ---- | -------------- |
| parameter | [StartAbilityParameter](#startabilityparameter) | Yes   | Ability to start.|
| callback  | AsyncCallback\<[AbilityResult](#abilityresult)> | Yes   | Callback used to return the result.     |
W
wusongqing 已提交
136

W
wusongqing 已提交
137
**Example**
W
wusongqing 已提交
138 139 140

```javascript
import featureAbility from '@ohos.ability.featureability';
W
wusongqing 已提交
141
import wantConstant from '@ohos.ability.wantConstant'
W
wusongqing 已提交
142 143 144 145 146 147 148
featureAbility.startAbilityForResult(
   {
        want:
        {
            action: "action.system.home",
            entities: ["entity.system.home"],
            type: "MIMETYPE",
W
wusongqing 已提交
149
            flags: wantConstant.Flags.FLAG_AUTH_READ_URI_PERMISSION,
W
wusongqing 已提交
150 151 152 153 154 155
            deviceId: "",
            bundleName: "com.example.featureabilitytest",
            abilityName: "com.example.featureabilitytest.MainAbility",
            uri:""
        },
    },
W
wusongqing 已提交
156 157 158
    (err, data) => {
        console.info("err: " + JSON.stringfy(err) + "data: " + JSON.stringfy(data))
    }
W
wusongqing 已提交
159 160 161
)
```

W
wusongqing 已提交
162
## featureAbility.startAbilityForResult<sup>7+</sup>
W
wusongqing 已提交
163

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

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

W
wusongqing 已提交
168
**System capability**: SystemCapability.Ability.AbilityRuntime.FAModel
W
wusongqing 已提交
169

W
wusongqing 已提交
170
**Parameters**
W
wusongqing 已提交
171

W
wusongqing 已提交
172 173 174
| Name       | Type                                      | Mandatory  | Description           |
| --------- | ---------------------------------------- | ---- | ------------- |
| parameter | [StartAbilityParameter](#startabilityparameter) | Yes   | Ability to start.|
W
wusongqing 已提交
175

W
wusongqing 已提交
176
**Return value**
W
wusongqing 已提交
177

W
wusongqing 已提交
178 179
| Type                                      | Description     |
| ---------------------------------------- | ------- |
W
wusongqing 已提交
180
| Promise\<[AbilityResult](#abilityresult)> | Promised returned with the execution result.|
W
wusongqing 已提交
181

W
wusongqing 已提交
182
**Example**
W
wusongqing 已提交
183 184 185

```javascript
import featureAbility from '@ohos.ability.featureability';
W
wusongqing 已提交
186
import wantConstant from '@ohos.ability.wantConstant'
W
wusongqing 已提交
187 188 189 190 191 192 193
featureAbility.startAbilityForResult(
    {
        want:
        {
            action: "action.system.home",
            entities: ["entity.system.home"],
            type: "MIMETYPE",
W
wusongqing 已提交
194
            flags: wantConstant.Flags.FLAG_AUTH_READ_URI_PERMISSION,
W
wusongqing 已提交
195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212
            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,
    },
W
wusongqing 已提交
213
).then((data) => {
W
wusongqing 已提交
214 215 216 217
    console.info("==========================>startAbilityForResult=======================>");
});
```

W
wusongqing 已提交
218
## featureAbility.terminateSelfWithResult<sup>7+</sup>
W
wusongqing 已提交
219

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

W
wusongqing 已提交
222
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 已提交
223

W
wusongqing 已提交
224
**System capability**: SystemCapability.Ability.AbilityRuntime.FAModel
W
wusongqing 已提交
225

W
wusongqing 已提交
226
**Parameters**
W
wusongqing 已提交
227

W
wusongqing 已提交
228 229 230 231
| Name       | Type                             | Mandatory  | Description            |
| --------- | ------------------------------- | ---- | -------------- |
| parameter | [AbilityResult](#abilityresult) | Yes   | Ability to start.|
| callback  | AsyncCallback\<void>            | Yes   | Callback used to return the result.     |
W
wusongqing 已提交
232

W
wusongqing 已提交
233
**Example**
W
wusongqing 已提交
234 235 236

```javascript
import featureAbility from '@ohos.ability.featureAbility'
W
wusongqing 已提交
237
import wantConstant from '@ohos.ability.wantConstant'
W
wusongqing 已提交
238 239 240 241 242 243 244 245
featureAbility.terminateSelfWithResult(
    {
        resultCode: 1,
        want:
        {
            action: "action.system.home",
            entities: ["entity.system.home"],
            type: "MIMETYPE",
W
wusongqing 已提交
246
            flags: wantConstant.Flags.FLAG_AUTH_READ_URI_PERMISSION,
W
wusongqing 已提交
247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265
            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 已提交
266
## featureAbility.terminateSelfWithResult<sup>7+</sup>
W
wusongqing 已提交
267

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

W
wusongqing 已提交
270
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 已提交
271

W
wusongqing 已提交
272
**System capability**: SystemCapability.Ability.AbilityRuntime.FAModel
W
wusongqing 已提交
273

W
wusongqing 已提交
274
**Parameters**
W
wusongqing 已提交
275

W
wusongqing 已提交
276 277 278
| Name       | Type                             | Mandatory  | Description           |
| --------- | ------------------------------- | ---- | ------------- |
| parameter | [AbilityResult](#abilityresult) | Yes   | Ability to start.|
W
wusongqing 已提交
279

W
wusongqing 已提交
280
**Return value**
W
wusongqing 已提交
281

W
wusongqing 已提交
282 283
| Type            | Description             |
| -------------- | --------------- |
W
wusongqing 已提交
284
| Promise\<void> | Promise used to return the result.|
W
wusongqing 已提交
285

W
wusongqing 已提交
286
**Example**
W
wusongqing 已提交
287 288 289

```javascript
import featureAbility from '@ohos.ability.featureability';
W
wusongqing 已提交
290
import wantConstant from '@ohos.ability.wantConstant'
W
wusongqing 已提交
291 292 293 294 295 296 297 298
featureAbility.terminateSelfWithResult(
    {
        resultCode: 1,
        want:
        {
            action: "action.system.home",
            entities: ["entity.system.home"],
            type: "MIMETYPE",
W
wusongqing 已提交
299
            flags: wantConstant.Flags.FLAG_AUTH_READ_URI_PERMISSION,
W
wusongqing 已提交
300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315
            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 已提交
316
).then((data) => {
W
wusongqing 已提交
317 318 319 320 321 322
    console.info("==========================>terminateSelfWithResult=======================>");
});
```



W
wusongqing 已提交
323
## featureAbility.hasWindowFocus<sup>7+<sup>
W
wusongqing 已提交
324

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

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

W
wusongqing 已提交
329
**System capability**: SystemCapability.Ability.AbilityRuntime.FAModel
W
wusongqing 已提交
330

W
wusongqing 已提交
331
**Parameters**
W
wusongqing 已提交
332

W
wusongqing 已提交
333 334 335
| 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 已提交
336

W
wusongqing 已提交
337
**Example**
W
wusongqing 已提交
338 339 340 341 342 343 344 345

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



W
wusongqing 已提交
346
## featureAbility.hasWindowFocus<sup>7+<sup>
W
wusongqing 已提交
347

W
wusongqing 已提交
348
hasWindowFocus(): Promise\<boolean>
W
wusongqing 已提交
349

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

W
wusongqing 已提交
352
**System capability**: SystemCapability.Ability.AbilityRuntime.FAModel
W
wusongqing 已提交
353

W
wusongqing 已提交
354
**Return value**
W
wusongqing 已提交
355

W
wusongqing 已提交
356 357
| Type               | Description                                   |
| ----------------- | ------------------------------------- |
W
wusongqing 已提交
358
| Promise\<boolean> | Returns **true** if the main window of this ability has the focus; returns **false** otherwise.|
W
wusongqing 已提交
359

W
wusongqing 已提交
360
**Example**
W
wusongqing 已提交
361 362 363

```javascript
import featureAbility from '@ohos.ability.featureability';
W
wusongqing 已提交
364
featureAbility.hasWindowFocus().then((data) => {
W
wusongqing 已提交
365 366 367 368 369 370
    console.info("==========================>hasWindowFocus=======================>");
});
```



W
wusongqing 已提交
371
## featureAbility.getWant
W
wusongqing 已提交
372

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

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

W
wusongqing 已提交
377
**System capability**: SystemCapability.Ability.AbilityRuntime.FAModel
W
wusongqing 已提交
378

W
wusongqing 已提交
379
**Parameters**
W
wusongqing 已提交
380

W
wusongqing 已提交
381 382 383
| Name      | Type                           | Mandatory  | Description       |
| -------- | ----------------------------- | ---- | --------- |
| callback | AsyncCallback\<[Want](#want)> | Yes   | Callback used to return the result.|
W
wusongqing 已提交
384

W
wusongqing 已提交
385
**Example**
W
wusongqing 已提交
386 387 388 389 390 391 392 393

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



W
wusongqing 已提交
394
## featureAbility.getWant
W
wusongqing 已提交
395

W
wusongqing 已提交
396
getWant(): Promise\<Want>
W
wusongqing 已提交
397

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

W
wusongqing 已提交
400
**System capability**: SystemCapability.Ability.AbilityRuntime.FAModel
W
wusongqing 已提交
401

W
wusongqing 已提交
402
**Return value**
W
wusongqing 已提交
403

W
wusongqing 已提交
404 405
| Type                     | Description              |
| ----------------------- | ---------------- |
W
wusongqing 已提交
406
| Promise\<[Want](#want)> | Promise used to return the result.|
W
wusongqing 已提交
407

W
wusongqing 已提交
408
**Example**
W
wusongqing 已提交
409 410 411

```javascript
import featureAbility from '@ohos.ability.featureability';
W
wusongqing 已提交
412
featureAbility.getWant().then((data) => {
W
wusongqing 已提交
413
	console.info("==========================>getWantCallBack=======================>");
W
wusongqing 已提交
414 415 416
});
```

W
wusongqing 已提交
417
## featureAbility.getContext
W
wusongqing 已提交
418

W
wusongqing 已提交
419
getContext(): Context
W
wusongqing 已提交
420

W
wusongqing 已提交
421
Obtains the application context.
W
wusongqing 已提交
422

W
wusongqing 已提交
423
**System capability**: SystemCapability.Ability.AbilityRuntime.FAModel
W
wusongqing 已提交
424

W
wusongqing 已提交
425
**Return value**
W
wusongqing 已提交
426

W
wusongqing 已提交
427 428
| Type     | Description        |
| ------- | ---------- |
W
wusongqing 已提交
429
| Context | Application context returned.|
W
wusongqing 已提交
430

W
wusongqing 已提交
431
**Example**
W
wusongqing 已提交
432 433 434 435 436 437 438 439 440

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



W
wusongqing 已提交
441
## featureAbility.terminateSelf<sup>7+</sup>
W
wusongqing 已提交
442

W
wusongqing 已提交
443
terminateSelf(callback: AsyncCallback\<void>): void
W
wusongqing 已提交
444

W
wusongqing 已提交
445
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 已提交
446

W
wusongqing 已提交
447
**System capability**: SystemCapability.Ability.AbilityRuntime.FAModel
W
wusongqing 已提交
448

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

W
wusongqing 已提交
451 452 453
| Name      | Type                  | Mandatory  | Description      |
| -------- | -------------------- | ---- | -------- |
| callback | AsyncCallback\<void> | Yes   | Callback used to return the result.|
W
wusongqing 已提交
454

W
wusongqing 已提交
455
**Example**
W
wusongqing 已提交
456 457 458 459 460 461 462 463

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



W
wusongqing 已提交
464
## featureAbility.terminateSelf<sup>7+</sup>
W
wusongqing 已提交
465

W
wusongqing 已提交
466
terminateSelf(): Promise\<void>
W
wusongqing 已提交
467

W
wusongqing 已提交
468
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 已提交
469

W
wusongqing 已提交
470
**System capability**: SystemCapability.Ability.AbilityRuntime.FAModel
W
wusongqing 已提交
471

W
wusongqing 已提交
472
**Return value**
W
wusongqing 已提交
473

W
wusongqing 已提交
474 475
| Type            | Description              |
| -------------- | ---------------- |
W
wusongqing 已提交
476
| Promise\<void> | Promise used to return the result.|
W
wusongqing 已提交
477

W
wusongqing 已提交
478
**Example**
W
wusongqing 已提交
479 480 481

```javascript
import featureAbility from '@ohos.ability.featureability';
W
wusongqing 已提交
482 483
featureAbility.terminateSelf().then((data) => {
    console.info("==========================>terminateSelfCallBack=======================>");
W
wusongqing 已提交
484 485 486
});
```

W
wusongqing 已提交
487
## featureAbility.connectAbility<sup>7+</sup>
W
wusongqing 已提交
488

W
wusongqing 已提交
489
connectAbility(request: Want, options:ConnectOptions): number
W
wusongqing 已提交
490

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

W
wusongqing 已提交
493
**System capability**: SystemCapability.Ability.AbilityRuntime.FAModel
W
wusongqing 已提交
494

W
wusongqing 已提交
495
**Parameters**
W
wusongqing 已提交
496

W
wusongqing 已提交
497 498 499 500
| Name     | Type            | Mandatory  | Description                   |
| ------- | -------------- | ---- | --------------------- |
| request | [Want](#want)  | Yes   | Service ability to connect.|
| options | ConnectOptions | Yes   | Callback used to return the result.            |
W
wusongqing 已提交
501

W
wusongqing 已提交
502
Want
W
wusongqing 已提交
503

W
wusongqing 已提交
504 505
**System capability**: SystemCapability.Ability.AbilityBase

W
wusongqing 已提交
506 507 508 509 510
| 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 已提交
511

W
wusongqing 已提交
512
ConnectOptions
W
wusongqing 已提交
513

W
wusongqing 已提交
514 515
**System capability**: SystemCapability.Ability.AbilityRuntime.Core

W
wusongqing 已提交
516 517 518 519 520
| 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 已提交
521

W
wusongqing 已提交
522
**Return value**
W
wusongqing 已提交
523

W
wusongqing 已提交
524 525
| Type    | Description                  |
| ------ | -------------------- |
W
wusongqing 已提交
526
| number | Returns the ID of the Service ability connected.|
W
wusongqing 已提交
527

W
wusongqing 已提交
528
**Example**
W
wusongqing 已提交
529 530

```javascript
W
wusongqing 已提交
531
import rpc from '@ohos.rpc'
W
wusongqing 已提交
532 533 534 535 536 537 538 539 540 541 542 543
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(
    {
W
wusongqing 已提交
544
        deviceId: "",
W
wusongqing 已提交
545 546 547 548 549 550 551 552 553 554 555
        bundleName: "com.ix.ServiceAbility",
        abilityName: "ServiceAbilityA",
    },
    {
        onConnect: onConnectCallback,
        onDisconnect: onDisconnectCallback,
        onFailed: onFailedCallback,
    },
);
```

W
wusongqing 已提交
556
## featureAbility.disconnectAbility<sup>7+</sup>
W
wusongqing 已提交
557

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

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

W
wusongqing 已提交
562
**System capability**: SystemCapability.Ability.AbilityRuntime.FAModel
W
wusongqing 已提交
563

W
wusongqing 已提交
564
**Parameters**
W
wusongqing 已提交
565

W
wusongqing 已提交
566 567 568 569
| 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 已提交
570

W
wusongqing 已提交
571
**Example**
W
wusongqing 已提交
572 573

```javascript
W
wusongqing 已提交
574
import rpc from '@ohos.rpc'
W
wusongqing 已提交
575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597
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) => {
W
wusongqing 已提交
598
        console.log('featureAbilityTest DisConnectJsSameBundleName result errCode : ' + error.code + " data: " + data)
W
wusongqing 已提交
599 600 601 602
    },
);
```

W
wusongqing 已提交
603
## featureAbility.disconnectAbility<sup>7+</sup>
W
wusongqing 已提交
604

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

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

W
wusongqing 已提交
609
**System capability**: SystemCapability.Ability.AbilityRuntime.FAModel
W
wusongqing 已提交
610

W
wusongqing 已提交
611
**Parameters**
W
wusongqing 已提交
612

W
wusongqing 已提交
613 614 615
| Name        | Type    | Mandatory  | Description                     |
| ---------- | ------ | ---- | ----------------------- |
| connection | number | Yes   | ID of the Service ability to disconnect.|
W
wusongqing 已提交
616 617

**Return value**
W
wusongqing 已提交
618

W
wusongqing 已提交
619 620
| Type            | Description             |
| -------------- | --------------- |
W
wusongqing 已提交
621
| Promise\<void> | Promise used to return the result.|
W
wusongqing 已提交
622

W
wusongqing 已提交
623
**Example**
W
wusongqing 已提交
624 625

```javascript
W
wusongqing 已提交
626
import rpc from '@ohos.rpc'
W
wusongqing 已提交
627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647
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,
    },
);
W
wusongqing 已提交
648

W
wusongqing 已提交
649
featureAbility.disconnectAbility(connId).then((error,data) => {
W
wusongqing 已提交
650 651
    console.log('featureAbilityTest result errCode : ' + error.code + " data: " + data);
});
W
wusongqing 已提交
652 653
```

W
wusongqing 已提交
654 655 656 657 658 659 660 661 662 663 664

## featureAbility.getWindow<sup>7+</sup>

getWindow(callback: AsyncCallback\<window.Window>): void

Obtains the window corresponding to this ability. This method uses a callback to return the result.

**System capability**: SystemCapability.Ability.AbilityRuntime.FAModel

**Parameters**

W
wusongqing 已提交
665 666
| Name    | Type                         | Mandatory| Description                         |
| -------- | ----------------------------- | ---- | ----------------------------- |
W
wusongqing 已提交
667 668 669 670 671
| callback | AsyncCallback\<window.Window> | Yes  | Callback used to return the window.|

**Example**

```javascript
W
wusongqing 已提交
672
featureAbility.getWindow()
W
wusongqing 已提交
673 674 675 676 677 678 679 680 681 682 683 684
```

## featureAbility.getWindow<sup>7+</sup>

getWindow(): Promise\<window.Window>;

Obtains the window corresponding to this ability. This method uses a promise to return the result.

**System capability**: SystemCapability.Ability.AbilityRuntime.FAModel

**Return value**

W
wusongqing 已提交
685 686
| Type                   | Description                         |
| ----------------------- | ----------------------------- |
W
wusongqing 已提交
687 688 689 690 691
| Promise\<window.Window> | Promise used to return the window.|

**Example**

```javascript
W
wusongqing 已提交
692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779
featureAbility.getWindow().then((data) => {
  console.info("=============getWindowPromise========== " +  JSON.stringify(data)); 
});
```

## ConnectOptions.onConnect<sup>7+</sup>

onConnect(elementName: ElementName, remote: rpc.IRemoteObject): void;

Callback invoked when the connection is successful.

**System capability**: SystemCapability.Ability.AbilityRuntime.Core

**Parameters**

| Name         | Type               | Mandatory  | Description      |
| ----------- | ----------------- | ---- | -------- |
| elementName | ElementName       | Yes   | Element name.    |
| remote      | rpc.IRemoteObject | Yes   | RPC remote object.|

**Example**

```javascript
import rpc from '@ohos.rpc'
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: "",
        bundleName: "com.ix.ServiceAbility",
        abilityName: "ServiceAbilityA",
    },
    {
        onConnect: onConnectCallback,
        onDisconnect: onDisconnectCallback,
        onFailed: onFailedCallback,
    },
);
```

## ConnectOptions.onDisconnect<sup>7+</sup>

onDisconnect(elementName: ElementName): void;

Callback invoked when the connection fails.

**System capability**: SystemCapability.Ability.AbilityRuntime.Core

**Parameters**

| Name         | Type         | Mandatory  | Description  |
| ----------- | ----------- | ---- | ---- |
| elementName | ElementName | Yes   | Element name.|

**Example**

```javascript
import rpc from '@ohos.rpc'
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: "",
        bundleName: "com.ix.ServiceAbility",
        abilityName: "ServiceAbilityA",
    },
    {
        onConnect: onConnectCallback,
        onDisconnect: onDisconnectCallback,
        onFailed: onFailedCallback,
    },
);
W
wusongqing 已提交
780 781
```

W
wusongqing 已提交
782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826
## ConnectOptions.onFailed<sup>7+</sup>

onFailed(code: number): void;

Callback invoked when **connectAbility** fails to be called.

**System capability**: SystemCapability.Ability.AbilityRuntime.Core

**Parameters**

| Name  | Type    | Mandatory  | Description       |
| ---- | ------ | ---- | --------- |
| code | number | Yes   | Number type.|

**Example**

```javascript
import rpc from '@ohos.rpc'
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: "",
        bundleName: "com.ix.ServiceAbility",
        abilityName: "ServiceAbilityA",
    },
    {
        onConnect: onConnectCallback,
        onDisconnect: onDisconnectCallback,
        onFailed: onFailedCallback,
    },
);
```




W
wusongqing 已提交
827 828 829 830 831 832 833 834 835 836 837

## AbilityWindowConfiguration

The value is obtained through the **featureAbility.AbilityWindowConfiguration** API.

**Example**

```
featureAbility.AbilityWindowConfiguration.WINDOW_MODE_UNDEFINED
```

W
wusongqing 已提交
838 839 840 841 842 843 844 845 846
**System capability**: SystemCapability.Ability.AbilityRuntime.FAModel

| Name                                      | Name  | Description                                      |
| ---------------------------------------- | ---- | ---------------------------------------- |
| WINDOW_MODE_UNDEFINED<sup>7+</sup>       | 0    | The Page ability is in an undefined window display mode.|
| WINDOW_MODE_FULLSCREEN<sup>7+</sup>      | 1    | The Page ability is in full screen mode.   |
| WINDOW_MODE_SPLIT_PRIMARY<sup>7+</sup>   | 100  | The Page ability is displayed in the primary window when it is in split-screen mode.|
| WINDOW_MODE_SPLIT_SECONDARY<sup>7+</sup> | 101  | The Page ability is displayed in the secondary window when it is in split-screen mode.|
| WINDOW_MODE_FLOATING<sup>7+</sup>        | 102  | The Page ability is displayed in floating window mode.|
W
wusongqing 已提交
847 848 849 850 851 852 853 854 855 856 857 858 859 860


## AbilityStartSetting

The **AbilityStartSetting** attribute is an object defined as [key: string]: any. The key is a type of **AbilityStartSetting**, and the value is a type of **AbilityWindowConfiguration**.

The value is obtained through the **featureAbility.AbilityStartSetting** API.

**Example**

```
featureAbility.AbilityStartSetting.BOUNDS_KEY
```

W
wusongqing 已提交
861 862 863 864 865 866 867
**System capability**: SystemCapability.Ability.AbilityRuntime.FAModel

| Name                          | Name             | Description                                      |
| ---------------------------- | --------------- | ---------------------------------------- |
| BOUNDS_KEY<sup>7+</sup>      | "abilityBounds" | Ability window size.|
| WINDOW_MODE_KEY<sup>7+</sup> | "windowMode"    | Ability window display mode.|
| DISPLAY_ID_KEY<sup>7+</sup>  | "displayId"     | Display device ID.|
W
wusongqing 已提交
868 869 870 871 872

## ErrorCode

Enumerates error codes.

W
wusongqing 已提交
873 874 875 876 877 878 879 880
**System capability**: SystemCapability.Ability.AbilityRuntime.FAModel

| Variable                            | Value   | Description                                      |
| ------------------------------ | ---- | ---------------------------------------- |
| NO_ERROR<sup>7+</sup>          | 0    | No error occurs.|
| INVALID_PARAMETER<sup>7+</sup> | -1   | Invalid parameter.|
| ABILITY_NOT_FOUND<sup>7+</sup> | -2   | The ability is not found.|
| PERMISSION_DENY<sup>7+</sup>   | -3   | The request is denied.|
W
wusongqing 已提交
881 882 883 884 885 886


## DataAbilityOperationType

Enumerates operation types of the Data ability.

W
wusongqing 已提交
887 888 889 890 891 892 893 894
**System capability**: SystemCapability.Ability.AbilityRuntime.FAModel

| Variable                      | Value   | Description                                      |
| ------------------------ | ---- | ---------------------------------------- |
| TYPE_INSERT<sup>7+</sup> | 1    | Insert operation.|
| TYPE_UPDATE<sup>7+</sup> | 2    | Update operation.|
| TYPE_DELETE<sup>7+</sup> | 3    | Deletion operation.|
| TYPE_ASSERT<sup>7+</sup> | 4    | Assert operation.|
W
wusongqing 已提交
895 896 897



W
wusongqing 已提交
898
## AbilityResult
W
wusongqing 已提交
899

W
wusongqing 已提交
900 901
**System capability**: SystemCapability.Ability.AbilityBase

W
wusongqing 已提交
902 903 904 905
| Name                     | Readable/Writable| Type           | Mandatory  | Description                                   |
| ----------------------- | ---- | ------------- | ---- | ------------------------------------- |
| resultCode<sup>7+</sup> | Read-only  | number        | Yes   | Result code returned after the ability is destroyed. The feature for defining error-specific result codes is coming soon.|
| want<sup>7+</sup>       | 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 已提交
906

W
wusongqing 已提交
907
## StartAbilityParameter
W
wusongqing 已提交
908

W
wusongqing 已提交
909 910
**System capability**: SystemCapability.AbilityRuntime.FAModel

W
wusongqing 已提交
911 912 913 914
| Name                 | Readable/Writable| Type                  | Mandatory  | Description                                    |
| ------------------- | ---- | -------------------- | ---- | -------------------------------------- |
| 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 已提交
915

W
wusongqing 已提交
916

W
wusongqing 已提交
917
## Want
W
wusongqing 已提交
918

W
wusongqing 已提交
919 920
**System capability**: SystemCapability.Ability.AbilityBase

W
wusongqing 已提交
921 922 923 924 925 926 927 928 929 930 931 932 933
| 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 the **Want** object.                                        |
| entities                         | Read-only    | Array\<string>       | No  | List of entities.                                      |
| extensionAbilityName<sup>9+<sup> | Read-only    | string               | No  | Description of the Extension ability name in the **Want** object.                                  |
| extensionAbilityType<sup>9+<sup> | Read-only    | number               | No  | Description of the Extension ability type in the **Want** object.                                  |
W
wusongqing 已提交
934 935 936

## flags

W
wusongqing 已提交
937 938
**System capability**: SystemCapability.Ability.AbilityBase

W
wusongqing 已提交
939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955
| Name                                  | Name        | Description                                      |
| ------------------------------------ | ---------- | ---------------------------------------- |
| 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 in the **startAbility** API passed to [ohos.app.Context](js-apis-ability-context.md) and must be used together with **flag_ABILITY_NEW_MISSION**.|
| FLAG_ABILITY_NEW_MISSION             | 0x10000000 | Creates a mission on the historical mission stack.                      |
W
wusongqing 已提交
956
| FLAG_ABILITY_MISSION_TOP             | 0x20000000 | Starts the mission on the top of the existing mission stack; creates an ability instance if no mission exists.|