Querying latest application version from the Android Market

后端 未结 4 589
無奈伤痛
無奈伤痛 2021-01-07 07:15

Can I query the Android Market for the latest version of my application in code? I would like to show an update notification for the user when a new version is available.

相关标签:
4条回答
  • 2021-01-07 07:34

    I bumped into the same problem here. So I thought... why not use AppBrain.

    I wrote a small function that gets your latest app version from the AppBrain website.

    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;
    }
    

    I use the jsoup Java HTML Parser to parse the HTML and from there on it's pretty simple.

    Once you've retrieved it, since it's a String the best way I can think of to compare two versions together is to remove the full stops (.) that way your version number would go from say 1.1.2 to 112 then it's just a simple matter of comparing two Integers.

    0 讨论(0)
  • 2021-01-07 07:35

    I found a work around that may just work. Name you app like this:

    My App - V.1.12

    Now you can quay your app page on the market. The title will be: My App - V.1.12 - Android Apps on Google Play

    Assuming that you change the app name version on each release, this will work.

    0 讨论(0)
  • 2021-01-07 07:42

    I found this one which might be useful for some people

    https://code.google.com/p/android-query/wiki/Service

    0 讨论(0)
  • 2021-01-07 07:43

    I know of no way to make that query, sorry.

    0 讨论(0)
提交回复
热议问题