答案 0 :(得分:4)
try {
ComponentName comp = new ComponentName(this, [CURRENT_ACTIVITY].class);
PackageInfo pinfo = getPackageManager().getPackageInfo(comp.getPackageName(), 0);
int versionCode = pinfo.versionCode;
} catch(android.content.pm.PackageManager.NameNotFoundException e) {}
将“[CURRENT_ACTIVITY]”替换为您活动的实际名称。 (只是为了澄清哈哈)
答案 1 :(得分:1)
context
.
getPackageManager
().
getPackageInfo
(context.
getPackageName
()).
versionCode