简体   繁体   English

android-更新按钮未显示在Google Play商店中

[英]android - Update button is not displaying on Google Play Store

I have a force update in my android application, where it checks the version name of my app on the play store and also, verifies with my app update. 我的Android应用程序中有一个强制更新,它会在Play商店中检查我的应用的版本名称,并通过我的应用更新进行验证。 If the google play store version differs from the current version it displays a popup message for the update. 如果Google Play商店的版本与当前版本不同,则会显示一条用于更新的弹出消息。

When the user presses the update button on the popup, it redirects to the play store. 当用户按下弹出窗口上的更新按钮时,它将重定向到Play商店。 The issue is, on google play store, in some devices, the 'Update' button is not displayed and the 'Open' button is displayed. 问题是,在Google Play商店的某些设备上,未显示“更新”按钮,而显示了“打开”按钮。

I tried clearing the cache, and it worked. 我尝试清除缓存,并且它起作用了。 But it's not very convenient for the user to do the same. 但这对用户来说不是很方便。 And on how many devices, do I have to keep doing this. 在多少设备上,我必须继续这样做。

This is my code below, for verifying the app version: 这是我的以下代码,用于验证应用版本:

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 "";
        }
    }

And this is the code for redirecting to google play store: 这是用于重定向到Google Play商店的代码:

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();

            }

As I have already told you that in some devices its working fine, while in some, I had to clear the Google Play Store cache. 正如我已经告诉您的那样,在某些设备中它可以正常工作,而在某些设备中,我必须清除Google Play商店缓存。

What could be the desired solution? 可能需要什么解决方案?

Thanks in advance. 提前致谢。

What you are doing is not recommended at all. 根本不建议您在做什么。

You are trying to scrape the website searching for specific HTML or CSS tags which are auto-generated and could vary every time they build the play site and between different version of PlayStore based on server which serves the page, this could break your logic in any moment. 您正在尝试抓取网站,以搜索自动生成的特定HTML或CSS标记,这些标记可能会在每次构建播放网站时以及基于提供该页面的服务器的不同版本的PlayStore之间发生变化,这可能会破坏您的逻辑时刻。

The correct way to handle this scenario is using the In-app Update Library for Android API >= 21 (Lollipop) and for Android < 21 using your own backend with a REST API which can be queried to get the latest available version (but you need to handle this manually). 解决此情况的正确方法是使用应用内更新库(适用于Android API> = 21(Lollipop),适用于Android <21),并使用自己的后端和REST API,可以查询该API以获取最新的可用版本(但是您可以需要手动处理)。

The problem you are seeing is probably related to the fact that your logic is reading wrong values from PlayStore in some cases. 您看到的问题可能与某些情况下您的逻辑正在从PlayStore读取错误的值有关。 Something already reported in similar libraries here and here which use hardcoded scraping. 此处此处的类似库中已经报告了某些使用硬编码抓取的内容。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM