• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Using startAbilityByType to Start a Financial Application
2
3This topic describes how to open the vertical domain panel of financial applications.
4
5## Parameters on the Financial Application Panel
6
7If the **type** field in **startAbilityByType** is set to **finance**, **wantParam** contains the following properties.
8
9| Name           | Type                                                        | Mandatory| Description|
10| -------------------- | ------------------------------------------------------------ | -------- | -------- |
11| sceneType            | number                          | No| Intent scene, which indicates the purpose of the current request. The options are as follows: 1: transfer; 2: credit card repayment. The default value is **1**.|
12| bankCardNo      | string                                               | No | Bank card number.|
13
14## Developing a Caller Application
151. Import the module.
16    ```ts
17    import { common } from '@kit.AbilityKit';
18    ```
192. Construct parameters and call the **startAbilityByType** API.
20
21    ```ts
22    @Entry
23    @Component
24    struct Index {
25        @State hideAbility: string = 'hideAbility';
26
27        build() {
28            Row() {
29                Column() {
30                    Text(this.hideAbility)
31                        .fontSize(30)
32                        .fontWeight(FontWeight.Bold)
33                        .onClick(() => {
34                            let context = this.getUIContext().getHostContext() as common.UIAbilityContext;
35                            let wantParam: Record<string, Object> = {
36                                'sceneType': 1,
37                                "bankCardNo": '123456789'
38                            };
39                            let abilityStartCallback: common.AbilityStartCallback = {
40                                onError: (code: number, name: string, message: string) => {
41                                    console.log(`onError code ${code} name: ${name} message: ${message}`);
42                                },
43                                onResult: (result) => {
44                                    console.log(`onResult result: ${JSON.stringify(result)}`);
45                                }
46                            }
47
48                            context.startAbilityByType("finance", wantParam, abilityStartCallback,
49                                (err) => {
50                                    if (err) {
51                                        console.error(`startAbilityByType fail, err: ${JSON.stringify(err)}`);
52                                    } else {
53                                        console.log(`success`);
54                                    }
55                                });
56                        });
57                }
58                .width('100%')
59            }
60            .height('100%')
61        }
62    }
63    ```
64    Effect
65
66    ![Effect example](./figures/start-finance-panel.png)
67
68## Developing a Target Application
69
701. Configure [uris](../quick-start/module-configuration-file.md#skills) in the **module.json5** file.
71   1. Set the **linkFeature** field to declare the features supported by the application so that the system can match the application against all the installed applications on the device. The options are as follows:
72
73        | Value          | Description                        |
74        | -------------- | ---------------------------- |
75        | Transfer     | The application supports transfer.		|
76        | CreditCardRepayment      | The application supports credit card repayment.	|
77   2. Set **scheme**, **host**, **port**, and **path** or **pathStartWith** to match the URIs in Want to distinguish different features.
78
79    ```json
80    {
81      "abilities": [
82          {
83          "skills": [
84              {
85              "uris": [
86                  {
87                  "scheme": "finance", // It is for reference only. Ensure that the declared URI can be started by external systems.
88                  "host": "transfer",
89                  "path": "",
90                  "linkFeature": "Transfer" // Declare that the application supports transfer.
91                  },
92                  {
93                  "scheme": "finance", // It is for reference only. Ensure that the declared URI can be started by external systems.
94                  "host": "credit_card_repayment",
95                  "path": "",
96                  "linkFeature": "CreditCardRepayment" // Declare that the application supports credit card repayment.
97                  }
98              ]
99              }
100          ]
101          }
102      ]
103    }
104    ```
105
1062. Parse and process the parameters transferred from the panel.
107
108    ```ts
109    UIAbility.onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void
110    ```
111
112    The **want.uri** parameter carries the URI corresponding to **linkFeature** configured by the target application.
113
114    The **want.parameters** parameter carries the parameters transferred by the caller application, as described in the table below.
115
116    | Name         | Type                                                        | Mandatory| Description|
117    | -------------------- | ------------------------------------------------------------ | -------- | -------- |
118    | bankCardNo  | string | No | Bank card number.|
119
120    The application can develop different style pages based on the features defined in [linkFeature](../quick-start/module-configuration-file.md#skills), such as transfer and credit card repayment, as well as the received URI.
121
122**Sample Code**
123
124```ts
125import { AbilityConstant, UIAbility, Want } from '@kit.AbilityKit';
126import { hilog } from '@kit.PerformanceAnalysisKit';
127import { window } from '@kit.ArkUI';
128
129const TAG = 'EntryAbility';
130
131export default class EntryAbility extends UIAbility {
132    windowStage: window.WindowStage | null = null;
133
134    uri?: string;
135    bankCardNo?: string;
136
137    onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void {
138        hilog.info(0x0000, TAG, `onCreate, want=${JSON.stringify(want)}`);
139        super.onCreate(want, launchParam);
140        this.parseWant(want);
141    }
142
143    onNewWant(want: Want, launchParam: AbilityConstant.LaunchParam): void {
144        hilog.info(0x0000, TAG, `onNewWant, want=${JSON.stringify(want)}`);
145        super.onNewWant(want, launchParam);
146        this.parseWant(want);
147        if (!this.windowStage) {
148            hilog.error(0x0000, TAG, 'windowStage is null');
149            this.context.terminateSelf();
150            return;
151        }
152        this.loadPage(this.windowStage);
153    }
154
155    private parseWant(want: Want): void {
156        this.uri = want.uri as string | undefined;
157        this.bankCardNo = want.parameters?.bankCardNo as string | undefined;
158    }
159
160    private loadPage(windowStage: window.WindowStage): void {
161        hilog.info(0x0000, TAG, `loadPage, uri=${this.uri}`);
162        if (this.uri === 'finance://transfer') {
163            // Construct parameters for the transfer scenario.
164            const storage: LocalStorage = new LocalStorage({
165                "bankCardNo": this.bankCardNo
166            } as Record<string, Object>);
167            // Open the transfer page.
168            windowStage.loadContent('pages/TransferPage', storage)
169        } else if (this.uri === 'finance://credit_card_repayment') {
170            // Construct parameters for the credit card repayment scenario.
171            const storage: LocalStorage = new LocalStorage({
172                "bankCardNo": this.bankCardNo
173            } as Record<string, Object>);
174            // Open the credit card repayment page.
175            windowStage.loadContent('pages/CreditCardRepaymentPage', storage)
176        } else {
177            // Display the home page by default.
178            windowStage.loadContent('pages/Index', (err) => {
179                if (err.code) {
180                    hilog.error(0x0000, TAG, 'Failed to load the content. Cause: %{public}s',
181                        JSON.stringify(err) ?? '');
182                    return;
183                }
184                hilog.info(0x0000, TAG, 'Succeeded in loading the content.');
185            });
186        }
187    }
188
189    onDestroy(): void {
190        hilog.info(0x0000, TAG, `onDestroy`);
191    }
192
193    onWindowStageCreate(windowStage: window.WindowStage): void {
194        hilog.info(0x0000, TAG, `onWindowStageCreate`);
195        this.windowStage = windowStage;
196        this.loadPage(this.windowStage);
197    }
198
199    onWindowStageDestroy(): void {
200        hilog.info(0x0000, TAG, '%{public}s', 'Ability onWindowStageDestroy');
201    }
202
203    onForeground(): void {
204        hilog.info(0x0000, TAG, '%{public}s', 'Ability onForeground');
205    }
206
207    onBackground(): void {
208        hilog.info(0x0000, TAG, '%{public}s', 'Ability onBackground');
209    }
210}
211```
212