js-apis-featureAbility.md 34.5 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 37 38 39 40 41 42
featureAbility.startAbility(
        {
        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 156 157 158
            deviceId: "",
            bundleName: "com.example.featureabilitytest",
            abilityName: "com.example.featureabilitytest.MainAbility",
            uri:""
        },
    },
)
```

W
wusongqing 已提交
159
## featureAbility.startAbilityForResult<sup>7+</sup>
W
wusongqing 已提交
160

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

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

W
wusongqing 已提交
165
**System capability**: SystemCapability.Ability.AbilityRuntime.FAModel
W
wusongqing 已提交
166

W
wusongqing 已提交
167
**Parameters**
W
wusongqing 已提交
168

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

W
wusongqing 已提交
173
**Return value**
W
wusongqing 已提交
174

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

W
wusongqing 已提交
179
**Example**
W
wusongqing 已提交
180 181 182

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

W
wusongqing 已提交
215
## featureAbility.terminateSelfWithResult<sup>7+</sup>
W
wusongqing 已提交
216

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

W
wusongqing 已提交
219
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 已提交
220

W
wusongqing 已提交
221
**System capability**: SystemCapability.Ability.AbilityRuntime.FAModel
W
wusongqing 已提交
222

W
wusongqing 已提交
223
**Parameters**
W
wusongqing 已提交
224

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

W
wusongqing 已提交
230
**Example**
W
wusongqing 已提交
231 232 233

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

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

W
wusongqing 已提交
267
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 已提交
268

W
wusongqing 已提交
269
**System capability**: SystemCapability.Ability.AbilityRuntime.FAModel
W
wusongqing 已提交
270

W
wusongqing 已提交
271
**Parameters**
W
wusongqing 已提交
272

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

W
wusongqing 已提交
277
**Return value**
W
wusongqing 已提交
278

W
wusongqing 已提交
279 280
| Type            | Description             |
| -------------- | --------------- |
W
wusongqing 已提交
281
| Promise\<void> | Promise used to return the result.|
W
wusongqing 已提交
282

W
wusongqing 已提交
283
**Example**
W
wusongqing 已提交
284 285 286

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



W
wusongqing 已提交
320
## featureAbility.hasWindowFocus<sup>7+<sup>
W
wusongqing 已提交
321

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

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

W
wusongqing 已提交
326
**System capability**: SystemCapability.Ability.AbilityRuntime.FAModel
W
wusongqing 已提交
327

W
wusongqing 已提交
328
**Parameters**
W
wusongqing 已提交
329

W
wusongqing 已提交
330 331 332
| 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 已提交
333

W
wusongqing 已提交
334
**Example**
W
wusongqing 已提交
335 336 337 338 339 340 341 342

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



W
wusongqing 已提交
343
## featureAbility.hasWindowFocus<sup>7+<sup>
W
wusongqing 已提交
344

W
wusongqing 已提交
345
hasWindowFocus(): Promise\<boolean>
W
wusongqing 已提交
346

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

W
wusongqing 已提交
349
**System capability**: SystemCapability.Ability.AbilityRuntime.FAModel
W
wusongqing 已提交
350

W
wusongqing 已提交
351
**Return value**
W
wusongqing 已提交
352

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

W
wusongqing 已提交
357
**Example**
W
wusongqing 已提交
358 359 360

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



W
wusongqing 已提交
368
## featureAbility.getWant
W
wusongqing 已提交
369

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

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

W
wusongqing 已提交
374
**System capability**: SystemCapability.Ability.AbilityRuntime.FAModel
W
wusongqing 已提交
375

W
wusongqing 已提交
376
**Parameters**
W
wusongqing 已提交
377

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

W
wusongqing 已提交
382
**Example**
W
wusongqing 已提交
383 384 385 386 387 388 389 390

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



W
wusongqing 已提交
391
## featureAbility.getWant
W
wusongqing 已提交
392

W
wusongqing 已提交
393
getWant(): Promise\<Want>
W
wusongqing 已提交
394

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

W
wusongqing 已提交
397
**System capability**: SystemCapability.Ability.AbilityRuntime.FAModel
W
wusongqing 已提交
398

W
wusongqing 已提交
399
**Return value**
W
wusongqing 已提交
400

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

W
wusongqing 已提交
405
**Example**
W
wusongqing 已提交
406 407 408

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

W
wusongqing 已提交
414
## featureAbility.getContext
W
wusongqing 已提交
415

W
wusongqing 已提交
416
getContext(): Context
W
wusongqing 已提交
417

W
wusongqing 已提交
418
Obtains the application context.
W
wusongqing 已提交
419

W
wusongqing 已提交
420
**System capability**: SystemCapability.Ability.AbilityRuntime.FAModel
W
wusongqing 已提交
421

W
wusongqing 已提交
422
**Return value**
W
wusongqing 已提交
423

W
wusongqing 已提交
424 425
| Type     | Description        |
| ------- | ---------- |
W
wusongqing 已提交
426
| Context | Application context returned.|
W
wusongqing 已提交
427

W
wusongqing 已提交
428
**Example**
W
wusongqing 已提交
429 430 431 432 433 434 435 436 437

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



W
wusongqing 已提交
438
## featureAbility.terminateSelf<sup>7+</sup>
W
wusongqing 已提交
439

W
wusongqing 已提交
440
terminateSelf(callback: AsyncCallback\<void>): void
W
wusongqing 已提交
441

W
wusongqing 已提交
442
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 已提交
443

W
wusongqing 已提交
444
**System capability**: SystemCapability.Ability.AbilityRuntime.FAModel
W
wusongqing 已提交
445

W
wusongqing 已提交
446
**Parameters**
W
wusongqing 已提交
447

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

W
wusongqing 已提交
452
**Example**
W
wusongqing 已提交
453 454 455 456 457 458 459 460

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



W
wusongqing 已提交
461
## featureAbility.terminateSelf<sup>7+</sup>
W
wusongqing 已提交
462

W
wusongqing 已提交
463
terminateSelf(): Promise\<void>
W
wusongqing 已提交
464

W
wusongqing 已提交
465
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 已提交
466

W
wusongqing 已提交
467
**System capability**: SystemCapability.Ability.AbilityRuntime.FAModel
W
wusongqing 已提交
468

W
wusongqing 已提交
469
**Return value**
W
wusongqing 已提交
470

W
wusongqing 已提交
471 472
| Type            | Description              |
| -------------- | ---------------- |
W
wusongqing 已提交
473
| Promise\<void> | Promise used to return the result.|
W
wusongqing 已提交
474

W
wusongqing 已提交
475
**Example**
W
wusongqing 已提交
476 477 478

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

W
wusongqing 已提交
483
## featureAbility.connectAbility<sup>7+</sup>
W
wusongqing 已提交
484

W
wusongqing 已提交
485
connectAbility(request: Want, options:ConnectOptions): number
W
wusongqing 已提交
486

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

W
wusongqing 已提交
489
**System capability**: SystemCapability.Ability.AbilityRuntime.FAModel
W
wusongqing 已提交
490

W
wusongqing 已提交
491
**Parameters**
W
wusongqing 已提交
492

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

W
wusongqing 已提交
498
Want
W
wusongqing 已提交
499

W
wusongqing 已提交
500 501
**System capability**: SystemCapability.Ability.AbilityBase

W
wusongqing 已提交
502 503 504 505 506
| 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 已提交
507

W
wusongqing 已提交
508
ConnectOptions
W
wusongqing 已提交
509

W
wusongqing 已提交
510 511
**System capability**: SystemCapability.Ability.AbilityRuntime.Core

W
wusongqing 已提交
512 513 514 515 516
| 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 已提交
517

W
wusongqing 已提交
518
**Return value**
W
wusongqing 已提交
519

W
wusongqing 已提交
520 521
| Type    | Description                  |
| ------ | -------------------- |
W
wusongqing 已提交
522
| number | Returns the ID of the Service ability connected.|
W
wusongqing 已提交
523

W
wusongqing 已提交
524
**Example**
W
wusongqing 已提交
525 526

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

W
wusongqing 已提交
552
## featureAbility.disconnectAbility<sup>7+</sup>
W
wusongqing 已提交
553

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

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

W
wusongqing 已提交
558
**System capability**: SystemCapability.Ability.AbilityRuntime.FAModel
W
wusongqing 已提交
559

W
wusongqing 已提交
560
**Parameters**
W
wusongqing 已提交
561

W
wusongqing 已提交
562 563 564 565
| 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 已提交
566

W
wusongqing 已提交
567
**Example**
W
wusongqing 已提交
568 569

```javascript
W
wusongqing 已提交
570
import rpc from '@ohos.rpc'
W
wusongqing 已提交
571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598
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 已提交
599
## featureAbility.disconnectAbility<sup>7+</sup>
W
wusongqing 已提交
600

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

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

