怎样获取app自身bundleName?

怎样获取app自身bundleName?

HarmonyOS
2024-07-13 10:32:03
浏览
收藏 0
回答 1
待解决
回答 1
按赞同
/
按时间
一杯生椰

可以通过getBundleInfoForSelf获取自身的应用包信息

import { bundleManager } from '@kit.AbilityKit';
// 申请获取bundleInfo和applicationInfo
let bundleFlags = bundleManager.BundleFlag.GET_BUNDLE_INFO_WITH_APPLICATION;
try {
  bundleManager.getBundleInfoForSelf(bundleFlags, (err, data) => {

获取应用自身的bundleName

const bundleName = data.name;

获取应用的版本号(versionCode)

const versionCode = data.versionCode;

获取应用的版本名(versionName)

const versionName = data.versionName;

    if (err) {
      console.error(`getBundleInfoForSelf failed: ${err.message}`);
    } else {
      console.info(`get bundleName successfully: ${bundleName}`);
      console.info(`get versionCode successfully: ${versionCode}`);
      console.info(`get versionName successfully: ${versionName}`);
      console.info(`getBundleInfoForSelf successfully: ${JSON.stringify(data)}`);
    }
  });
} catch (err) {
  console.error(`getBundleInfoForSelf failed: ${JSON.stringify(err)}`);
}
分享
微博
QQ
微信
回复
2024-07-13 16:52:07