AmigoPal
AmigoPal

Reputation: 39

How to fetch the live app version programmatically?

Initially, to fetch the live app version programmatically I was using the following snippet

 try {
            newVersion = Jsoup.connect("https://play.google.com/store/apps/details?id=" + appPackageName + "&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(".hAyfc .htlgb")
                    .get(7)
                    .ownText();
        } catch (IOException e) {
            e.printStackTrace();
        }

But at the end of May 2022, this snippet started throwing exceptions. Is anyone having a similar issue? Any fixes are very welcome.

***Solution***

Google Provides an official solution for this now

Use AppUpdateManager

from the official documentation

Check for update availability

Before requesting an update, you need to first check if one is available for your app. To check for an update, use AppUpdateManager, as shown below:

// Creates instance of the manager. 
 AppUpdateManager appUpdateManager = AppUpdateManagerFactory.create(context);
    
// Returns an intent object that you use to check for an update.
Task<AppUpdateInfo> appUpdateInfoTask = appUpdateManager.getAppUpdateInfo();
    
// Checks that the platform will allow the specified type of update. appUpdateInfoTask.addOnSuccessListener(appUpdateInfo -> {
        if (appUpdateInfo.updateAvailability() == UpdateAvailability.UPDATE_AVAILABLE
              // For a flexible update, use AppUpdateType.FLEXIBLE
              && appUpdateInfo.isUpdateTypeAllowed(AppUpdateType.IMMEDIATE)) {
                  // Request the update.
        } }); 

The result contains the update availability status. If an update is available and the update is allowed, the returned AppUpdateInfo also contains an intent to start the update. See the next section for how to start the update.

If an in-app update is already in progress, the result will also report the status of the in-progress update.

This worked for me. Hope it helps !

Upvotes: 0

Views: 463

Answers (1)

JakeGilesPhillips
JakeGilesPhillips

Reputation: 193

Yes, google updated their play store website, that solution no longer works. The dom structure has changed, app versions are no hidden behind a modal that is dynamically loaded. I am currently in the process of trying to find a new solution as well.

Upvotes: 2

Related Questions