W
wusongqing 已提交
605
**System capability**: SystemCapability.Ability.AbilityRuntime.FAModel
W
wusongqing 已提交
606

W
wusongqing 已提交
607
**Parameters**
W
wusongqing 已提交
608

W
wusongqing 已提交
609 610 611
| Name        | Type    | Mandatory  | Description                     |
| ---------- | ------ | ---- | ----------------------- |
| connection | number | Yes   | ID of the Service ability to disconnect.|
W
wusongqing 已提交
612 613

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

W
wusongqing 已提交
615 616
| Type            | Description             |
| -------------- | --------------- |
W
wusongqing 已提交
617
| Promise\<void> | Promise used to return the result.|
W
wusongqing 已提交
618

W
wusongqing 已提交
619
**Example**
W
wusongqing 已提交
620 621

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

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

W
wusongqing 已提交
650 651 652 653 654 655 656 657 658 659 660

## 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 已提交
661 662
| Name    | Type                         | Mandatory| Description                         |
| -------- | ----------------------------- | ---- | ----------------------------- |
W
wusongqing 已提交
663 664 665 666 667
| callback | AsyncCallback\<window.Window> | Yes  | Callback used to return the window.|

**Example**

```javascript
W
wusongqing 已提交
668
featureAbility.getWindow()
W
wusongqing 已提交
669 670 671 672 673 674 675 676 677 678 679 680
```

