Android get Google Play Store app version

前端 未结 8 1633
渐次进展
渐次进展 2021-02-06 11:49

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

8条回答
  •  傲寒
    傲寒 (楼主)
    2021-02-06 12:15

    Google change the API from 'softwareVersion' to 'currentVersion' and we can get the same version using ".hAyfc .htlgb"

    Below code will not work i.e.

    latestVersion = Jsoup.connect("https://play.google.com/store/apps/details?id=" + context.getPackageName() + "&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();
    

    Instead of above code just add this code, it will work fine i.e.

    Document document = Jsoup.connect("https://play.google.com/store/apps/details?id=" + context.getPackageName() + "&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();
        if(document != null) {
            if(document.select(".hAyfc .htlgb").get(5) != null) {
                latestVersion = document.select(".hAyfc .htlgb").get(5).ownText();
            } else {
                latestVersion = currentVersion;
            }
        }
    
    Note: There is no official API to get the current application version from Google Play. So use the above code to get the current version. Sometimes get(5).ownText() will change as google is updating the Google Play site. [Previously it was working with get(2).ownText()].
    

提交回复
热议问题