HarmonyOS使用arkTS拉起指定第三方应用程序

import promptAction from '@ohos.promptAction'; import { BusinessError } from '@kit.BasicServicesKit'; import Logger from '../util/Logger' import { common } from '@kit.AbilityKit'; const TAG: string = 'LogIndex' const BUNDLE_NAME: string = 'com.example.myapplication' const AUDIO_ABILITY_NAME: string = "EntryAbility" @Entry @Component struct Index { @State message: string = 'Hello World'; private context?: common.UIAbilityContext build() { RelativeContainer() { Text(this.message) .id('HelloWorld') .fontSize(50) .fontWeight(FontWeight.Bold) .alignRules({ center: { anchor: '__container__', align: VerticalAlign.Center }, middle: { anchor: '__container__', align: HorizontalAlign.Center } }) .onClick(() => { promptAction.showToast({ message: "点击提示" }) console.log("fadfasdfasfasdf") }) Button("UI控件") .onClick(() => { Logger.info(TAG, 'onClick success') if (this.context) { this.context.startAbility({ bundleName: BUNDLE_NAME, abilityName: AUDIO_ABILITY_NAME }).then(() => { Logger.info(TAG, 'start UI控件 ability success') }).catch((error: BusinessError) => { Logger.error(TAG, 'start UI控件 ability failed, error: ' + JSON.stringify(error)) }) } }) Button("跳转") .margin({ top: 100, left: 100 }) .onClick(() => { if (this.context) { this.context.startAbility({ bundleName: "com.tencent.tmgp.sgamece.hw", abilityName: "SGameAbility" }).then(() => { Logger.info(TAG, 'start ability success') }).catch((error: BusinessError) => { Logger.error(TAG, 'start ability failed, error: ' + JSON.stringify(error)) }) } }) } .height('100%') .width('100%') } aboutToAppear() { this.context = getContext(this) as common.UIAbilityContext } }
上一篇:L6.【LeetCode笔记】合并两个有序链表


下一篇:第07章 运算符的使用