1# FullScreenLaunchComponent 2<!--Kit: ArkUI--> 3<!--Subsystem: ArkUI--> 4<!--Owner: @dutie123--> 5<!--Designer: @lmleon--> 6<!--Tester: @fredyuan0912--> 7<!--Adviser: @HelloCrease--> 8 9全屏启动原子化服务组件,当被拉起方授权使用方可以嵌入式运行原子化服务时,使用方全屏嵌入式运行原子化服务;未授权时,使用方跳出式拉起原子化服务。 10 11 12> **说明:** 13> 14> 该组件从API Version 12开始支持。后续版本如有新增内容,则采用上角标单独标记该内容的起始版本。 15> 16> 该组件不支持在Wearable设备上使用。 17> 18> 如果需要在该组件中实现可嵌入式运行的原子化服务,必须继承自[EmbeddableUIAbility](../../apis-ability-kit/js-apis-app-ability-embeddableUIAbility.md)。否则,系统无法保证原子化服务功能正常。 19 20 21## 导入模块 22 23```ts 24import { FullScreenLaunchComponent } from '@kit.ArkUI'; 25``` 26 27 28## 子组件 29 30无 31 32## 属性 33不支持[通用属性](ts-component-general-attributes.md)。 34 35## 事件 36不支持[通用事件](ts-component-general-events.md)。 37 38## FullScreenLaunchComponent 39 40FullScreenLaunchComponent({ content: Callback\<void>, appId: string, options?: AtomicServiceOptions, onError?: ErrorCallback, onTerminated?: Callback\<TerminationInfo> }) 41 42**装饰器类型:**\@Component 43 44**系统能力:** SystemCapability.ArkUI.ArkUI.Full 45 46| 名称 | 类型 | 必填 | 装饰器类型 | 说明 | 47| -------- | -------- | -------- | -------- | -------- | 48| content | Callback\<void> | 是 | \@BuilderParam | 可以使用组件组合来自定义拉起原子化服务前的占位图标,实现类似大桌面应用图标的效果。点击占位组件后,将拉起原子化服务。<br/>**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。| 49| appId | string | 是 | - | 需要拉起的原子化服务appId,appId是原子化服务的唯一标识。<br/>**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。<!--RP1--><!--RP1End-->| 50| options | [AtomicServiceOptions](../../apis-ability-kit/js-apis-app-ability-atomicServiceOptions.md) | 否 | - | 拉起原子化服务参数。<br/>**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 | 51| onError<sup>18+<sup> | [ErrorCallback](../../apis-basic-services-kit/js-apis-base.md#errorcallback) | 否 | - | 被拉起的嵌入式运行原子化服务在运行过程中发生异常时触发本回调。可通过回调参数中的code、name和message获取错误信息并做处理。<br/>**原子化服务API:** 从API version 18开始,该接口支持在原子化服务中使用。 | 52| onTerminated<sup>18+<sup> | [Callback](../../apis-basic-services-kit/js-apis-base.md#callback)\<[TerminationInfo](ts-container-embedded-component.md#terminationinfo)> | 否 | - | 被拉起的嵌入式运行原子化服务通过调用[terminateSelfWithResult](../../apis-ability-kit/js-apis-inner-application-uiAbilityContext.md#terminateselfwithresult)或者[terminateSelf](../../apis-ability-kit/js-apis-inner-application-uiAbilityContext.md#terminateself)正常退出时,触发本回调函数。<br/>**原子化服务API:** 从API version 18开始,该接口支持在原子化服务中使用。 | 53| onReceive<sup>20+<sup> | [Callback](../../apis-basic-services-kit/js-apis-base.md#callback)\<Record<string, Object>> | 否 | - | 被拉起的嵌入式运行原子化服务通过[Window](../../../windowmanager/application-window-stage.md)调用API时,触发本回调。<br/>**原子化服务API:** 从API version 20开始,该接口支持在原子化服务中使用。 | 54 55> **说明:** 56> 57> - 若原子化服务通过调用[terminateSelfWithResult](../../apis-ability-kit/js-apis-inner-application-uiAbilityContext.md#terminateselfwithresult)退出,其携带的信息会传给回调函数的入参; 58> - 若原子化服务通过调用[terminateSelf](../../apis-ability-kit/js-apis-inner-application-uiAbilityContext.md#terminateself)退出,上述回调函数的入参中,"code"取默认值"0","want"为"undefined"。 59 60## 示例 61本示例展示组件使用方法和扩展的原子化服务。实际运行时请使用开发者自己的原子化服务appId。 62 63**使用方** 64```ts 65// 使用方入口界面Index.ets内容如下: 66import { FullScreenLaunchComponent } from '@kit.ArkUI'; 67 68@Entry 69@Component 70struct Index { 71 @State appId: string = '6917573653426122083'; // 原子化服务appId 72 73 build() { 74 Row() { 75 Column() { 76 FullScreenLaunchComponent({ 77 content: ColumnChild, 78 appId: this.appId, 79 options: {}, 80 onTerminated: (info) => { 81 console.info("onTerminated code: " + info.code.toString()); 82 }, 83 onError: (err) => { 84 console.error("onError code: " + err.code + ", message: ", err.message); 85 }, 86 onReceive: (data) => { 87 console.info("onReceive, data: " + JSON.stringify(data)); 88 } 89 }).width("80vp").height("80vp") 90 } 91 .width('100%') 92 } 93 .height('100%') 94 } 95} 96 97@Builder 98function ColumnChild() { 99 Column() { 100 Image($r('app.media.startIcon')) 101 Text('test') 102 } 103} 104``` 105**组件提供方** 106 107原子化服务提供方需要修改两个文件: 108- 提供方入口文件:/src/main/ets/entryability/EntryAbility.ets。 109```ts 110import { AbilityConstant, Want, EmbeddableUIAbility } from '@kit.AbilityKit'; 111import { hilog } from '@kit.PerformanceAnalysisKit'; 112import { window } from '@kit.ArkUI'; 113 114const DOMAIN = 0x0000; 115 116export default class EntryAbility extends EmbeddableUIAbility { 117 storage = new LocalStorage(); 118 onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void { 119 hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onCreate'); 120 } 121 122 onDestroy(): void { 123 hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onDestroy'); 124 } 125 126 onWindowStageCreate(windowStage: window.WindowStage): void { 127 hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onWindowStageCreate'); 128 let mainWindow = windowStage.getMainWindowSync() 129 this.storage.setOrCreate("window", mainWindow) 130 this.storage.setOrCreate("windowStage", windowStage) 131 windowStage.loadContent('pages/Index', this.storage); 132 } 133 134 onWindowStageDestroy(): void { 135 hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onWindowStageDestroy'); 136 } 137 138 onForeground(): void { 139 hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onForeground'); 140 } 141 142 onBackground(): void { 143 hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onBackground'); 144 } 145} 146``` 147 148- 提供方扩展Ability入口页面文件:/src/main/ets/pages/Index.ets。 149```ts 150import { BusinessError } from '@kit.BasicServicesKit'; 151import { window } from '@kit.ArkUI'; 152 153const DOMAIN = 0x0000; 154 155@Entry({ storage : new LocalStorage() }) 156@Component 157struct Index { 158 storage = new LocalStorage() 159 160 build() { 161 Row() { 162 Column() { 163 GridRow({ columns: 2 }) { 164 GridCol() { 165 Button("setWindowSystemBar") 166 .onClick(() => { 167 this.testSetSystemBarEnable() 168 }).width(120) 169 }.height(60) 170 GridCol() { 171 Button("setGestureBack") 172 .onClick(() => { 173 this.testSetGestureBackEnable() 174 }).width(120) 175 }.height(60) 176 GridCol() { 177 Button("setImmersive") 178 .onClick(() => { 179 this.testSetImmersiveEnable() 180 }).width(120) 181 }.height(60) 182 GridCol() { 183 Button("setSpecificSystemBarEnabled") 184 .onClick(() => { 185 this.testSetSpecificSystemBarEnabled() 186 }).width(120) 187 }.height(60) 188 } 189 } 190 .width('100%') 191 } 192 .height('100%') 193 } 194 testSetSystemBarEnable() { 195 let window: window.Window | undefined = this.storage.get("window"); 196 let p = window?.setWindowSystemBarEnable(["status"]) 197 p?.then(() => { 198 console.info('setWindowSystemBarEnable success'); 199 }).catch((err: BusinessError) => { 200 console.info('setWindowSystemBarEnable failed, error = ' + JSON.stringify(err)); 201 }) 202 } 203 testSetGestureBackEnable() { 204 let window: window.Window | undefined = this.storage.get("window"); 205 let p = window?.setGestureBackEnabled(true) 206 p?.then(() => { 207 console.info('setGestureBackEnabled success'); 208 }).catch((err: BusinessError) => { 209 console.info('setGestureBackEnabled failed, error = ' + JSON.stringify(err)); 210 }) 211 } 212 testSetImmersiveEnable() { 213 let window: window.Window | undefined = this.storage.get("window"); 214 try{ 215 window?.setImmersiveModeEnabledState(true) 216 } catch(err) { 217 console.info('setImmersiveModeEnabledState failed, error = ' + JSON.stringify(err)); 218 } 219 } 220 testSetSpecificSystemBarEnabled() { 221 let window: window.Window | undefined = this.storage.get("window"); 222 let p = window?.setSpecificSystemBarEnabled('navigationIndicator', false, false) 223 p?.then(() => { 224 console.info('setSpecificSystemBarEnabled success'); 225 }).catch((err: BusinessError) => { 226 console.info('setSpecificSystemBarEnabled failed, error = ' + JSON.stringify(err)); 227 }) 228 } 229} 230``` 231