【发布时间】: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