javiersantos / AppUpdater

A library that checks for your apps' updates on Google Play, GitHub, Amazon, F-Droid or your own server. API 9+ required.
Apache License 2.0
1.98k stars 412 forks source link

The position of the Play Store version is hardcoded #140

Open sillysachin opened 6 years ago

sillysachin commented 6 years ago

The playstore listing has some time no entry for parameters like Size as in my case - https://play.google.com/store/apps/details?id=com.appbootup.ipo.news&hl=en

I checked that some apps have it and some do not - https://play.google.com/store/apps/details?id=com.olacabs.customer

In essence version = getJsoupString(updateURL.toString(), ".hAyfc .htlgb", 7); does not work in my apps case.

The solution it would seen to process all the fields with their titles nearby and then conclude which ones i version tag.

sillysachin commented 6 years ago

version = getJsoupString(updateURL.toString(), ".hAyfc", 7);

private static String getJsoupString(String url, String css, int position) throws Exception {
        final Document document = Jsoup.connect(url).timeout(30000).userAgent("Mozilla/5.0 (Windows; U; WindowsNT 5.1; en-US; rv1.8.1.6) Gecko/20070725 Firefox/2.0.0.6").get();
        final Elements elements = document.select(css);
        String version = "";
        for (Element element : elements) {
            if (element.childNodeSize() == 2) {
                final String title = element.child(0).ownText();
                final String value = element.child(1).child(0).child(0).ownText();
                if ("Current Version".equalsIgnoreCase(title)) {
                    version = value;
                }
            }
        }
        return version;
    }
javiersantos commented 6 years ago

Thank you @sillysachin. It could be a good workaround to avoid the position but unfortunately, String title = element.child(0).ownText(); could be in other language rather than English. We should avoid hardcoded titles too.

sillysachin commented 6 years ago

Can you provide a callback way to handle this allowing developers to handle the scenarios? Currently i forked the entire repo, copy pasted into my folder structure and made it work.

sillysachin commented 6 years ago

https://play.google.com/store/apps/details?id=com.appbootup.ipo.news&hl=en and https://play.google.com/store/apps/details?id=com.appbootup.ipo.news&hl=hi

The hl parameter will ensure the title is always in english and i am slightly guessing is good enough solution.

marcosrocha85 commented 4 years ago

Sorry to join the party too late. What position stands for? I made a full migration to Kotlin and I'm intended to use AppUpdater in a project of mine. I can provide this callback in version 3.0.

fukemy commented 3 years ago

@marcosrocha85 hi, did u solved Jsoup problem?

marcosrocha85 commented 3 years ago

@fukemy I ended giving up and I forgot why 😳

fukemy commented 3 years ago

thanks, i just gave up too, trying to using https://developer.android.com/guide/playcore/in-app-update