HarmonyOS 如何在har包中获得当前应用的包名、活动的AbilityName以及活动的ModuleName

NFC读卡接口需要传递bundleManager.ElementName,其中包括bundleName、abilityName和moduleName若是读卡逻辑写在har包内,如何获取bundleName、abilityName和moduleName

HarmonyOS
2024-12-20 16:14:35
浏览
收藏 0
回答 1
待解决
回答 1
按赞同
/
按时间
put_get

har包中可以通过外部传参取得bundleName、abilityName和moduleName 请见下方示例:

hap包中的页面(OutPage)调用har包导出的组件页面(MainPage)

import { MainPage } from 'harApp/Index';
import { common } from '@kit.AbilityKit';
import { hilog } from '@kit.PerformanceAnalysisKit';
const TAG: string = 'testTag'
@Entry
@Component
struct OutPage {
  @State message: string = 'OutPage';
  private bundleName: string = ''
  private abilityName: string = ''
  private moduleName: string = ''
  aboutToAppear(): void {
    let context = getContext() as common.UIAbilityContext
    hilog.info(0x0000, TAG, 'OutPage-bundleName为:%{public}s', context.abilityInfo.bundleName)
    hilog.info(0x0000, TAG, 'OutPage-abilityName为:%{public}s', context.abilityInfo.name)
    hilog.info(0x0000, TAG, 'OutPage-moduleName为:%{public}s', context.abilityInfo.moduleName)
    this.bundleName = context.abilityInfo.bundleName
    this.abilityName = context.abilityInfo.name
    this.moduleName = context.abilityInfo.moduleName
  }
  build() {
    Column() {
      MainPage({ bundleName: this.bundleName, abilityName: this.abilityName, moduleName: this.moduleName })
    }
  }
}
分享
微博
QQ
微信
回复
2024-12-20 18:41:20
相关问题
如何获取当前HAP
2893浏览 • 1回复 待解决
怎么获得当前设备IP地址?
682浏览 • 1回复 待解决
鸿蒙JS UI如何获得当前组件值?
6960浏览 • 1回复 待解决
HarmonyOS 应用命名规则
1759浏览 • 1回复 待解决
HarmonyOS 系统里如何查看应用
1404浏览 • 1回复 待解决
harworker如何在entry内使用
2495浏览 • 1回复 待解决