开发者

Retrieve the version code of the App in Android

开发者 https://www.devze.com 2023-03-30 20:59 出处:网络
How can I retrieve the version code of my application programmatically? 开发者_如何学JAVA I checked that question but all the links are broken

How can I retrieve the version code of my application programmatically?

开发者_如何学JAVA

I 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

0

精彩评论

暂无评论...
验证码 换一张
取 消