1# Using startAbilityByType to Start a Flight Application 2 3This topic describes how to open the vertical domain panel of flight applications. 4 5For example, in a travel scheduling application, if a user inputs the flight number for an upcoming journey, the application can identify this flight number and provide a link to track the flight status. After the user touches the link, the application calls [UIAbilityContext.startAbilityByType](../reference/apis-ability-kit/js-apis-inner-application-uiAbilityContext.md#startabilitybytype11) or [UIExtensionContentSession.startAbilityByType](../reference/apis-ability-kit/js-apis-app-ability-uiExtensionContentSession.md#startabilitybytype11) to open a panel. This panel displays all available applications on the device that support flight query, enabling the user to select and switch to the application that meets their needs. 6 7## Parameters on the Flight Application Panel 8 9If the **type** field in **startAbilityByType** is set to **flight**, two intent scenarios are supported: flight query by flight number and by origin and destination. The corresponding **wantParam** parameter contains the following properties. 10 11- Flight query by flight number 12 13 | Name | Type | Mandatory| Description | 14 | ------------- | ------ | ---- | ------------------------------------------------------------ | 15 | sceneType | number | No | Intent scene, which indicates the purpose of the current request. The default value is **1**. In scenarios of flight query by flight number, set it to **1** or leave it empty. | 16 | flightNo | string | Yes | Flight number, which is a two-digit code of the airline company plus a digit.| 17 | departureDate | string | No | Flight departure date, in the format of YYYY-MM-DD. | 18 19- Flight query by origin and destination 20 21 | Name | Type | Mandatory| Description | 22 | -------------------- | ---------------------- | ---- | -------------------------------------------------------- | 23 | sceneType | number | Yes | Intent scene, which indicates the purpose of the current request. In scenarios of flight query by origin and destination, set it to **2**. | 24 | originLocation | string | Yes | Departure place. | 25 | destinationLocation | string | Yes | Destination. | 26 | departureDate | string | No | Flight departure date, in the format of YYYY-MM-DD. | 27 28 29## Developing a Caller Application 30 311. Import the module. 32 ```ts 33 import { common } from '@kit.AbilityKit'; 34 ``` 35 362. Construct parameters and call the **startAbilityByType** API. 37 38 ```ts 39 @Entry 40 @Component 41 struct Index { 42 @State hideAbility: string = 'hideAbility' 43 44 build() { 45 Row() { 46 Column() { 47 Text(this.hideAbility) 48 .fontSize(30) 49 .fontWeight(FontWeight.Bold) 50 .onClick(() => { 51 let context = this.getUIContext().getHostContext() as common.UIAbilityContext; 52 let wantParam: Record<string, Object> = { 53 'sceneType': 1, 54 'flightNo': 'ZH1509', 55 'departureDate': '2024-10-01' 56 }; 57 let abilityStartCallback: common.AbilityStartCallback = { 58 onError: (code: number, name: string, message: string) => { 59 console.log(`onError code ${code} name: ${name} message: ${message}`); 60 }, 61 onResult: (result) => { 62 console.log(`onResult result: ${JSON.stringify(result)}`); 63 } 64 } 65 66 context.startAbilityByType("flight", wantParam, abilityStartCallback, 67 (err) => { 68 if (err) { 69 console.error(`startAbilityByType fail, err: ${JSON.stringify(err)}`); 70 } else { 71 console.log(`success`); 72 } 73 }); 74 }); 75 } 76 .width('100%') 77 } 78 .height('100%') 79 } 80 } 81 ``` 82 Effect 83  84 85## Developing a Target Application 86 871. Configure [uris](../quick-start/module-configuration-file.md#skills) in the **module.json5** file. 88 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: 89 | Value | Description | 90 | ----------- | ------------------------ | 91 | QueryByFlightNo | Declares that the application supports flight query by flight number. | 92 | QueryByLocation | Declares that the application supports flight query by origin and destination.| 93 2. Set **scheme**, **host**, **port**, and **path** or **pathStartWith** to match the URIs in Want to distinguish different features. 94 ```json 95 { 96 "abilities": [ 97 { 98 "skills": [ 99 { 100 "uris": [ 101 { 102 "scheme": "flight", 103 "host": "queryByFlightNo", 104 "path": "", 105 "linkFeature": "QueryByFlightNo" 106 }, 107 { 108 "scheme": "flight", 109 "host": "queryByLocation", 110 "path": "", 111 "linkFeature": "QueryByLocation" 112 } 113 ] 114 } 115 ] 116 } 117 ] 118 } 119 ``` 120 1212. Parse parameters and perform corresponding processing. 122 123 ```ts 124 UIAbility.onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void 125 ``` 126 127 The **want.uri** parameter carries the URI corresponding to **linkFeature** configured by the target application. 128 129 **want.parameters** carries the parameters passed by the caller, which vary in different scenarios. 130 131 - Flight query by flight number 132 133 | Name | Type | Mandatory| Description | 134 | -------------------- | ------ | ---- | ---------------------------------------------------- | 135 | flightNo | string | Yes | Flight number, which is a two-digit code of the airline company plus a digit. | 136 | departureDate | string | No | Flight departure date, in the format of YYYY-MM-DD. If this field is left blank, it indicates the current day. | 137 138 - Flight query by origin and destination 139 140 | Name | Type | Mandatory| Description | 141 | -------------------- | ------ | ---- | -------------------------------------------------- | 142 | originLocation | string | Yes | Departure place. | 143 | destinationLocation | string | Yes | Destination. | 144 | departureDate | string | No | Flight departure date, in the format of YYYY-MM-DD. If this field is left blank, it indicates the current day. | 145 146 The application can develop different style pages based on the features defined in [linkFeature](../quick-start/module-configuration-file.md#skills), such as flight query by flight number or by origin and destination, as well as the received URI and parameters. 147 148**Sample Code** 149 150```ts 151import { AbilityConstant, UIAbility, Want } from '@kit.AbilityKit'; 152import { hilog } from '@kit.PerformanceAnalysisKit'; 153import { window } from '@kit.ArkUI'; 154 155const TAG = 'EntryAbility'; 156 157export default class EntryAbility extends UIAbility { 158 windowStage: window.WindowStage | null = null; 159 160 uri?: string; 161 flightNo?: string; 162 departureDate?: string; 163 originLocation?: string; 164 destinationLocation?: string; 165 166 onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void { 167 hilog.info(0x0000, TAG, `onCreate, want=${JSON.stringify(want)}`); 168 super.onCreate(want, launchParam); 169 this.parseWant(want); 170 } 171 172 onNewWant(want: Want, launchParam: AbilityConstant.LaunchParam): void { 173 hilog.info(0x0000, TAG, `onNewWant, want=${JSON.stringify(want)}`); 174 super.onNewWant(want, launchParam); 175 this.parseWant(want); 176 if (!this.windowStage) { 177 hilog.error(0x0000, TAG, 'windowStage is null'); 178 this.context.terminateSelf(); 179 return; 180 } 181 this.loadPage(this.windowStage); 182 } 183 184 private parseWant(want: Want): void { 185 this.uri = want.uri as string | undefined; 186 this.flightNo = want.parameters?.flightNo as string | undefined; 187 this.departureDate = want.parameters?.departureDate as string | undefined; 188 this.originLocation = want.parameters?.originLocation as string | undefined; 189 this.destinationLocation = want.parameters?.destinationLocation as string | undefined; 190 } 191 192 private loadPage(windowStage: window.WindowStage): void { 193 hilog.info(0x0000, TAG, `loadPage, uri=${this.uri}`); 194 if (this.uri === 'flight://queryByFlightNo') { 195 // Construct parameters for scenarios of flight query by flight number. 196 const storage: LocalStorage = new LocalStorage({ 197 "flightNo": this.flightNo, 198 "departureDate": this.departureDate 199 } as Record<string, Object>); 200 // Display the page for querying flights by flight number. 201 windowStage.loadContent('pages/QueryByFlightNoPage', storage) 202 } else if (this.uri === 'flight://queryByLocation') { 203 // Construct parameters for scenarios of flight query by origin and destination. 204 const storage: LocalStorage = new LocalStorage({ 205 "originLocation": this.originLocation, 206 "destinationLocation": this.destinationLocation, 207 "departureDate": this.departureDate 208 } as Record<string, Object>); 209 // Display the page for querying flights by origin and destination. 210 windowStage.loadContent('pages/QueryByLocationPage', storage) 211 } else { 212 // Display the home page by default. 213 windowStage.loadContent('pages/Index', (err) => { 214 if (err.code) { 215 hilog.error(0x0000, TAG, 'Failed to load the content. Cause: %{public}s', 216 JSON.stringify(err) ?? ''); 217 return; 218 } 219 hilog.info(0x0000, TAG, 'Succeeded in loading the content.'); 220 }); 221 } 222 } 223 224 onDestroy(): void { 225 hilog.info(0x0000, TAG, `onDestroy`); 226 } 227 228 onWindowStageCreate(windowStage: window.WindowStage): void { 229 hilog.info(0x0000, TAG, `onWindowStageCreate`); 230 this.windowStage = windowStage; 231 this.loadPage(this.windowStage); 232 } 233 234 onWindowStageDestroy(): void { 235 hilog.info(0x0000, TAG, '%{public}s', 'Ability onWindowStageDestroy'); 236 } 237 238 onForeground(): void { 239 hilog.info(0x0000, TAG, '%{public}s', 'Ability onForeground'); 240 } 241 242 onBackground(): void { 243 hilog.info(0x0000, TAG, '%{public}s', 'Ability onBackground'); 244 } 245} 246``` 247