When versioning your application, you use the AndroidManifest.xml to specify the versionCode and versionName.

You can read your application’s versionCode and versionName from you activity using the following code:

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

To know more about versioning your app read de documentation.