0

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();
                        }
                    }
                }
            }
Benjamin Loison
  • 3,782
  • 4
  • 16
  • 33
alice
  • 23
  • 7
  • Did you try jsoup? Show your code – AIK Sep 07 '18 at 10:03
  • Hello @alice have you tried this https://stackoverflow.com/questions/4616095/how-to-get-the-build-version-number-of-your-android-application – Nilesh Panchal Sep 07 '18 at 10:07
  • You can also use gpsversion checker library – Vivek Mishra Sep 07 '18 at 10:07
  • possible duplicate of https://stackoverflow.com/questions/25201349/programmatically-check-play-store-for-app-updates – AIK Sep 07 '18 at 10:11
  • Possible duplicate of [Programmatically check Play Store for app updates](https://stackoverflow.com/questions/25201349/programmatically-check-play-store-for-app-updates) – AIK Sep 07 '18 at 10:27
  • Hello @AIK, the two methods I've tried have been re-added to the problem, and you can see them now, thanks. – alice Sep 07 '18 at 10:35
  • Does it give any errors? If so then post the error log as well. – AIK Sep 07 '18 at 10:37
  • Hello @Nilesh, thanks, but what I want to get is the version number of my app on Google play. – alice Sep 07 '18 at 10:41
  • Hello @Vivek, The gpsversion checker library seems to only support that updates via the app's server. but I want the user to jump to Google play to update. And I will read the documentation of this library again. Thanks. – alice Sep 07 '18 at 10:46
  • Hello @ AIK, the compiler didn't throw any exceptions, but after I opened this address in my browser, Google play prompts me: "We're sorry, the requested URL was not found on this server." This link: "https://play.google.com/store/apps/details?id=" + + "&hl=en" – alice Sep 07 '18 at 10:53
  • 1
    Hello @AIK, the answer you provided is feasible. thank you very much! – alice Sep 07 '18 at 11:21
  • I have used that library for fetching updates status from google play store – Vivek Mishra Sep 07 '18 at 11:28
  • @alice glad to help. – AIK Sep 07 '18 at 11:56
  • Afaik there is no any official way to query Google Play to determine if you are running latest version or not. If you really need to do so, you must store version info somewhere else, for example in Firebase or your own server. I don't recommend any "unofficial" hacks, they may suddenly stop working or get blocked by Google. – user1209216 Sep 07 '18 at 12:03

1 Answers1

0

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();
                    }
                }
            }
        }
alice
  • 23
  • 7