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#uiabilitycontextstartabilitybytype11) or [UIExtensionContentSession.startAbilityByType](../reference/apis-ability-kit/js-apis-app-ability-uiExtensionContentSession.md#uiextensioncontentsessionstartabilitybytype11) 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. 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 dight.| 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. 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 **ohos.app.ability.common** module. 32 ```ts 33 import { common } from '@kit.AbilityKit'; 34 ``` 35 362. Construct parameters and call the **startAbilityByType** API. 37 38 ```ts 39 let context = getContext(this) as common.UIAbilityContext; 40 let wantParam: Record<string, Object> = { 41 'sceneType': 1, 42 'flightNo': 'ZH1509', 43 'departureDate': '2024-10-01' 44 }; 45 let abilityStartCallback: common.AbilityStartCallback = { 46 onError: (code: number, name: string, message: string) => { 47 console.log(`onError code ${code} name: ${name} message: ${message}`); 48 }, 49 onResult: (result)=>{ 50 console.log(`onResult result: ${JSON.stringify(result)}`); 51 } 52 } 53 54 context.startAbilityByType("flight", wantParam, abilityStartCallback, 55 (err) => { 56 if (err) { 57 console.error(`startAbilityByType fail, err: ${JSON.stringify(err)}`); 58 } else { 59 console.log(`success`); 60 } 61 }); 62 ``` 63 Effect 64 65  66 67## Developing a Target Application 68 691. Configure [uris](../quick-start/module-configuration-file.md#skills) in the **module.json5** file. 70 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: 71 | Value | Description | 72 | ----------- | ------------------------ | 73 | QueryByFlightNo | Declares that the application supports flight query by flight number. | 74 | QueryByLocation | Declares that the application supports flight query by origin and destination.| 75 2. Set **scheme**, **host**, **port**, and **path** or **pathStartWith** to match the URIs in Want to distinguish different features. 76 ```json 77 { 78 "abilities": [ 79 { 80 "skills": [ 81 { 82 "uris": [ 83 { 84 "scheme": "flight", 85 "host": "queryByFlightNo", 86 "path": "", 87 "linkFeature": "QueryByFlightNo" 88 }, 89 { 90 "scheme": "flight", 91 "host": "queryByLocation", 92 "path": "", 93 "linkFeature": "QueryByLocation" 94 } 95 ] 96 } 97 ] 98 } 99 ] 100 } 101 ``` 102 1032. Parse parameters and perform corresponding processing. 104 105 ```ts 106 UIAbility::onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void 107 ``` 108 109 The **want.uri** parameter carries the URI corresponding to **linkFeature** configured by the target application. 110 111 **want.parameters** carries the parameters passed by the caller, which vary in different scenarios. 112 113 - Flight query by flight number 114 115 | Name | Type | Mandatory| Description | 116 | -------------------- | ------ | ---- | ---------------------------------------------------- | 117 | flightNo | string | Yes | Flight number, which is a two-digit code of the airline company plus a dight. | 118 | departureDate | string | No | Flight departure date, in the format of YYYY-MM-DD. If this field is left blank, it indicates the current day. | 119 120 - Flight query by origin and destination 121 122 | Name | Type | Mandatory| Description | 123 | -------------------- | ------ | ---- | -------------------------------------------------- | 124 | originLocation | string | Yes | Departure place. | 125 | destinationLocation | string | Yes | Destination. | 126 | departureDate | string | No | Flight departure date, in the format of YYYY-MM-DD. If this field is left blank, it indicates the current day. | 127 128 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. 129 130**Sample Code** 131 132```ts 133import { AbilityConstant, UIAbility, Want } from '@kit.AbilityKit'; 134import { hilog } from '@kit.PerformanceAnalysisKit'; 135import { window } from '@kit.ArkUI'; 136 137const TAG = 'EntryAbility' 138 139export default class EntryAbility extends UIAbility { 140 windowStage: window.WindowStage | null = null; 141 142 uri?: string; 143 flightNo?: string; 144 departureDate?: string; 145 originLocation?: string; 146 destinationLocation?: string; 147 148 onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void { 149 hilog.info(0x0000, TAG, `onCreate, want=${JSON.stringify(want)}`); 150 super.onCreate(want, launchParam); 151 this.parseWant(want); 152 } 153 154 onNewWant(want: Want, launchParam: AbilityConstant.LaunchParam): void { 155 hilog.info(0x0000, TAG, `onNewWant, want=${JSON.stringify(want)}`); 156 super.onNewWant(want, launchParam); 157 this.parseWant(want); 158 if (!this.windowStage) { 159 hilog.error(0x0000, TAG, 'windowStage is null'); 160 this.context.terminateSelf(); 161 return; 162 } 163 this.loadPage(this.windowStage); 164 } 165 166 private parseWant(want: Want): void { 167 this.uri = want.uri as string | undefined; 168 this.flightNo = want.parameters?.flightNo as string | undefined; 169 this.departureDate = want.parameters?.departureDate as string | undefined; 170 this.originLocation = want.parameters?.originLocation as string | undefined; 171 this.destinationLocation = want.parameters?.destinationLocation as string | undefined; 172 } 173 174 private loadPage(windowStage: window.WindowStage): void { 175 hilog.info(0x0000, TAG, `loadPage, uri=${this.uri}`); 176 if (this.uri === 'flight://queryByFlightNo') { 177 // Construct parameters for scenarios of flight query by flight number. 178 const storage: LocalStorage = new LocalStorage({ 179 "flightNo": this.flightNo, 180 "departureDate": this.departureDate 181 } as Record<string, Object>); 182 // Display the page for querying flights by flight number. 183 windowStage.loadContent('pages/QueryByFlightNoPage', storage) 184 } else if (this.uri === 'flight://queryByLocation') { 185 // Construct parameters for scenarios of flight query by origin and destination. 186 const storage: LocalStorage = new LocalStorage({ 187 "originLocation": this.originLocation, 188 "destinationLocation": this.destinationLocation, 189 "departureDate": this.departureDate 190 } as Record<string, Object>); 191 // Display the page for querying flights by origin and destination. 192 windowStage.loadContent('pages/QueryByLocationPage', storage) 193 } else { 194 // Display the home page by default. 195 windowStage.loadContent('pages/Index', (err) => { 196 if (err.code) { 197 hilog.error(0x0000, TAG, 'Failed to load the content. Cause: %{public}s', 198 JSON.stringify(err) ?? ''); 199 return; 200 } 201 hilog.info(0x0000, TAG, 'Succeeded in loading the content.'); 202 }); 203 } 204 } 205 206 onDestroy(): void { 207 hilog.info(0x0000, TAG, `onDestroy`); 208 } 209 210 onWindowStageCreate(windowStage: window.WindowStage): void { 211 hilog.info(0x0000, TAG, `onWindowStageCreate`); 212 this.windowStage = windowStage; 213 this.loadPage(this.windowStage); 214 } 215 216 onWindowStageDestroy(): void { 217 hilog.info(0x0000, TAG, '%{public}s', 'Ability onWindowStageDestroy'); 218 } 219 220 onForeground(): void { 221 hilog.info(0x0000, TAG, '%{public}s', 'Ability onForeground'); 222 } 223 224 onBackground(): void { 225 hilog.info(0x0000, TAG, '%{public}s', 'Ability onBackground'); 226 } 227} 228``` 229