android - 在多个 apk 的情况下,以编程方式从 playstore 获取最新应用程序的版本代码

标签 android android-studio android-version

我在从 Play 商店获取我的应用的最新版本代码时遇到了问题。我有 app apk 以及在 playstore 上上传的 wear apk。现在,当我调用 playstore 获取最新版本的移动应用程序时,如果提供以下响应:

It varies according to the device

那么有什么办法可以获取最新的手机app版本码呢?

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

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

最佳答案

你得到“Varies with device”因为应用程序在设备上运行不同的版本

enter image description here

如果有版本号就可以得到版本号否则不可能

关于android - 在多个 apk 的情况下,以编程方式从 playstore 获取最新应用程序的版本代码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43626017/

相关文章:

java - Android 应用程序未在 KitKat 中运行

android - 我可以跳过询问棉花糖的运行时权限吗?

android - Eclipse 无法编译 apk

Android 截取我的应用程序 Activity 的屏幕截图

java - 按钮不执行正确的命令[编辑]

android - Gradle 嵌套、多项目、共享库环境设置

java - java 和 python 中的 Unicode 字符串支持

Java 处理程序如何在不发送 onUserInteraction 方法的情况下执行 Intent

android - 当我尝试创建图像 Assets 时,Android Studio 中不存在文件 Logo.png

android - 在Eclipse项目中升级android版本