3

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?

Community
  • 1
  • 1
Bill The Ape
  • 3,261
  • 25
  • 44
  • 1
    Why not just do it in an AsyncTask? That way it doesn't interfere with the UI? Also, what exactly are you trying to accomplish ? – Kevin Coppock Aug 12 '12 at 21:17
  • @kcoppock I would like to display a dialog box informing user of a newer version and recommending going to Google Play to update it (many users don't bother checking Google Play for updates, so I need to make them aware ASAP of a new version). Can you post your suggestion on how to do that via AsyncTask? – Bill The Ape Aug 12 '12 at 21:21
  • 2
    This relies on AppBrain not changing their Web design, and indirectly relies upon AppBrain's pirating of the Play Store data. Please simply maintain your own file somewhere (e.g., Amazon S3) that contains your app's version number. And *always* do network I/O on a background thread (e.g., `AsyncTask`). – CommonsWare Aug 12 '12 at 21:26
  • 1
    @CommonsWare That's why I was asking for a better way. Are you sure there isn't any API that provides the Google Play version much faster? Can you post your suggestion on how to do that via AsyncTask? – Bill The Ape Aug 12 '12 at 21:46

1 Answers1

5

Are you sure there isn't any API that provides the Google Play version much faster?

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.

Can you post your suggestion on how to do that via AsyncTask?

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 in doInBackground() of an AsyncTask, with updating your UI (preferably via something non-modal) in the onPostExecute() of that same AsyncTask.

Here is a sample project demonstrating an AsyncTask that performs an HTTP operation (pulling a weather forecast from the US National Weather Service) and parsing the result, updating the UI (populating a WebView) when done.

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491