如何判断某个应用是否为系统应用(API 9)
解决措施
使用bundleManager模块的getApplicationInfo接口(仅系统应用可以使用)获取待检验应用的ApplicationInfo,根据ApplicationInfo中systemApp字段判断,若为true,则是系统应用,否则为非系统应用。
如何获取应用配置的versionCode和versionName(API 9)
解决措施
首先通过@ohos.bundle.bundleManager模块bundleManager.getBundleInfoForSelf()接口获取包信息BundleInfo,然后分别通过BundleInfo.versionCode、BundleInfo.versionName获取所需信息。
代码示例
import bundleManager from '@ohos.bundle.bundleManager';
import hilog from '@ohos.hilog';
let bundleFlags = bundleManager.BundleFlag.GET_BUNDLE_INFO_DEFAULT;
try {
bundleManager.getBundleInfoForSelf(bundleFlags).then((data) => {
const versionCode = data.versionCode;
const versionName = data.versionName;
hilog.info(0x0000, 'testTag', `successfully. versionCode: ${versionCode}, versionName: ${versionName}`);
}).catch(err => {
hilog.error(0x0000, 'testTag', 'failed. Cause: %{public}s', err.message);
});
} catch (err) {
hilog.error(0x0000, 'testTag', 'failed: %{public}s', err.message);
}
如何获取应用自身的bundleName(API 9)
解决措施
可以通过UIAbilityContext.abilityInfo.bundleName获取。
代码示例
import common from '@ohos.app.ability.common';
const context = getContext(this) as common.UIAbilityContext
console.log(`bundleName: ${context.abilityInfo.bundleName}`)
如何获取App版本号,版本名,屏幕分辨率等信息(API 9)
解决措施
-
通过@ohos.bundle.bundleManag