• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# postCardAction
2
3postCardAction(component: Object, action: Object): void
4
5Provides information for interaction between the widget and widget provider. Currently, router, message, and call events are supported. This API can only be called within the widget.
6
7> **NOTE**
8>
9> This API is supported since API version 9.
10
11**System capability**: SystemCapability.ArkUI.ArkUI.Full
12
13**Parameters**
14
15
16| **Name**| **Type**| **Mandatory**| **Description**|
17| -------- | -------- | -------- | -------- |
18| component | Object | Yes| Instance of the current custom component. Generally, **this** is passed in.|
19| action | Object | Yes| Action description. For details, see the following table.|
20
21
22Description of the action parameter
23
24
25| **Name**| **Type**|  **Mandatory**| **Description**|
26| -------- | -------- | -------- | -------- |
27| action | string | Yes|Action type.<br>- **"router"**: redirection to the specified UIAbility of the widget provider.<br>- **"message"**: custom message. If this type of action is triggered, the [onFormEvent()](../apis-form-kit/js-apis-app-form-formExtensionAbility.md#onformevent) lifecycle callback of the provider FormExtensionAbility is called.<br>- **"call"**: launch of the widget provider in the background. If this type of action is triggered, the specified UIAbility (whose [launch type](../../application-models/uiability-launch-type.md) must be singleton) of the widget provider is started in the background, but not displayed in the foreground. This action type requires that the widget provider should have the [ohos.permission.KEEP_BACKGROUND_RUNNING](../../security/AccessToken/permissions-for-all.md#ohospermissionkeep_background_running) permission.|
28| bundleName | string | No| Name of the target bundle when **action** is **"router"** or **"call"**.|
29| moduleName | string | No| Name of the target module when **action** is **"router"** or **"call"**.|
30| abilityName | string | No| Name of the target UIAbility when **action** is **"router"** or **"call"**.|
31| uri<sup>11+</sup> | string   | No  | URI of the target UIAbility when **action** is **"router"** or **"call"**. If both **uri** and **abilityName** are set, **abilityName** takes precedence.|
32| params | Object | No| Additional parameters carried in the current action. The value is a key-value pair in JSON format.|
33
34>**NOTE**
35>
36>When **action** is **"router"** or **"call"**, **'method'** of the string type must be passed to **params** to trigger the corresponding method in the UIAbility.
37
38**Example**
39
40```ts
41Button ('Redirect')
42  .width('40%')
43  .height('20%')
44  .onClick(() => {
45    postCardAction(this, {
46      action: 'router',
47      bundleName: 'com.example.myapplication',
48      abilityName: 'EntryAbility',
49      params: {
50        message: 'testForRouter' // Customize the message to send.
51      }
52    });
53  })
54
55Button ('Start in Background')
56  .width('40%')
57  .height('20%')
58  .onClick(() => {
59    postCardAction(this, {
60      action: 'call',
61      bundleName: 'com.example.myapplication',
62      abilityName: 'EntryAbility',
63      params: {
64        method: 'fun', // Set the name of the method to call. It is mandatory.
65        message: 'testForCall' // Customize the message to send.
66      }
67    });
68  })
69
70Button ('Redirect URI')
71  .width('40%')
72  .height('20%')
73  .onClick(() => {
74    postCardAction(this, {
75      action: 'router',
76      uri: 'example://uri.ohos.com/link_page',
77      params: {
78        message: 'router msg for dynamic uri deeplink' // Customize the message to send.
79      }
80    });
81  })
82
83```
84
85The following is an example of **uris** configuration in the [module.json5](../../quick-start/module-configuration-file.md#skills) file of the target application:
86
87```json
88"abilities": [
89  {
90    "skills": [
91      {
92        "uris": [
93          {
94            "scheme": "example",
95            "host": "uri.ohos.com",
96            "path": "link_page"
97          },
98        ]
99      }
100    ],
101  }
102]
103```
104