Within your build.gradle
you can define the versionName
, which is a String that indicates the version:
android {
...
versionCode 1
versionName "(v. 1.3)"
...
}
these values can also be defined within your file AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.jorgesys.ussd"
android:versionCode="1"
android:versionName="(v. 1.3)">
just remember that the setting of build.gradle
always overwrites the one in the file AndroidManifest.xml
Given the above, you can get the value of versionName
in this way :
public String getVersionName(Context ctx){
try {
return ctx.getPackageManager().getPackageInfo(getPackageName(), 0).versionName;
} catch (PackageManager.NameNotFoundException e) {
e.printStackTrace();
return "";
}
}
another way is simply (requires the project to be built):
public String getVersionName(){
return BuildConfig.VERSION_NAME;
}
The String value of versionName
can be concatenated to the name of your application.
You can even define as versionName
the value Liturgia+ (v. 1.3)
, example:
android {
...
versionCode 1
versionName "Liturgia+ (v. 1.3)"
...
}