开发者

Retrieve the version code of the App in Android

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