How to set and get application version

8

I'm almost done with my first android app, and I made an "envelope" page and manually entered the version number. Can I set the version somewhere? and how can you get it within the program?

    
asked by anonymous 27.05.2016 / 22:46

1 answer

9

To retrieve the app version use:

PackageInfo pInfo = getPackageManager().getPackageInfo(getPackageName(), 0);
String version = pInfo.versionName;

int verCode = pInfo.versionCode;

The easiest and fastest way to change the version in Android Studio is:

  

Press SHIFT + CTRL + ALT + S

     

Choose the 'Flavors' tab

     

The last two fields are 'Version Code' and 'Version Name'

But you can also change by the file build.gradle :

defaultConfig {
    minSdkVersion 9
    targetSdkVersion 19
    versionCode 1
    versionName "1.0"
}
    
27.05.2016 / 22:51