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

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)}`); 
}
Logo

一站式 AI 云服务平台

更多推荐