文档管理中心

如何查询应用包的名称、供应商、版本号、版本文本、安装时间、更新时间描述信息

首先,通过 bundleManager.getBundleInfoForSelf() 接口获取应用包的名称、供应商、版本号、版本文本、安装时间和更新时间。具体可参考示例代码:

收起
自动换行
深色代码主题
复制
  1. import { bundleManager } from '@kit.AbilityKit';
  2. // Apply to obtain BundleInfo and applicationInfo
  3. let bundleFlags = bundleManager.BundleFlag.GET_BUNDLE_INFO_WITH_APPLICATION;
  4. try {
  5. bundleManager.getBundleInfoForSelf(bundleFlags, (err, data) => {
  6. // Get the bundle name of the application itself
  7. const bundleName = data.name;
  8. // Get the version number of the application(versionCode)
  9. const versionCode = data.versionCode;
  10. // Get the version name of the application(versionName)
  11. const versionName = data.versionName;
  12. if (err) {
  13. console.error(`getBundleInfoForSelf failed: ${err.message}`);
  14. } else {
  15. console.info(`get bundleName successfully: ${bundleName}`);
  16. console.info(`get versionCode successfully: ${versionCode}`);
  17. console.info(`get versionName successfully: ${versionName}`);
  18. console.info(`getBundleInfoForSelf successfully: ${JSON.stringify(data)}`);
  19. }
  20. });
  21. } catch (err) {
  22. console.error(`getBundleInfoForSelf failed: ${JSON.stringify(err)}`);
  23. }

参考链接

bundleManager.getBundleInfoForSelf