Call bundleManager.getBundleInfoForSelf() to obtain the information about an application package, including the bundle name, vendor, and version information. Refer to the code snippet below.
import { bundleManager } from '@kit.AbilityKit';
// Apply to obtain BundleInfo and applicationInfo
let bundleFlags = bundleManager.BundleFlag.GET_BUNDLE_INFO_WITH_APPLICATION;
try {
bundleManager.getBundleInfoForSelf(bundleFlags, (err, data) => {
// Get the bundle name of the application itself
const bundleName = data.name;
// Get the version number of the application (versionCode)
const versionCode = data.versionCode;
// Get the version name of the application (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)}`);
} Reference