[笔记] How to get the versionCode and versionName of your app

In you AndroidManifest.xml file, you can specify the values of android:versionCode and android:versionName.


1. versionCode

The versionCode is integer value used to easily differentiate between app versions.

App developers must increment this value when they release updates to their apps in Android Market, so it can determine if users are using an old version of the app, and offer them to update it.

2. versionName

The versionName is a string containing a regular “release version” as seen in other desktop applications, such as “1.4.5” or “3.7”.

The versionName is just a “human readable” version code.

3. Accessing it

Here is how you can access these values in your application code:

PackageInfo pinfo = getPackageManager().getPackageInfo(getPackageName(), 0);  
int versionNumber = pinfo.versionCode;  
String versionName = pinfo.versionName;

This way, you can check which version of your app is being used, if you need to do something spesific with that information. Or you can make a small method that checks for new updates to the app.

4. Note

You can also access other useful resources this way, for example: packageName and requestedPermissions.


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值