• 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**| **Description**|
26| -------- | -------- | -------- |
27| action | string | 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/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 | Name of the target bundle when **action** is **"router"** or **"call"**. This parameter is optional.|
29| moduleName | string | Name of the target module when **action** is **"router"** or **"call"**. This parameter is optional.|
30| abilityName | string | Name of the target UIAbility when **action** is **"router"** or **"call"**. This parameter is mandatory.|
31| params | Object | Additional parameters carried in the current action. The value is a key-value pair in JSON format. This parameter is mandatory.|
32
33>**NOTE**
34>
35>When **action** is **"router"** or **"call"**, **'method'** of the string type must be passed to **params** to trigger the corresponding method in the UIAbility.
36
37**Example**
38
39```ts
40Button ('Redirect')
41  .width('40%')
42  .height('20%')
43  .onClick(() => {
44    postCardAction(this, {
45      action: 'router',
46      bundleName: 'com.example.myapplication',
47      abilityName: 'EntryAbility',
48      params: {
49        message: 'testForRouter' // Customize the message to send.
50      }
51    });
52  })
53
54Button ('Start in Background')
55  .width('40%')
56  .height('20%')
57  .onClick(() => {
58    postCardAction(this, {
59      action: 'call',
60      bundleName: 'com.example.myapplication',
61      abilityName: 'EntryAbility',
62      params: {
63        method: 'fun', // Set the name of the method to call. It is mandatory.
64        message: 'testForCall' // Customize the message to send.
65      }
66    });
67  })
68```
69