js-apis-formextensioncontext.md 2.7 KB
Newer Older
W
wusongqing 已提交
1 2
# FormExtensionContext

3
The **FormExtensionContext** module, inherited from **ExtensionContext**, provides context for Form Extension abilities.
W
wusongqing 已提交
4

5
You can use the APIs of this module to start abilities.
W
wusongqing 已提交
6

7 8 9 10
> **NOTE**
>
> The initial APIs of this module are supported since API version 9. Newly added APIs will be marked with a superscript to indicate their earliest API version.
> The APIs of this module can be used only in the stage model.
W
wusongqing 已提交
11

12
## FormExtensionContext.startAbility
W
wusongqing 已提交
13

14
startAbility(want: Want, callback: AsyncCallback<void>): void
W
wusongqing 已提交
15

16
Starts an ability. This API uses an asynchronous callback to return the result.
W
wusongqing 已提交
17

W
wusongqing 已提交
18
**System capability**: SystemCapability.Ability.Form
W
wusongqing 已提交
19

20 21
**System API**: This is a system API and cannot be called by third-party applications.

W
wusongqing 已提交
22 23
**Parameters**

24 25 26 27
| Name|                Type              | Mandatory|              Description              |
| ------| --------------------------------- | ---- | -------------------------------------- |
| want| [Want](js-apis-application-Want.md) | Yes | Information about the ability to start, such as the ability name and bundle name.|
| callback| AsyncCallback<void>       | Yes | Callback used to return the result.|
W
wusongqing 已提交
28

W
wusongqing 已提交
29
**Example**
W
wusongqing 已提交
30

31 32 33 34 35 36 37 38 39 40 41 42 43 44 45
```js
var want = {
    deviceId: "",
    bundleName: "com.example.formstartability",
    abilityName: "MainAbility",
    action: "action1",
    entities: ["entity1"],
    type: "MIMETYPE",
    uri: "key={true,true,false}",
    parameters: {}
}
this.context.startAbility(want, function(err) {
    console.info(err.code);
})
```
W
wusongqing 已提交
46

47
## FormExtensionContext.startAbility
W
wusongqing 已提交
48

49
startAbility(want: Want): Promise<void>
W
wusongqing 已提交
50

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

W
wusongqing 已提交
53 54
**System capability**: SystemCapability.Ability.Form

55 56
**System API**: This is a system API and cannot be called by third-party applications.

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

59 60 61
| Name|                Type              | Mandatory|              Description              |
| ------| --------------------------------- | ---- | -------------------------------------- |
| want| [Want](js-apis-application-Want.md) | Yes | Information about the ability to start, such as the ability name and bundle name.|
W
wusongqing 已提交
62

W
wusongqing 已提交
63
**Return value**
W
wusongqing 已提交
64

65 66 67
| Type         | Description                               |
| ------------ | ---------------------------------- |
| Promise\<void> | Promise used to return the result.|
W
wusongqing 已提交
68

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

71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87
```js
var want = {
    deviceId: "",
    bundleName: "com.example.formstartability",
    abilityName: "MainAbility",
    action: "action1",
    entities: ["entity1"],
    type: "MIMETYPE",
    uri: "key={true,true,false}",
    parameters: {}
}
this.context.startAbility(want).then(() => {
    console.info("StartAbility Success");
}).catch((error) => {
    console.info("StartAbility failed");
});
```