首页 > 解决方案 > android - Google Play 商店上未显示更新按钮

问题描述

我在我的 android 应用程序中进行了强制更新,它会在 Play 商店中检查我的应用程序的版本名称,并通过我的应用程序更新进行验证。如果 google play 商店版本与当前版本不同,它会显示更新的弹出消息。

当用户按下弹出窗口上的更新按钮时,它会重定向到 Play 商店。问题是,在 google play store 上,在某些设备中,“更新”按钮不显示,而显示“打开”按钮。

我尝试清除缓存,它工作。但是用户这样做不是很方便。在多少设备上,我必须继续这样做。

这是我下面的代码,用于验证应用程序版本:

protected String doInBackground(String... urls) {
        try {

            newVersion =  Jsoup.connect("https://play.google.com/store/apps/details?id=" + <Your package name> + "&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.hAyfc:nth-child(4) > span:nth-child(2) > div:nth-child(1) > span:nth-child(1)")
                    .first()
                    .ownText();
            return newVersion;

        } catch (Exception e) {
            e.printStackTrace();
            return "";
        }
    }

这是重定向到谷歌游戏商店的代码:

try {
                Intent intent = new Intent(Intent.ACTION_VIEW);
                intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                intent.setData(Uri.parse("market://details?id=" + context.getPackageName()));
                startActivity(intent);
                dialog.dismiss();
            } catch (Exception e) {
                e.printStackTrace();

            }

正如我已经告诉过你的那样,在某些设备中它工作正常,而在某些设备中,我必须清除 Google Play 商店的缓存。

什么是理想的解决方案?

提前致谢。

标签: javaandroidandroid-studio

解决方案


根本不推荐您正在做的事情。

您正在尝试抓取网站搜索特定的 HTML 或 CSS 标签,这些标签是自动生成的,并且每次构建播放站点时以及基于为页面提供服务的服务器的不同版本的 PlayStore 之间可能会有所不同,这可能会破坏您的任何逻辑片刻。

处理这种情况的正确方法是使用Android API >= 21 (Lollipop) 和 Android < 21的应用内更新库,使用您自己的后端和 REST API,可以查询以获取最新的可用版本(但您需要手动处理)。

您看到的问题可能与您的逻辑在某些情况下从 PlayStore 读取错误值有关。已经在此处此处的类似库中报告了使用硬编码抓取的内容。


推荐阅读