OpenHarmony开发者论坛

标题: 如何获取app.json5配置文件中的应用配置信息 [打印本页]

作者: 润开鸿_坚果    时间: 2024-6-19 16:18
标题: 如何获取app.json5配置文件中的应用配置信息
[md]## 如何获取app.json5配置文件中的应用配置信息

**完整代码**

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

@Entry
@Component
struct Page1 {
 @State message: string = 'Hello World';

 build() {
   Column() {
     Text(this.message).onClick(() => {
       let bundleFlags = bundleManager.BundleFlag.GET_BUNDLE_INFO_WITH_APPLICATION;
       try {
         bundleManager.getBundleInfoForSelf(bundleFlags).then((data) => {
           let context = getContext(this) as common.UIAbilityContext;
           context.resourceManager.getStringValue(data.appInfo.labelId, (error, value) => {
             if (error != null) {
             } else {
               hilog.info(0x0000, 'testTag', 'getBundleInfoForSelf successfully. Data: %{public}s',

                 this.message = JSON.stringify(value));
             }
           })
           hilog.info(0x0000, 'testTag', 'getBundleInfoForSelf successfully. Data: %{public}s', JSON.stringify(data));
         })
       } catch (err) {
         hilog.error(0x0000, 'testTag', 'getBundleInfoForSelf failed: %{public}s', err.message);
       }
     })

   }
   .height('100%')
   .width('100%').justifyContent(FlexAlign.Center)
  }
}
```


monica-code-tools
[/md]




欢迎光临 OpenHarmony开发者论坛 (https://forums.openharmony.cn/) Powered by Discuz! X3.5