2

I am facing an issue in fetching the latest version code of my app from the playstore. I have app apk as well as wear apk uploaded on the playstore. Now when I call playstore to get the latest version of the mobile app available, if provide response as:

It varies according to the device

So is there any way to get the the latest version code of the mobile app?

Below is the code I am using to retrieve the latest version code of the app.

private class GetVersionCode extends AsyncTask<Void, String, String> {
    @Override
    protected String doInBackground(Void... voids) {
        String newVersion = null;
        try {
            newVersion = Jsoup.connect("https://play.google.com/store/apps/details?id=" + getApplicationContext().getPackageName() + "&hl=it").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();
            return newVersion;
        } catch (Exception e) {
            return null;
        }
    }

    @Override
    protected void onPostExecute(String onlineVersion) {
        super.onPostExecute(onlineVersion);
        if (onlineVersion != null && !onlineVersion.isEmpty()) {
            String currentVer = getIntVersionNumber(currentVersion);
            String onlineVer = getIntVersionNumber(onlineVersion);
            if (Integer.parseInt(currentVer) < Integer.parseInt(onlineVer)) {
                showAlertDialog(onlineVersion);
            }
        }
    }
}
halfer
  • 19,824
  • 17
  • 99
  • 186
DPP
  • 59
  • 6
  • what is the actual error? Don't you get version number from above JSOUP method or anything else? – Bhupat Bheda Apr 26 '17 at 06:12
  • Varying version code in your case is the expected behavior because you have multiple apks i.e for mobile and wear. – Muhammad Babar Apr 26 '17 at 06:36
  • @BhupatBheda i am not getting any version code from jsoup, instead it is giving me string as varied versions available. – DPP Apr 26 '17 at 07:00
  • @MuhammadBabar yes, but the question is how to get the latest apk version for mobile app. – DPP Apr 26 '17 at 07:01
  • Actually there is no api available to get the version like this. What you can do is add the version in your own database server and then fetch accordingly to the device type. – Muhammad Babar Apr 26 '17 at 07:39
  • This is not working at all.. wasted a complete day over it. – Zafar Imam Apr 02 '18 at 06:10

1 Answers1

1

you get "Varies with device" because application run a different version on devices

enter image description here

if there is version number then you can get version number otherwise not possible

Bhupat Bheda
  • 1,968
  • 1
  • 8
  • 13
  • Ok. it is showing the same as shown in your pic. So in this case how can i get the version number, as i have to tell users to update every time i add new apk? any solutions? – DPP Apr 26 '17 at 08:33