我在从 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);
}
}
}
}
最佳答案
关于android - 在多个 apk 的情况下,以编程方式从 playstore 获取最新应用程序的版本代码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43626017/