js-apis-featureAbility.md 32.0 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
| Name     | Type                 | Mandatory| Description               |
W
wusongqing 已提交
27
| --------- | --------------------- | ---- | ------------------- |
W
wusongqing 已提交
28 29
| 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
| Name     | Type                                           | Mandatory| Description                 |
W
wusongqing 已提交
66
| --------- | ----------------------------------------------- | ---- | --------------------- |
W
wusongqing 已提交
67
| 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
| Name| Type  | Mandatory| Description                    |
W
wusongqing 已提交
104
| ---- | ------ | ---- | ------------------------ |
W
wusongqing 已提交
105
| uri  | string | Yes  | URI of the file to open.|
W
wusongqing 已提交
106

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

W
wusongqing 已提交
109
| Type             | Description                                        |
W
wusongqing 已提交
110
| ----------------- | -------------------------------------------- |
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
| Name     | Type                                           | Mandatory| Description                 |
W
wusongqing 已提交
133
| --------- | ----------------------------------------------- | ---- | --------------------- |
W
wusongqing 已提交
134 135
| 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
| Name     | Type                                           | Mandatory| Description               |
W
wusongqing 已提交
170
| --------- | ----------------------------------------------- | ---- | ------------------- |
W
wusongqing 已提交
171
| parameter | [StartAbilityParameter](#startabilityparameter) | Yes  | Ability to start.|
W
wusongqing 已提交
172

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

W
wusongqing 已提交
175
| Type                                     | Description          |
W
wusongqing 已提交
176 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
| Name     | Type         | Mandatory| Description               |
W
wusongqing 已提交
226
| --------- | ------------- | ---- | ------------------- |
W
wusongqing 已提交
227 228
| 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
| Name     | Type                           | Mandatory| Description               |
W
wusongqing 已提交
274
| --------- | ------------------------------- | ---- | ------------------- |
W
wusongqing 已提交
275
| parameter | [AbilityResult](#abilityresult) | Yes  | Ability to start.|
W
wusongqing 已提交
276

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

W
wusongqing 已提交
279
| Type          | Description                   |
W
wusongqing 已提交
280
| -------------- | ----------------------- |
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
| Name    | Type                   | Mandatory| Description                                                        |
W
wusongqing 已提交
331
| -------- | ----------------------- | ---- | ------------------------------------------------------------ |
W
wusongqing 已提交
332
| 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
| Type             | Description                                                      |
W
wusongqing 已提交
354 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
| Name    | Type                         | Mandatory| Description              |
W
wusongqing 已提交
379
| -------- | ----------------------------- | ---- | ------------------ |
W
wusongqing 已提交
380
| 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
| Type                   | Description                     |
W
wusongqing 已提交
402
| ----------------------- | ------------------------- |
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
| Type   | Description                |
W
wusongqing 已提交
425 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
| Name    | Type                | Mandatory| Description            |
W
wusongqing 已提交
449
| -------- | -------------------- | ---- | ---------------- |
W
wusongqing 已提交
450
| 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
| Type          | Description                     |
W
wusongqing 已提交
472
| -------------- | ------------------------- |
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
| Name   | Type          | Mandatory| Description                        |
W
wusongqing 已提交
494
| ------- | -------------- | ---- | ---------------------------- |
W
wusongqing 已提交
495 496
| 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
| Name        | Readable/Writable | Type    | Mandatory| Description                                                             |
W
wusongqing 已提交
503
| ------------ | -------- | -------- | ---- | ----------------------------------                               |
W
wusongqing 已提交
504 505 506
| 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
| Name        | Readable/Writable| Type    | Mandatory| Description                              |
W
wusongqing 已提交
513
| ------------ | -------- | -------- | ---- | ---------------------------------- |
W
wusongqing 已提交
514 515 516
| 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
| Type  | Description                    |
W
wusongqing 已提交
521 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
| Name      | Type         | Mandatory| Description                          |
W
wusongqing 已提交
563
| ---------- | ------------- | ---- | ------------------------------ |
W
wusongqing 已提交
564 565
| 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
| Name      | Type  | Mandatory| Description                          |
W
wusongqing 已提交
610
| ---------- | ------ | ---- | ------------------------------ |
W
wusongqing 已提交
611
| connection | number | Yes  | ID of the Service ability to disconnect.|
W
wusongqing 已提交
612 613

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

W
wusongqing 已提交
615
| Type          | Description                   |
W
wusongqing 已提交
616
| -------------- | ----------------------- |
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 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 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

## 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**

| Name    | Type                   | Mandatory| Description                                                        |
| -------- | ----------------------- | ---- | ------------------------------------------------------------ |
| callback | AsyncCallback\<window.Window> | Yes  | Callback used to return the window.|

**Example**

```javascript
GetWindow(){
        featureAbility.getWindow()
    }
```

## 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**

| Type             | Description                                                      |
| ----------------- | ---------------------------------------------------------- |
| Promise\<window.Window> | Promise used to return the window.|

**Example**

```javascript
GetWindowPromise(){
        featureAbility.getWindow().then((data) => {
            console.info("=============getWindowPromise========== " + JSON.stringify(data));
        });
    }
```


## AbilityWindowConfiguration

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

**Example**

```
featureAbility.AbilityWindowConfiguration.WINDOW_MODE_UNDEFINED
```

| Name                       | Name| Description      |
| --------------------------- | ---- | ---------- |
| WINDOW_MODE_UNDEFINED<sup>7+</sup>       | 0    | The Page ability is in an undefined window display mode.<br>**System capability**: SystemCapability.Ability.AbilityRuntime.FAModel  |
| WINDOW_MODE_FULLSCREEN<sup>7+</sup>      | 1    | The Page ability is in full screen mode.<br>**System capability**: SystemCapability.Ability.AbilityRuntime.FAModel    |
| WINDOW_MODE_SPLIT_PRIMARY<sup>7+</sup>   | 100  | The Page ability is displayed in the primary window when it is in split-screen mode.<br>**System capability**: SystemCapability.Ability.AbilityRuntime.FAModel|
| WINDOW_MODE_SPLIT_SECONDARY<sup>7+</sup> | 101  | The Page ability is displayed in the secondary window when it is in split-screen mode.<br>**System capability**: SystemCapability.Ability.AbilityRuntime.FAModel|
| WINDOW_MODE_FLOATING<sup>7+</sup>        | 102  | The Page ability is displayed in floating window mode.<br>**System capability**: SystemCapability.Ability.AbilityRuntime.FAModel  |


## 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
```

| Name           | Name           | Description                      |
| --------------- | --------------- | -------------------------- |
| BOUNDS_KEY<sup>7+</sup>       | "abilityBounds" | Ability window size.<br>**System capability**: SystemCapability.Ability.AbilityRuntime.FAModel  |
| WINDOW_MODE_KEY<sup>7+</sup>  | "windowMode"    | Ability window display mode.<br>**System capability**: SystemCapability.Ability.AbilityRuntime.FAModel  |
| DISPLAY_ID_KEY<sup>7+</sup>   | "displayId"     | Display device ID.<br>**System capability**: SystemCapability.Ability.AbilityRuntime.FAModel|

## ErrorCode

Enumerates error codes.

| Variable                         | Value  | Description                                                        |
| ----------------------------- | ---- | ------------------------------------------------------------ |
| NO_ERROR<sup>7+</sup>           | 0    | No error occurs.<br>**System capability**: SystemCapability.Ability.AbilityRuntime.FAModel|
| INVALID_PARAMETER<sup>7+</sup>          | -1    | Invalid parameter.<br>**System capability**: SystemCapability.Ability.AbilityRuntime.FAModel|
| ABILITY_NOT_FOUND<sup>7+</sup>  | -2    | The ability is not found.<br>**System capability**: SystemCapability.Ability.AbilityRuntime.FAModel|
| PERMISSION_DENY<sup>7+</sup>            | -3    | The request is denied.<br>**System capability**: SystemCapability.Ability.AbilityRuntime.FAModel|


## DataAbilityOperationType

Enumerates operation types of the Data ability.

| Variable                         | Value  | Description                                                        |
| ----------------------------- | ---- | ------------------------------------------------------------ |
| TYPE_INSERT<sup>7+</sup>           | 1   | Insert operation.<br>**System capability**: SystemCapability.Ability.AbilityRuntime.FAModel|
| TYPE_UPDATE<sup>7+</sup>          | 2  | Update operation.<br>**System capability**: SystemCapability.Ability.AbilityRuntime.FAModel|
| TYPE_DELETE<sup>7+</sup>  | 3    | Deletion operation.<br>**System capability**: SystemCapability.Ability.AbilityRuntime.FAModel|
| TYPE_ASSERT<sup>7+</sup>            | 4    | Assert operation.<br>**System capability**: SystemCapability.Ability.AbilityRuntime.FAModel|



W
wusongqing 已提交
760
## AbilityResult
W
wusongqing 已提交
761

W
wusongqing 已提交
762 763
**System capability**: SystemCapability.Ability.AbilityBase

W
wusongqing 已提交
764
| Name      | Readable/Writable| Type                 | Mandatory| Description                                                        |
W
wusongqing 已提交
765
| ---------- | -------- | --------------------- | ---- | ------------------------------------------------------------ |
W
wusongqing 已提交
766 767
| 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 已提交
768

W
wusongqing 已提交
769
## StartAbilityParameter
W
wusongqing 已提交
770

W
wusongqing 已提交
771 772
**System capability**: SystemCapability.AbilityRuntime.FAModel

W
wusongqing 已提交
773
| Name               | Readable/Writable| Type                | Mandatory| Description                                                        |
W
wusongqing 已提交
774
| ------------------- | -------- | -------------------- | ---- | ------------------------------------------------------------ |
W
wusongqing 已提交
775 776 777
| 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 已提交
778

W
wusongqing 已提交
779
## Want
W
wusongqing 已提交
780

W
wusongqing 已提交
781 782
**System capability**: SystemCapability.Ability.AbilityBase

W
wusongqing 已提交
783
| Name       | Readable/Writable| Type                | Mandatory| Description                                                        |
W
wusongqing 已提交
784
| ----------- | -------- | -------------------- | ---- | ------------------------------------------------------------ |
W
wusongqing 已提交
785 786 787 788 789 790 791 792 793
| deviceId<sup>8+</sup>     | Read-only    | string               | No  | ID of the device that runs the ability.                               |
| bundleName<sup>8+</sup>   | 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<sup>8+</sup>  | 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<sup>8+</sup>          | 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<sup>8+</sup>         | Read-only    | string               | No  | MIME type, for example, text/plain or image/*.  |
| flags<sup>8+</sup>        | Read-only    | number               | No  | How the **Want** object will be handled. By default, a number is passed. For details, see [flags](#flags).|
| action<sup>8+</sup>       | Read-only    | string               | No  | Action option.                          |
| parameters<sup>8+</sup>   | Read-only    | {[key: string]: any} | No  | List of parameters in a **Want** object.                                      |
| entities<sup>8+</sup>     | Read-only    | Array\<string>       | No  | List of entities.                                   |
W
wusongqing 已提交
794 795 796

## flags

W
wusongqing 已提交
797 798
**System capability**: SystemCapability.Ability.AbilityBase

W
wusongqing 已提交
799
| Name                                | Name      | Description                                                        |
W
wusongqing 已提交
800
| ------------------------------------ | ---------- | ------------------------------------------------------------ |
W
wusongqing 已提交
801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816
| FLAG_AUTH_READ_URI_PERMISSION        | 0x00000001 | Indicates the permission to read the URI.                                 |
| FLAG_AUTH_WRITE_URI_PERMISSION       | 0x00000002 | Indicates the permission to write the URI.                                |
| FLAG_ABILITY_FORWARD_RESULT          | 0x00000004 | Returns the result to the ability.                                          |
| FLAG_ABILITY_CONTINUATION            | 0x00000008 | Indicates whether the ability on the local device can be migrated to a remote device.               |
| FLAG_NOT_OHOS_COMPONENT              | 0x00000010 | Indicates that a component does not belong to OHOS.                                        |
| FLAG_ABILITY_FORM_ENABLED            | 0x00000020 | Indicates whether to enable an ability.                                        |
| FLAG_AUTH_PERSISTABLE_URI_PERMISSION | 0x00000040 | Indicates the permission to make the URI persistent.                                   |
| FLAG_AUTH_PREFIX_URI_PERMISSION      | 0x00000080 | Indicates the permission to verify URIs by prefix matching.                                          |
| FLAG_ABILITYSLICE_MULTI_DEVICE       | 0x00000100 | Supports cross-device startup in a distributed scheduler.                              |
| FLAG_START_FOREGROUND_ABILITY        | 0x00000200 | Indicates that the Service ability is started regardless of whether the host application has been started.  |
| FLAG_ABILITY_CONTINUATION_REVERSIBLE | 0x00000400 | Indicates that the migration is reversible.                                       |
| FLAG_INSTALL_ON_DEMAND               | 0x00000800 | Indicates that the specific ability will be installed if it has not been installed.                          |
| FLAG_INSTALL_WITH_BACKGROUND_MODE    | 0x80000000 | Indicates that the specific ability will be installed in the background if it has not been installed.                        |
| FLAG_ABILITY_CLEAR_MISSION           | 0x00008000 | Clears other operation missions. This flag can be set for the **Want** object passed to **ohos.app.Context#startAbility** and must be used together with **flag_ABILITY_NEW_MISSION**.|
| FLAG_ABILITY_NEW_MISSION             | 0x10000000 | Creates a mission on the historical mission stack.                        |
| FLAG_ABILITY_MISSION_TOP             | 0x20000000 | Starts the mission on the top of the existing mission stack; creates an ability instance if no mission exists.|