code: public static int getVersionCode(Context context, int fallback) {
          try {
              PackageManager manager = context.getPackageManager();
              PackageInfo info = manager.getPackageInfo(context.getPackageName(), 0);
              return info.versionCode;
          } catch (NameNotFoundException e) {
              Log.e(TAG, "no such package installed on the device: ", e);
          }
          return fallback;
      }
docs: Read version code from the manifest of the context.
  @param context the context.
  @param fallback fallback value of the version code.
  @return the version code, or fallback value if not found.