在鸿蒙原生开发中如何获取应用名称,代码中如何获取应用名称(桌面图标下面显示的应用名称)?

阅读 741
1 个回答

moudle.json5中使用的是资源文件’$string:EntryAbility_label‘,这边提供了一个demo,包含了包名和应用名称的显示:

import common from '@ohos.app.ability.common'; 
 
const context = getContext(this) as common.UIAbilityContext 
console.log(`bundleName: ${context.abilityInfo.bundleName}`) 
 
@Entry 
@Component 
struct Page240604115304029 { 
  @State message: string = 'Hello World'; 
 
  build() { 
    Row() { 
      Column() { 
        Text($r('app.string.EntryAbility_label')) 
          .fontSize(50) 
          .fontWeight(FontWeight.Bold) 
      } 
      .width('100%') 
    } 
    .height('100%') 
  } 
}

本文参与了 【 HarmonyOS NEXT 技术问答冲榜,等你来战!】欢迎正在阅读的你也加入。

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进