Getting information about your app programatically:

Get App Version Code

public static int getAppVersionCode(Context context) {
    PackageInfo pInfo;
    try {
      pInfo = context.getPackageManager().getPackageInfo(
          context.getPackageName(), 0);
      return pInfo.versionCode;
    } catch (NameNotFoundException e) {
      e.printStackTrace();
      return 0;
    }

 }

Get App Version Name

public static String getAppVersionName(Context context) {
    PackageInfo pInfo;
    try {
      pInfo = context.getPackageManager().getPackageInfo(
          context.getPackageName(), 0);
      return pInfo.versionName;
    } catch (NameNotFoundException e) {
      e.printStackTrace();
      return null;
    }

}