code: public String getPackageVersion(String packageName) { 
  
          if (packageName == null || packageName.trim().length() == 0) {
              return null;
          }
          
          if (!packageName.endsWith(".")) {
              packageName = packageName + ".";
          }
          
          String className = packageName + "PackageInfo";
  
          Class<?> packageInfoClass = getClassForName(className);
          if (packageInfoClass == null) {
              return null;
          }
  
          String productVersion = null;
          String buildNumber = null;
  
          try {
  
              Method getProductVersionMethod = 
                  packageInfoClass.getMethod("getProductVersion", 
                                             EMPTY_CLASS_ARRAY);
  
              productVersion = 
                  (String) getProductVersionMethod.invoke(null, 
                                                          EMPTY_OBJECT_ARRAY);
              
              Method getBuildNumberMethod = 
                  packageInfoClass.getMethod("getBuildNumber", 
                                             EMPTY_CLASS_ARRAY);
  
              buildNumber = 
                  (String) getBuildNumberMethod.invoke(null, 
                                                       EMPTY_OBJECT_ARRAY);
  
          }
          catch (Throwable t) { 
              // Just eat it 
          }
  
          if (productVersion != null && productVersion.length() > 0 &&
              buildNumber != null && buildNumber.length() > 0) {
  
              productVersion += '.' + buildNumber;
          }
  
          return productVersion;
      }
docs: Create a version information string based on what the build process
  provided.  The string is of the form "M.m.r" or
  "M.m.r.bbbb" (i.e. 1.1.0.0004) if the build number can be retrieved.
  Returns <code>null</code> if the version string cannot be retrieved.