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