androidgoogle-playauto-update

How to get the app's latest version from Google play?


I added my app to Google Play.

I want to pop up a dialog box to remind the user when the user launches the application, if there is a new update, the user can click "update" and then jump to Google Play.

I saw the following question, but unfortunately the answer is no longer working.

How to get application version from google play?

Google does not seem to provide any API to get the app version.

I am searching for a long time on net. Many answers are said to get the version number through Jsoup, but no use now. Please help or try to give some ideas how to achieve this.

Here are the two methods I have tried:

(1)

newVersionName = Jsoup.connect("https://play.google.com/store/apps/details?id=" + BuildConfig.APPLICATION_ID + "&hl=en")
                    .timeout(30000)
                    .userAgent("Mozilla/5.0 (Windows; U; WindowsNT 5.1; en-US; rv1.8.1.6) Gecko/20070725 Firefox/2.0.0.6")
                    .referrer("http://www.google.com")
                    .get()
                    .select("div[itemprop=softwareVersion]")
                    .first()
                    .ownText();

(2)

         Document document = Jsoup.connect("https://play.google.com/store/apps/details?id=" + BuildConfig.APPLICATION_ID + "&hl=en")
                    .timeout(30000)
                    .userAgent("Mozilla/5.0 (Windows; U; WindowsNT 5.1; en-US; rv1.8.1.6) Gecko/20070725 Firefox/2.0.0.6")
                    .referrer("http://www.google.com")
                    .get();

            if (document != null) {
                Elements element = document.getElementsContainingOwnText("Current\\sVersion");
                for (Element ele : element) {
                    if (ele.siblingElements() != null) {
                        Elements sibElemets = ele.siblingElements();
                        for (Element sibElemet : sibElemets) {
                            newVersionName = sibElemet.text();
                        }
                    }
                }
            }

Solution

  • The following method is possible: replace "Current\\sVersion" with "Current Version":

         Document document = Jsoup.connect("https://play.google.com/store/apps/details?id=" + BuildConfig.APPLICATION_ID + "&hl=en")
                    .timeout(30000)
                    .userAgent("Mozilla/5.0 (Windows; U; WindowsNT 5.1; en-US; rv1.8.1.6) Gecko/20070725 Firefox/2.0.0.6")
                    .referrer("http://www.google.com")
                    .get();
    
            if (document != null) {
                Elements element = document.getElementsContainingOwnText("Current Version");
                for (Element ele : element) {
                    if (ele.siblingElements() != null) {
                        Elements sibElemets = ele.siblingElements();
                        for (Element sibElemet : sibElemets) {
                            newVersionName = sibElemet.text();
                        }
                    }
                }
            }