HarmonyOS 配置文件中metadata如何读取?

HarmonyOS 配置文件中metadata如何读取?

HarmonyOS
2024-11-01 10:02:57
浏览
收藏 0
回答 1
待解决
回答 1
按赞同
/
按时间
superinsect

获取metadata可参考:

let bundleFlags = bundleManager.BundleFlag.GET_BUNDLE_INFO_WITH_METADATA | 
bundleManager.BundleFlag.GET_BUNDLE_INFO_WITH_APPLICATION; 
try { 
  bundleManager.getBundleInfoForSelf(bundleFlags).then((bundleInfo: bundleManager.BundleInfo) => { 
    hilog.info(0x0000, ‘testTag’, ‘getBundleInfoForSelf successfully. Data: %{public}s’, JSON.stringify(bundleInfo)); 
    hilog.info(0x0000, ‘testTag’, ‘getBundleInfoForSelf successfully. MetaData: %{public}s’, JSON.stringify(bundleInfo.appInfo.metadataArray)); 
    let arr = bundleInfo.appInfo.metadataArray; 
    console.info("testTag arr is ", (arr instanceof Array)); 
    hilog.info(0x0000, ‘testTag’, ‘arr : %{public}s’, JSON.stringify(arr.length)); 
    for(let data of arr){ 
      hilog.info(0x0000, ‘testTag’, ‘MetaData name: %{public}s’, JSON.stringify(data.moduleName)); 
      for(let metadata of data.metadata){ 
        hilog.info(0x0000, ‘testTag’, ‘MetaData content: %{public}s’, JSON.stringify(metadata)); 
      } 
    } 
  }).catch((err: BusinessError) => { 
    hilog.error(0x0000, ‘testTag’, ‘getBundleInfoForSelf failed. Cause: %{public}s’, err.message); 
  }); 
} catch (err) { 
  let message = (err as BusinessError).message; 
  hilog.error(0x0000, ‘testTag’, ‘getBundleInfoForSelf failed: %{public}s’, message); 
},

​可参考相关文档:​https://developer.huawei.com/consumer/cn/doc/harmonyos-references/js-apis-bundlemanager-V5#bundlemanagergetbundleinfo

分享
微博
QQ
微信
回复
2024-11-01 15:16:34
相关问题
配置文件配置权限时报错如下
1233浏览 • 1回复 待解决
HarmonyOS应用内配置文件读写问题
403浏览 • 1回复 待解决
DevEco Device Tool配置文件在哪?
6454浏览 • 1回复 待解决
module.json5配置文件type的含义
538浏览 • 1回复 待解决
关于权限申请的配置文件声明
1686浏览 • 1回复 待解决
关于 web 项目配置文件是否使用缓存
4163浏览 • 1回复 待解决
HarmonyOS如何读取文件
561浏览 • 1回复 待解决
配置文件的文档的问题有懂的吗?
3086浏览 • 1回复 待解决