title: How to fetch the Android versionCode & versionName from a .apk file outside the android environment?
body: <p>The use case is this.  I write custom applications for corporations.  These applications are proprietary and for a variety reasons are inappropriate for the Android Market.  Some customers require that the applications automatically contact a corporate server on a regular basis to check for updates and, if needed, automatically download and install them.  I have a working mechanisms for doing this, but it is not as robust as I would like.  The best solution would be for the application running on the device, to pass its Android versionCode (and perhaps VersionName) to the server where these would be compared with the versionCode of the potential upgrade .apk on the server.  Only if the .apk on the server represents an upgrade would it be uploaded to the device and installed.</p>
  
  <p>There are many suggested solutions posted.  One common one is to place a separate text file on the server which contains the versionCode and versionName, but it is possible through administrative error for this text file to get out of sync with the values in the .apk file.  The result would be constant and unnecesary downloads.  The various other solutions, such as using apktool or any of its wrappers, while workable, have other drawbacks.  </p>
  
  <p>There are workarounds which I am pursuing, but all seem to involve persisting some additional information about an .apk file (e.g. a checksum) that was recently downloaded and installed.  This information can be passed to the server and compared.  This can be made to work, it is just not as clean ss I would like. </p>
  
  <p>I am looking for a library .jar file that will allow the versionCode and versionName to be fetched from the .apk file.  Basically is would be passed the File object representing the .apk file location and provide methods to get the versionCode and versionName.</p>
  
  <p>An other suggestions would be welcome.</p>