I would like to be able to compare, on application start, the running version against the same application’s version currently on Google Play.
I found a nice way to this, described here:
public String getLatestVersionNumber() {
String versionNumber = "0.0.0";
try {
Document doc = Jsoup.connect("http://www.appbrain.com/app/wallpaper-switch/com.mlevit.wallpaperswitch").get();
Elements changeLog = doc.select("div.clDesc");
for (Element div : changeLog) {
String divText = div.text();
if (divText.contains("Version")) {
return divText.split(" ")[1];
}
}
}
catch (IOException e) {
e.printStackTrace();
}
return versionNumber;
}
But it’s way too slow and significantly hampers user experience on application start.
Is there a faster way to query application’s current version on Google Play?
Perhaps some hidden LVL or in-app billing API?
Well, by definition, network access is slow. Even if Google Play had a documented, supported, and licensed API (they don’t as of the time of this writing), it would only be incrementally faster than what you are doing.
Step #1: Create a file.
Step #2: In that file, type in your version number, optionally along with other data (e.g., description of update) in some format (e.g., JSON).
Step #3: Upload that file to some well-known stable URL.
Step #4: Create an
AsyncTask, putting the HTTP request for your file indoInBackground()of anAsyncTask, with updating your UI (preferably via something non-modal) in theonPostExecute()of that sameAsyncTask.Here is a sample project demonstrating an
AsyncTaskthat performs an HTTP operation (pulling a weather forecast from the US National Weather Service) and parsing the result, updating the UI (populating aWebView) when done.