code: public static int getVersionCode(Context context) {
          int versionCode;
          try {
              versionCode = context.getPackageManager().getPackageInfo(context.getPackageName(), 0).versionCode;
          } catch (NameNotFoundException e) {
              versionCode = -999;
          }
          return versionCode;
      }
docs: Get the "android:versionCode" value from the Manifest file.
  
  @param context The current Context or Activity that this method is called from
  @return the application version code, or -999 if versionName cannot be found for the given context.