中国优质的IT技术网站
专业IT技术创作平台
IT职业在线教育平台
如何获取当前UIAbility是哪个UIAbility?
微信扫码分享
import { bundleManager } from '@kit.AbilityKit'; import { BusinessError } from '@kit.BasicServicesKit'; import { hilog } from '@kit.PerformanceAnalysisKit'; @Entry @Component struct Index { build() { Column() { Button("获取当前UIAbility信息").onClick(() => { let bundleFlags = bundleManager.BundleFlag.GET_BUNDLE_INFO_WITH_HAP_MODULE | bundleManager.BundleFlag.GET_BUNDLE_INFO_WITH_ABILITY bundleManager.getBundleInfoForSelf(bundleFlags).then(data => { hilog.info(0x0000, 'testTag', 'getBundleInfoForSelf successfully. Data: %{public}s', JSON.stringify(data)); }) .catch((err: BusinessError) => { hilog.error(0x0000, 'testTag', 'getBundleInfoForSelf failed. Cause: %{public}s', err.message); }); }) } .height("100%") .width('100%') .justifyContent(FlexAlign.Center) } }