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

W
wusongqing 已提交
3
> **NOTE**<br/>
W
wusongqing 已提交
4 5
> 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

20
Starts an ability. This API 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
| Name       | Type                                      | Mandatory  | Description            |
| --------- | ---------------------------------------- | ---- | -------------- |
W
wusongqing 已提交
28
| parameter | [StartAbilityParameter](#startabilityparameter) | Yes   | Ability to start.|
W
wusongqing 已提交
29
| 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
            deviceId: "",
W
wusongqing 已提交
45 46
            bundleName: "com.example.myapplication",
            /* In the FA model, abilityName consists of package and ability name. */
W
wusongqing 已提交
47
            abilityName: "com.example.entry.secondAbility",
W
wusongqing 已提交
48 49 50
            uri: ""
        },
    },
W
wusongqing 已提交
51
);
W
wusongqing 已提交
52 53 54 55
```



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

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

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

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

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

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

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

```javascript
import featureAbility from '@ohos.ability.featureAbility'
W
wusongqing 已提交
74
import wantConstant from '@ohos.ability.wantConstant'
W
wusongqing 已提交
75 76 77 78 79 80 81
featureAbility.startAbility(
    {
        want:
        {
            action: "action.system.home",
            entities: ["entity.system.home"],
            type: "MIMETYPE",
W
wusongqing 已提交
82 83
			flags: wantConstant.Flags.FLAG_AUTH_READ_URI_PERMISSION,
            deviceId: "",
W
wusongqing 已提交
84 85 86
            bundleName: "com.example.myapplication",
            /* In the FA model, abilityName consists of package and ability name. */
            abilityName: "com.example.entry.secondAbility",
W
wusongqing 已提交
87 88 89
            uri: ""
        },
    }
W
wusongqing 已提交
90
).then((data) => {
W
wusongqing 已提交
91 92 93 94
	console.info("==========================>startAbility=======================>");
});
```

W
wusongqing 已提交
95
## featureAbility.acquireDataAbilityHelper<sup>7+</sup>
W
wusongqing 已提交
96

W
wusongqing 已提交
97
acquireDataAbilityHelper(uri: string): DataAbilityHelper
W
wusongqing 已提交
98

W
wusongqing 已提交
99
Obtains a **dataAbilityHelper** object.
W
wusongqing 已提交
100

W
wusongqing 已提交
101
**System capability**: SystemCapability.Ability.AbilityRuntime.FAModel
W
wusongqing 已提交
102

W
wusongqing 已提交
103
**Parameters**
W
wusongqing 已提交
104

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

W
wusongqing 已提交
109
**Return value**
W
wusongqing 已提交
110

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

W
wusongqing 已提交
115
**Example**
W
wusongqing 已提交
116 117 118 119

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

W
wusongqing 已提交
124
## featureAbility.startAbilityForResult<sup>7+</sup>
W
wusongqing 已提交
125

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

128
Starts an ability. This API uses a callback to return the execution result when the ability is destroyed.
W
wusongqing 已提交
129

W
wusongqing 已提交
130
**System capability**: SystemCapability.Ability.AbilityRuntime.FAModel
W
wusongqing 已提交
131

W
wusongqing 已提交
132
**Parameters**
W
wusongqing 已提交
133

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

W
wusongqing 已提交
139
**Example**
W
wusongqing 已提交
140 141

```javascript
W
wusongqing 已提交
142
import featureAbility from '@ohos.ability.featureAbility';
W
wusongqing 已提交
143
import wantConstant from '@ohos.ability.wantConstant'
W
wusongqing 已提交
144 145 146 147 148 149 150
featureAbility.startAbilityForResult(
   {
        want:
        {
            action: "action.system.home",
            entities: ["entity.system.home"],
            type: "MIMETYPE",
W
wusongqing 已提交
151
            flags: wantConstant.Flags.FLAG_AUTH_READ_URI_PERMISSION,
W
wusongqing 已提交
152
            deviceId: "",
W
wusongqing 已提交
153 154 155
            bundleName: "com.example.myapplication",
            /* In the FA model, abilityName consists of package and ability name. */
            abilityName: "com.example.entry.secondAbility",
W
wusongqing 已提交
156 157 158
            uri:""
        },
    },
W
wusongqing 已提交
159
    (err, data) => {
W
wusongqing 已提交
160
        console.info("err: " + JSON.stringify(err) + "data: " + JSON.stringify(data))
W
wusongqing 已提交
161
    }
W
wusongqing 已提交
162 163 164
)
```

W
wusongqing 已提交
165
## featureAbility.startAbilityForResult<sup>7+</sup>
W
wusongqing 已提交
166

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

169
Starts an ability. This API uses a promise to return the execution result when the ability is destroyed.
W
wusongqing 已提交
170

W
wusongqing 已提交
171
**System capability**: SystemCapability.Ability.AbilityRuntime.FAModel
W
wusongqing 已提交
172

W
wusongqing 已提交
173
**Parameters**
W
wusongqing 已提交
174

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

W
wusongqing 已提交
179
**Return value**
W
wusongqing 已提交
180

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

W
wusongqing 已提交
185
**Example**
W
wusongqing 已提交
186 187

```javascript
W
wusongqing 已提交
188
import featureAbility from '@ohos.ability.featureAbility';
W
wusongqing 已提交
189
import wantConstant from '@ohos.ability.wantConstant'
W
wusongqing 已提交
190 191 192 193 194 195 196
featureAbility.startAbilityForResult(
    {
        want:
        {
            action: "action.system.home",
            entities: ["entity.system.home"],
            type: "MIMETYPE",
W
wusongqing 已提交
197
            flags: wantConstant.Flags.FLAG_AUTH_READ_URI_PERMISSION,
W
wusongqing 已提交
198
            deviceId: "",
W
wusongqing 已提交
199 200 201
            bundleName: "com.example.myapplication",
            /* In the FA model, abilityName consists of package and ability name. */
            abilityName: "com.example.entry.secondAbility",
W
wusongqing 已提交
202 203 204 205 206 207 208 209 210 211 212 213 214 215 216
            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 已提交
217
).then((data) => {
W
wusongqing 已提交
218 219 220 221
    console.info("==========================>startAbilityForResult=======================>");
});
```

W
wusongqing 已提交
222
## featureAbility.terminateSelfWithResult<sup>7+</sup>
W
wusongqing 已提交
223

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

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

W
wusongqing 已提交
228
**System capability**: SystemCapability.Ability.AbilityRuntime.FAModel
W
wusongqing 已提交
229

W
wusongqing 已提交
230
**Parameters**
W
wusongqing 已提交
231

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

W
wusongqing 已提交
237
**Example**
W
wusongqing 已提交
238 239 240

```javascript
import featureAbility from '@ohos.ability.featureAbility'
W
wusongqing 已提交
241
import wantConstant from '@ohos.ability.wantConstant'
W
wusongqing 已提交
242 243 244 245 246 247 248 249
featureAbility.terminateSelfWithResult(
    {
        resultCode: 1,
        want:
        {
            action: "action.system.home",
            entities: ["entity.system.home"],
            type: "MIMETYPE",
W
wusongqing 已提交
250
            flags: wantConstant.Flags.FLAG_AUTH_READ_URI_PERMISSION,
W
wusongqing 已提交
251
            deviceId: "",
W
wusongqing 已提交
252 253 254
            bundleName: "com.example.myapplication",
            /* In the FA model, abilityName consists of package and ability name. */
            abilityName: "com.example.entry.secondAbility",
W
wusongqing 已提交
255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270
            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 已提交
271
## featureAbility.terminateSelfWithResult<sup>7+</sup>
W
wusongqing 已提交
272

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

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

W
wusongqing 已提交
277
**System capability**: SystemCapability.Ability.AbilityRuntime.FAModel
W
wusongqing 已提交
278

W
wusongqing 已提交
279
**Parameters**
W
wusongqing 已提交
280

W
wusongqing 已提交
281 282
| Name       | Type                             | Mandatory  | Description           |
| --------- | ------------------------------- | ---- | ------------- |
W
wusongqing 已提交
283
| parameter | [AbilityResult](#abilityresult) | Yes   | Ability to start.|
W
wusongqing 已提交
284

W
wusongqing 已提交
285
**Return value**
W
wusongqing 已提交
286

W
wusongqing 已提交
287 288
| Type            | Description             |
| -------------- | --------------- |
W
wusongqing 已提交
289
| Promise\<void> | Promise used to return the result.|
W
wusongqing 已提交
290

W
wusongqing 已提交
291
**Example**
W
wusongqing 已提交
292 293

```javascript
W
wusongqing 已提交
294
import featureAbility from '@ohos.ability.featureAbility';
W
wusongqing 已提交
295
import wantConstant from '@ohos.ability.wantConstant'
W
wusongqing 已提交
296 297 298 299 300 301 302 303
featureAbility.terminateSelfWithResult(
    {
        resultCode: 1,
        want:
        {
            action: "action.system.home",
            entities: ["entity.system.home"],
            type: "MIMETYPE",
W
wusongqing 已提交
304
            flags: wantConstant.Flags.FLAG_AUTH_READ_URI_PERMISSION,
W
wusongqing 已提交
305
            deviceId: "",
W
wusongqing 已提交
306 307 308
            bundleName: "com.example.myapplication",
            /* In the FA model, abilityName consists of package and ability name. */
            abilityName: "com.example.entry.secondAbility",
W
wusongqing 已提交
309 310 311 312 313 314 315 316 317 318 319 320 321
            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 已提交
322
).then((data) => {
W
wusongqing 已提交
323 324 325 326 327 328
    console.info("==========================>terminateSelfWithResult=======================>");
});
```



W
wusongqing 已提交
329
## featureAbility.hasWindowFocus<sup>7+<sup>
W
wusongqing 已提交
330

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

333
Checks whether the main window of this ability has the focus. This API uses a callback to return the result.
W
wusongqing 已提交
334

W
wusongqing 已提交
335
**System capability**: SystemCapability.Ability.AbilityRuntime.FAModel
W
wusongqing 已提交
336

W
wusongqing 已提交
337
**Parameters**
W
wusongqing 已提交
338

W
wusongqing 已提交
339 340
| Name      | Type                     | Mandatory  | Description                                      |
| -------- | ----------------------- | ---- | ---------------------------------------- |
W
wusongqing 已提交
341
| 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 已提交
342

W
wusongqing 已提交
343
**Example**
W
wusongqing 已提交
344 345

```javascript
W
wusongqing 已提交
346
import featureAbility from '@ohos.ability.featureAbility';
W
wusongqing 已提交
347 348 349 350 351
featureAbility.hasWindowFocus()
```



W
wusongqing 已提交
352
## featureAbility.hasWindowFocus<sup>7+<sup>
W
wusongqing 已提交
353

W
wusongqing 已提交
354
hasWindowFocus(): Promise\<boolean>
W
wusongqing 已提交
355

356
Checks whether the main window of this ability has the focus. This API uses a promise to return the result.
W
wusongqing 已提交
357

W
wusongqing 已提交
358
**System capability**: SystemCapability.Ability.AbilityRuntime.FAModel
W
wusongqing 已提交
359

W
wusongqing 已提交
360
**Return value**
W
wusongqing 已提交
361

W
wusongqing 已提交
362 363
| Type               | Description                                   |
| ----------------- | ------------------------------------- |
W
wusongqing 已提交
364
| Promise\<boolean> | Returns **true** if the main window of this ability has the focus; returns **false** otherwise.|
W
wusongqing 已提交
365

W
wusongqing 已提交
366
**Example**
W
wusongqing 已提交
367 368 369

```javascript
import featureAbility from '@ohos.ability.featureability';
W
wusongqing 已提交
370
featureAbility.hasWindowFocus().then((data) => {
W
wusongqing 已提交
371 372 373 374 375 376
    console.info("==========================>hasWindowFocus=======================>");
});
```



W
wusongqing 已提交
377
## featureAbility.getWant
W
wusongqing 已提交
378

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

381
Obtains the **Want** object sent from this ability. This API uses a callback to return the result.
W
wusongqing 已提交
382

W
wusongqing 已提交
383
**System capability**: SystemCapability.Ability.AbilityRuntime.FAModel
W
wusongqing 已提交
384

W
wusongqing 已提交
385
**Parameters**
W
wusongqing 已提交
386

W
wusongqing 已提交
387 388
| Name      | Type                           | Mandatory  | Description       |
| -------- | ----------------------------- | ---- | --------- |
W
wusongqing 已提交
389
| callback | AsyncCallback\<[Want](js-apis-application-Want.md)> | Yes   | Callback used to return the result.|
W
wusongqing 已提交
390

W
wusongqing 已提交
391
**Example**
W
wusongqing 已提交
392 393

```javascript
W
wusongqing 已提交
394
import featureAbility from '@ohos.ability.featureAbility';
W
wusongqing 已提交
395 396 397 398 399
featureAbility.getWant()
```



W
wusongqing 已提交
400
## featureAbility.getWant
W
wusongqing 已提交
401

W
wusongqing 已提交
402
getWant(): Promise\<Want>
W
wusongqing 已提交
403

404
Obtains the **Want** object sent from this ability. This API uses a promise to return the result.
W
wusongqing 已提交
405

W
wusongqing 已提交
406
**System capability**: SystemCapability.Ability.AbilityRuntime.FAModel
W
wusongqing 已提交
407

W
wusongqing 已提交
408
**Return value**
W
wusongqing 已提交
409

W
wusongqing 已提交
410 411
| Type                     | Description              |
| ----------------------- | ---------------- |
W
wusongqing 已提交
412
| Promise\<[Want](js-apis-application-Want.md)> | Promise used to return the result.|
W
wusongqing 已提交
413

W
wusongqing 已提交
414
**Example**
W
wusongqing 已提交
415 416

```javascript
W
wusongqing 已提交
417
import featureAbility from '@ohos.ability.featureAbility';
W
wusongqing 已提交
418
featureAbility.getWant().then((data) => {
W
wusongqing 已提交
419
	console.info("==========================>getWantCallBack=======================>");
W
wusongqing 已提交
420 421 422
});
```

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

W
wusongqing 已提交
425
getContext(): Context
W
wusongqing 已提交
426

W
wusongqing 已提交
427
Obtains the application context.
W
wusongqing 已提交
428

W
wusongqing 已提交
429
**System capability**: SystemCapability.Ability.AbilityRuntime.FAModel
W
wusongqing 已提交
430

W
wusongqing 已提交
431
**Return value**
W
wusongqing 已提交
432

W
wusongqing 已提交
433 434
| Type     | Description        |
| ------- | ---------- |
W
wusongqing 已提交
435
| Context | Application context returned.|
W
wusongqing 已提交
436

W
wusongqing 已提交
437
**Example**
W
wusongqing 已提交
438 439

```javascript
W
wusongqing 已提交
440
import featureAbility from '@ohos.ability.featureAbility';
W
wusongqing 已提交
441 442 443 444 445 446
var context = featureAbility.getContext()
context.getBundleName()
```



W
wusongqing 已提交
447
## featureAbility.terminateSelf<sup>7+</sup>
W
wusongqing 已提交
448

W
wusongqing 已提交
449
terminateSelf(callback: AsyncCallback\<void>): void
W
wusongqing 已提交
450

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

W
wusongqing 已提交
453
**System capability**: SystemCapability.Ability.AbilityRuntime.FAModel
W
wusongqing 已提交
454

W
wusongqing 已提交
455
**Parameters**
W
wusongqing 已提交
456

W
wusongqing 已提交
457 458
| Name      | Type                  | Mandatory  | Description      |
| -------- | -------------------- | ---- | -------- |
W
wusongqing 已提交
459
| callback | AsyncCallback\<void> | Yes   | Callback used to return the result.|
W
wusongqing 已提交
460

W
wusongqing 已提交
461
**Example**
W
wusongqing 已提交
462 463

```javascript
W
wusongqing 已提交
464
import featureAbility from '@ohos.ability.featureAbility';
W
wusongqing 已提交
465 466 467 468 469
featureAbility.terminateSelf()
```



W
wusongqing 已提交
470
## featureAbility.terminateSelf<sup>7+</sup>
W
wusongqing 已提交
471

W
wusongqing 已提交
472
terminateSelf(): Promise\<void>
W
wusongqing 已提交
473

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

W
wusongqing 已提交
476
**System capability**: SystemCapability.Ability.AbilityRuntime.FAModel
W
wusongqing 已提交
477

W
wusongqing 已提交
478
**Return value**
W
wusongqing 已提交
479

W
wusongqing 已提交
480 481
| Type            | Description              |
| -------------- | ---------------- |
W
wusongqing 已提交
482
| Promise\<void> | Promise used to return the result.|
W
wusongqing 已提交
483

W
wusongqing 已提交
484
**Example**
W
wusongqing 已提交
485 486

```javascript
W
wusongqing 已提交
487
import featureAbility from '@ohos.ability.featureAbility';
W
wusongqing 已提交
488 489
featureAbility.terminateSelf().then((data) => {
    console.info("==========================>terminateSelfCallBack=======================>");
W
wusongqing 已提交
490 491 492
});
```

W
wusongqing 已提交
493
## featureAbility.connectAbility<sup>7+</sup>
W
wusongqing 已提交
494

W
wusongqing 已提交
495
connectAbility(request: Want, options:ConnectOptions): number
W
wusongqing 已提交
496

497
Connects this ability to a specific Service ability. This API uses a callback to return the result.
W
wusongqing 已提交
498

W
wusongqing 已提交
499
**System capability**: SystemCapability.Ability.AbilityRuntime.FAModel
W
wusongqing 已提交
500

W
wusongqing 已提交
501
**Parameters**
W
wusongqing 已提交
502

W
wusongqing 已提交
503 504
| Name     | Type            | Mandatory  | Description                   |
| ------- | -------------- | ---- | --------------------- |
W
wusongqing 已提交
505
| request | [Want](js-apis-application-Want.md)  | Yes   | Service ability to connect.|
W
wusongqing 已提交
506
| options | ConnectOptions | Yes   | Callback used to return the result.            |
W
wusongqing 已提交
507

W
wusongqing 已提交
508
Want
W
wusongqing 已提交
509

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

W
wusongqing 已提交
512 513
| Name         | Readable/Writable| Type    | Mandatory  | Description                                      |
| ----------- | ---- | ------ | ---- | ---------------------------------------- |
W
wusongqing 已提交
514
| deviceId    | Read-only  | string | No   | Device ID of the Service ability to connect. The default value is the local device ID.|
W
wusongqing 已提交
515 516
| 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 已提交
517

W
wusongqing 已提交
518
ConnectOptions
W
wusongqing 已提交
519

W
wusongqing 已提交
520 521
**System capability**: SystemCapability.Ability.AbilityRuntime.Core

W
wusongqing 已提交
522 523 524 525
| 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.              |
W
wusongqing 已提交
526
| onFailed     | Read-only  | function | Yes   | Callback invoked when **connectAbility** fails to be called.|
W
wusongqing 已提交
527

W
wusongqing 已提交
528
**Return value**
W
wusongqing 已提交
529

W
wusongqing 已提交
530 531
| Type    | Description                  |
| ------ | -------------------- |
W
wusongqing 已提交
532
| number | Returns the ID of the Service ability connected.|
W
wusongqing 已提交
533

W
wusongqing 已提交
534
**Example**
W
wusongqing 已提交
535 536

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

W
wusongqing 已提交
562
## featureAbility.disconnectAbility<sup>7+</sup>
W
wusongqing 已提交
563

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

566
Disconnects this ability from a specific Service ability. This API uses a callback to return the result.
W
wusongqing 已提交
567

W
wusongqing 已提交
568
**System capability**: SystemCapability.Ability.AbilityRuntime.FAModel
W
wusongqing 已提交
569

W
wusongqing 已提交
570
**Parameters**
W
wusongqing 已提交
571

W
wusongqing 已提交
572 573
| Name        | Type                  | Mandatory  | Description                     |
| ---------- | -------------------- | ---- | ----------------------- |
W
wusongqing 已提交
574
| connection | number               | Yes   | ID of the Service ability to disconnect.|
W
wusongqing 已提交
575
| callback   | AsyncCallback\<void> | Yes   | Callback used to return the result.               |
W
wusongqing 已提交
576

W
wusongqing 已提交
577
**Example**
W
wusongqing 已提交
578 579

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

W
wusongqing 已提交
609
## featureAbility.disconnectAbility<sup>7+</sup>
W
wusongqing 已提交
610

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

613
Disconnects this ability from a specific Service ability. This API uses a promise to return the result.
W
wusongqing 已提交
614

W
wusongqing 已提交
615
**System capability**: SystemCapability.Ability.AbilityRuntime.FAModel
W
wusongqing 已提交
616

W
wusongqing 已提交
617
**Parameters**
W
wusongqing 已提交
618

W
wusongqing 已提交
619 620
| Name        | Type    | Mandatory  | Description                     |
| ---------- | ------ | ---- | ----------------------- |
W
wusongqing 已提交
621
| connection | number | Yes   | ID of the Service ability to disconnect.|
W
wusongqing 已提交
622 623

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

W
wusongqing 已提交
625 626
| Type            | Description             |
| -------------- | --------------- |
W
wusongqing 已提交
627
| Promise\<void> | Promise used to return the result.|
W
wusongqing 已提交
628

W
wusongqing 已提交
629
**Example**
W
wusongqing 已提交
630 631

```javascript
W
wusongqing 已提交
632
import rpc from '@ohos.rpc'
W
wusongqing 已提交
633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653
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 已提交
654

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

W
wusongqing 已提交
660 661 662 663 664

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

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

665
Obtains the window corresponding to this ability. This API uses a callback to return the result.
W
wusongqing 已提交
666 667 668 669 670

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

**Parameters**

W
wusongqing 已提交
671 672
| Name    | Type                         | Mandatory| Description                         |
| -------- | ----------------------------- | ---- | ----------------------------- |
W
wusongqing 已提交
673
| callback | AsyncCallback\<window.Window> | Yes  | Callback used to return the window.|
W
wusongqing 已提交
674 675 676 677

**Example**

```javascript
W
wusongqing 已提交
678
featureAbility.getWindow()
W
wusongqing 已提交
679 680 681 682 683 684
```

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

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

685
Obtains the window corresponding to this ability. This API uses a promise to return the result.
W
wusongqing 已提交
686 687 688 689 690

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

**Return value**

W
wusongqing 已提交
691 692
| Type                   | Description                         |
| ----------------------- | ----------------------------- |
W
wusongqing 已提交
693
| Promise\<window.Window> | Promise used to return the window.|
W
wusongqing 已提交
694 695 696 697

**Example**

```javascript
W
wusongqing 已提交
698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715
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.    |
W
wusongqing 已提交
716
| remote      | rpc.IRemoteObject | Yes   | RPC remote object.|
W
wusongqing 已提交
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

**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  |
| ----------- | ----------- | ---- | ---- |
W
wusongqing 已提交
758
| elementName | ElementName | Yes   | Element name.|
W
wusongqing 已提交
759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785

**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 已提交
786 787
```

W
wusongqing 已提交
788 789 790 791 792 793 794 795 796 797 798 799
## 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       |
| ---- | ------ | ---- | --------- |
W
wusongqing 已提交
800
| code | number | Yes   | Number type.|
W
wusongqing 已提交
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 827 828 829 830 831 832

**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 已提交
833 834 835 836 837 838 839 840 841 842 843

## AbilityWindowConfiguration

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

**Example**

```
featureAbility.AbilityWindowConfiguration.WINDOW_MODE_UNDEFINED
```

W
wusongqing 已提交
844 845 846 847
**System capability**: SystemCapability.Ability.AbilityRuntime.FAModel

| Name                                      | Name  | Description                                      |
| ---------------------------------------- | ---- | ---------------------------------------- |
W
wusongqing 已提交
848
| WINDOW_MODE_UNDEFINED<sup>7+</sup>       | 0    | The Page ability is in an undefined window display mode.|
W
wusongqing 已提交
849
| WINDOW_MODE_FULLSCREEN<sup>7+</sup>      | 1    | The Page ability is in full screen mode.   |
W
wusongqing 已提交
850 851 852
| 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 已提交
853 854 855 856 857 858 859 860 861 862 863 864 865 866


## 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 已提交
867 868 869 870
**System capability**: SystemCapability.Ability.AbilityRuntime.FAModel

| Name                          | Name             | Description                                      |
| ---------------------------- | --------------- | ---------------------------------------- |
W
wusongqing 已提交
871 872 873
| 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 已提交
874 875 876 877 878

## ErrorCode

Enumerates error codes.

W
wusongqing 已提交
879 880 881 882
**System capability**: SystemCapability.Ability.AbilityRuntime.FAModel

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


## DataAbilityOperationType

Enumerates operation types of the Data ability.

W
wusongqing 已提交
893 894 895 896
**System capability**: SystemCapability.Ability.AbilityRuntime.FAModel

| Variable                      | Value   | Description                                      |
| ------------------------ | ---- | ---------------------------------------- |
W
wusongqing 已提交
897 898 899 900
| 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 已提交
901 902 903



W
wusongqing 已提交
904
## AbilityResult
W
wusongqing 已提交
905

W
wusongqing 已提交
906 907
**System capability**: SystemCapability.Ability.AbilityBase

W
wusongqing 已提交
908 909
| Name                     | Readable/Writable| Type           | Mandatory  | Description                                   |
| ----------------------- | ---- | ------------- | ---- | ------------------------------------- |
W
wusongqing 已提交
910 911
| 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](js-apis-application-Want.md) | No   | Data returned after the ability is destroyed. You can define the data to be returned. This parameter can be **null**. |
W
wusongqing 已提交
912

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

W
wusongqing 已提交
915 916
**System capability**: SystemCapability.AbilityRuntime.FAModel

W
wusongqing 已提交
917 918
| Name                 | Readable/Writable| Type                  | Mandatory  | Description                                    |
| ------------------- | ---- | -------------------- | ---- | -------------------------------------- |
W
wusongqing 已提交
919 920
| want                | Read-only  | [Want](js-apis-application-Want.md)        | 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 已提交
921 922 923

## flags

W
wusongqing 已提交
924 925
**System capability**: SystemCapability.Ability.AbilityBase

W
wusongqing 已提交
926
| Name                                  | Value     | Description                                      |
W
wusongqing 已提交
927 928 929 930 931 932 933 934 935 936 937 938 939 940
| ------------------------------------ | ---------- | ---------------------------------------- |
| 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.                      |
W
wusongqing 已提交
941
| 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**.|
W
wusongqing 已提交
942
| FLAG_ABILITY_NEW_MISSION             | 0x10000000 | Creates a mission on the historical mission stack.                      |
W
wusongqing 已提交
943
| FLAG_ABILITY_MISSION_TOP             | 0x20000000 | Starts the mission on the top of the existing mission stack; creates an ability instance if no mission exists.|