Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android get Google Play Store app version

I am using this code to get the Google Play Store app version but this is causing my app to hang. Please specify another way to get the app version or how I can use this code to make the app not hang and run successfully.

public class VersionChecker extends AsyncTask<String, String, String> {

    private String newVersion;

    @Override
    protected String doInBackground(String... params) {

        try {
            newVersion = Jsoup.connect("https://play.google.com/store/apps/details?id=" + "trai.gov.in.dnd" + "&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();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return newVersion;
    }
}

This is my code to get the app version from asynctask

VersionChecker versionChecker = new VersionChecker();
try {
    String appVersionName = BuildConfig.VERSION_NAME;
    String mLatestVersionName = versionChecker.execute().get();
    if (versionChecker.compareVersionNames(appVersionName, mLatestVersionName) == -1) {
        showAppUpdateDialog();
    }
} catch (InterruptedException | ExecutionException e) {
    e.printStackTrace();
}
like image 208
Priyanka Singhal Avatar asked Feb 22 '18 12:02

Priyanka Singhal


1 Answers

Just replace your code

.get()
.select("div[itemprop=softwareVersion]")
.first()
.ownText();

                    

with below:

.get()
.select(".hAyfc .htlgb")
.get(3)
.ownText();

it will work..!

like image 93
Ketan Patel Avatar answered Sep 28 '22 08:09

Ketan Patel