【问题标题】:Get version code of the latest app from playstore programmatically in case of multiple apks在多个 apk 的情况下,以编程方式从 playstore 获取最新应用程序的版本代码
【发布时间】:2017-04-26 05:49:16
【问题描述】:

我在从 Playstore 获取我的应用的最新版本代码时遇到问题。我在 Playstore 上上传了 app apk 和 wear apk。现在,当我致电 Playstore 以获取可用的最新版本的移动应用程序时,如果提供以下响应:

因设备而异

那么有什么方法可以获取最新版本的移动应用代码吗?

下面是我用来检索应用程序最新版本代码的代码。

private class GetVersionCode extends AsyncTask<Void, String, String> {
    @Override
    protected String doInBackground(Void... voids) {
        String newVersion = null;
        try {
            newVersion = Jsoup.connect("https://play.google.com/store/apps/details?id=" + getApplicationContext().getPackageName() + "&hl=it").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();
            return newVersion;
        } catch (Exception e) {
            return null;
        }
    }

    @Override
    protected void onPostExecute(String onlineVersion) {
        super.onPostExecute(onlineVersion);
        if (onlineVersion != null && !onlineVersion.isEmpty()) {
            String currentVer = getIntVersionNumber(currentVersion);
            String onlineVer = getIntVersionNumber(onlineVersion);
            if (Integer.parseInt(currentVer) < Integer.parseInt(onlineVer)) {
                showAlertDialog(onlineVersion);
            }
        }
    }
}

【问题讨论】:

  • 实际错误是什么?您不是从上面的 JSOUP 方法或其他方法中获取版本号吗?
  • 在您的情况下,不同的版本代码是预期的行为,因为您有多个 apk,即用于移动和穿戴。
  • @BhupatBheda 我没有从 jsoup 获得任何版本代码,而是给我提供了可用版本的字符串。
  • @MuhammadBabar 是的,但问题是如何为移动应用获取最新的 apk 版本。
  • 其实没有api可以获取这样的版本。您可以做的是在您自己的数据库服务器中添加版本,然后根据设备类型相应地获取。

标签: android android-studio android-version


【解决方案1】:

您会收到“因设备而异”,因为应用程序在设备上运行的版本不同

如果有版本号,那么你可以得到版本号,否则不可能

【讨论】:

  • 好的。它的显示与您的图片中显示的相同。那么在这种情况下,我如何获得版本号,因为我每次添加新的 apk 时都必须告诉用户更新?有什么解决办法吗?
猜你喜欢
  • 1970-01-01
  • 2022-11-16
  • 1970-01-01
  • 2021-10-07
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多