Retrieve the version code of the App in Android
How can I retrieve the version code of my application programmatically?
开发者_如何学JAVAI checked that question but all the links are broken
Thanks
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) {}
Replace "[CURRENT_ACTIVITY]" with the actual name of your activity. (Just to clarify haha)
context
.
getPackageManager
().
getPackageInfo
(context.
getPackageName
()).
versionCode
精彩评论