HarmonyOS 原信息是什么概念,该如何理解?

经常看到Api里提到, 从XX版本开始支持原信息XXX 这里原信息是什么意思,该如何理解

阅读 471
1 个回答

可以参考一下metadata标签:

https://developer.huawei.com/consumer/cn/doc/harmonyos-guides-V5/module-configuration-file-V5\#metadata标签

Metadata主要是通过一个TAG(Key),去找对应的Data,用于传递参数和配置信息,减少内存拷贝操作

元服务问题可以参考链接:

https://developer.huawei.com/consumer/cn/doc/atomic-guides-V5/atomic-service-definition-V5

示例参考:

import { hilog } from '@kit.PerformanceAnalysisKit';
import { BusinessError } from '@kit.BasicServicesKit';
import { bundleManager, common } from '@kit.AbilityKit';

@Entry
@Component
struct getMetadata {
  @State message: string = 'Hello World';
  context = getContext(this) as common.UIAbilityContext;

  build() {
    RelativeContainer() {
      Text(this.message)
        .id('HelloWorld')
        .fontSize(50)
        .fontWeight(FontWeight.Bold)
        .alignRules({
          center: { anchor: '__container__', align: VerticalAlign.Center },
          middle: { anchor: '__container__', align: HorizontalAlign.Center }
        })
        .onClick(() => {
          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);
          }
        })
    }
    .height('100%')
    .width('100%')
  }
}
logo
HarmonyOS
子站问答
访问
宣传栏