#鸿蒙学习大百科#如何获取当前UIAbility是哪个UIAbility?

如何获取当前UIAbility是哪个UIAbility?

HarmonyOS
2024-10-29 09:33:43
浏览
收藏 0
回答 1
待解决
回答 1
按赞同
/
按时间
鹈鹕说蟹蟹你
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)
  }
}

分享
微博
QQ
微信
回复
2024-10-29 15:34:20
相关问题
#鸿蒙学习大百科#什么AppStorage?
113浏览 • 1回复 待解决
#鸿蒙学习大百科#什么LocalStorage?
129浏览 • 1回复 待解决
#鸿蒙学习大百科#什么HiTraceMeter?
159浏览 • 1回复 待解决
#鸿蒙学习大百科#什么组合手势?
235浏览 • 1回复 待解决