HarmonyOS bundleManager.getProfileByAbility一直报错17700024?

如题:HarmonyOS bundleManager.getProfileByAbility一直报错17700024?

阅读 413
1 个回答

建议参考官网样例使用,报错17700024是因为没有传入对应的resource;getProfileByAbility接口获取的是模块下的module.json5配置项中,abilities内的metadata resource内容,当不传metadataName时,获取的是对应abilityName下的所有metadata配置的resource内容;

metadata参考配置:

https://developer.huawei.com/consumer/cn/doc/harmonyos-guides-V5/module-configuration-file-V5

try {
  bundleManager.getProfileByAbility('entry','EntryAbility','string').then((data) => {
    hilog.info(0x0000, 'testTag', 'getProfileByAbility successfully. Data: %{public}s', JSON.stringify(data));
  }).catch((err: BusinessError) => {
    hilog.error(0x0000, 'testTag', 'getProfileByAbility failed. Cause: %{public}s', err.message);
  });
} catch (err) {
  let message = (err as BusinessError).message;
  hilog.error(0x0000, 'testTag', 'getProfileByAbility failed. Cause: %{public}s', message);
}

配置:

"metadata": [{
  "name": "string",
  "value": "string",
  "resource": "$profile:metadata_con"
}],
logo
HarmonyOS
子站问答
访问
宣传栏