How to get latest version of android app from Google Playstore?
Asked Answered
A

2

7

Question :

I want to get the latest version of my app in production, from Google Playstore. I want to add functionality to force upgrade, if some changes in the latest version require it.

What I have :

I am currently updating the latest version of the app on my server, and forcing the app to request for it and check the version against it. This works. But I do not want to update on my server everytime I release a new version. I want the app to be able to pick up the same information from Google Playstore instead.

What I need :

I can handle the logic at client side (on the app). All I need is an API call to Playstore to get my own app's latest production version. If anyone can help me with some pointers on this, it would be very helpful.

Aponeurosis answered 16/1, 2016 at 4:20 Comment(6)
Check if this still works. If it does, then you don't need to make any API calls.Stringboard
@IceMAN: That looks good. But I would still prefer something more lightweight. Which is why I would like to know, if I can make an API call to the Playstore and get that data myself.Aponeurosis
@IceMAN: So, I looked through the code and they are also scraping the webpage for the app on Playstore. That is the idea I initially had, but according to me, its not a very elegant solution. So, was wondering if there is an API.Aponeurosis
To the best of my knowledge, there isn't an official API. Most libraries that I have seen in the past have been scrapping the website. From what I can tell, either scrape the data yourself, or use the library (if it still works) and save some time with coding it yourself. Or, continue using your existing system if it's a lot let hassle.Stringboard
@IceMAN: For now, scraping the data myself! Thanks a ton for pointing me in the right direction! :)Aponeurosis
Possible duplicate of query the google play store for the version of an app?Outclass
M
4

You can check it with Android in-app-update. Android dev guide

Miasma answered 22/12, 2019 at 18:9 Comment(0)
D
1

There is a trick that you can implement for getting current play store version.

public void getUpdate() {
        final String appPackageName = getPackageName();
        Document doc = null;
        try {
            doc = Jsoup.connect("https://play.google.com/store/apps/details?id=" + appPackageName).get();
        } catch (IOException e) {
            e.printStackTrace();
        }
        // Document doc = Jsoup.parse(resString);
        if(doc!=null) {
            Element meta = doc.select("div[itemprop=softwareVersion]").first();
            String content = meta.ownText();
            System.out.println(content);
            Double playStoreVersion = Double.valueOf(content);
            Double currentVersion = getVersionName();
            if (playStoreVersion > currentVersion) {
                try {
                    new AlertDialog.Builder(SplashScreen.this)
                            .setTitle("Alert")
                            .setMessage("Update Is Available.Do You Want To Update?")
                            .setIcon(R.mipmap.ic_launcher)
                            .setCancelable(false)
                            .setPositiveButton("Update",
                                    new DialogInterface.OnClickListener() {
                                        public void onClick(DialogInterface dialog,
                                                            int id) {
                                            try {
                                                startActivityForResult(new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=" + appPackageName)), UPDATE_FROM_PLAY_STORE_REQUEST);

                                            } catch (Exception e) {
                                                try {
                                                    startActivityForResult(new Intent(Intent.ACTION_VIEW, Uri.parse("https://play.google.com/store/apps/details?id=" + appPackageName)), UPDATE_FROM_PLAY_STORE_REQUEST);
                                                } catch (Exception e1) {

                                                }
                                            }
                                            dialog.dismiss();
                                        }
                                    }).setNegativeButton("Not yet", new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialogInterface, int i) {
                            dialogInterface.dismiss();
                            Handler();

                        }
                    }).show();
                    //startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("https://play.google.com/store/apps/details?id=" + appPackageName)));
                } catch (android.content.ActivityNotFoundException anfe) {
                    try {
                        startActivityForResult(new Intent(Intent.ACTION_VIEW, Uri.parse("https://play.google.com/store/apps/details?id=" + appPackageName)), UPDATE_FROM_PLAY_STORE_REQUEST);
                    } catch (Exception e) {
                    }
                }
            } else {
                Handler();
            }
        }else {
            Handler();
        }
}

get the version of our own application.

public Double getVersionName() {
    Double VersionName = 0.0;
    try {
        String vName = SplashScreen.this.getPackageManager().getPackageInfo(SplashScreen.this.getPackageName(), 0).versionName;
        VersionName = Double.valueOf(vName);

    } catch (PackageManager.NameNotFoundException e) {
        e.printStackTrace();
    } catch (Exception e) {
        e.printStackTrace();
    }
    return VersionName;
}
Downstate answered 20/11, 2017 at 11:35 Comment(2)
That's a good workaround @ChandraShekhar! But it still scrapes the data from playstore listing. That is what I am currently doing. But I had asked if there was any API available for this. Scraping data, is never a good idea as even a minute change in the HTML of playstore listing, will break the logic.Aponeurosis
No, there isn't any official API for getting the apps version from play store.Downstate

© 2022 - 2024 — McMap. All rights reserved.