## 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 已提交
681 682
| Type                   | Description                         |
| ----------------------- | ----------------------------- |
W
wusongqing 已提交
683 684 685 686 687
| Promise\<window.Window> | Promise used to return the window.|

**Example**

```javascript
W
wusongqing 已提交
688 689 690 691 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
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 已提交
776 777
```

W
wusongqing 已提交
778 779 780 781 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
## 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 已提交
823 824 825 826 827 828 829 830 831 832 833

## AbilityWindowConfiguration

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

**Example**

```
featureAbility.AbilityWindowConfiguration.WINDOW_MODE_UNDEFINED
```

W
wusongqing 已提交
834 835 836 837 838 839 840 841 842
**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 已提交
843 844 845 846 847 848 849 850 851 852 853 854 855 856


## 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 已提交
857 858 859 860 861 862 863
**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 已提交
864 865 866 867 868

## ErrorCode

Enumerates error codes.

W
wusongqing 已提交
869 870 871 872 873 874 875 876
**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 已提交
877 878 879 880 881 882


## DataAbilityOperationType

Enumerates operation types of the Data ability.

W
wusongqing 已提交
883 884 885 886 887 888 889 890
**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 已提交
891 892 893



W
wusongqing 已提交
894
## AbilityResult
W
wusongqing 已提交
895

W
wusongqing 已提交
896 897
**System capability**: SystemCapability.Ability.AbilityBase

W
wusongqing 已提交
898 899 900 901
| 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 已提交
902

W
wusongqing 已提交
903
## StartAbilityParameter
W
wusongqing 已提交
904

W
wusongqing 已提交
905 906
**System capability**: SystemCapability.AbilityRuntime.FAModel

W
wusongqing 已提交
907 908 909 910
| 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 已提交
911

W
wusongqing 已提交
912

W
wusongqing 已提交
913
## Want
W
wusongqing 已提交
914

W
wusongqing 已提交
915 916
**System capability**: SystemCapability.Ability.AbilityBase

W
wusongqing 已提交
917 918 919 920 921 922 923 924 925 926 927 928 929
| 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 已提交
930 931 932

## flags

W
wusongqing 已提交
933 934
**System capability**: SystemCapability.Ability.AbilityBase

W
wusongqing 已提交
935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951
| 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 已提交
952
| FLAG_ABILITY_MISSION_TOP             | 0x20000000 | Starts the mission on the top of the existing mission stack; creates an ability instance if no mission exists.|