To get versionName
and versionCode
of current build of your application you should query Android's package manager.
try {
// Reference to Android's package manager
PackageManager packageManager = this.getPackageManager();
// Getting package info of this application
PackageInfo info = packageManager.getPackageInfo(this.getPackageName(), 0);
// Version code
info.versionCode
// Version name
info.versionName
} catch (NameNotFoundException e) {
// Handle the exception
}