【发布时间】:2018-02-22 12:04:32
【问题描述】:
我正在使用此代码获取 Google Play 商店应用程序版本,但这会导致我的应用程序挂起。请指定获取应用版本的另一种方式或如何使用此代码使应用不挂起并成功运行。
public class VersionChecker extends AsyncTask<String, String, String> {
private String newVersion;
@Override
protected String doInBackground(String... params) {
try {
newVersion = Jsoup.connect("https://play.google.com/store/apps/details?id=" + "trai.gov.in.dnd" + "&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[itemprop=softwareVersion]")
.first()
.ownText();
} catch (IOException e) {
e.printStackTrace();
}
return newVersion;
}
}
这是我从 asynctask 获取应用版本的代码
VersionChecker versionChecker = new VersionChecker();
try {
String appVersionName = BuildConfig.VERSION_NAME;
String mLatestVersionName = versionChecker.execute().get();
if (versionChecker.compareVersionNames(appVersionName, mLatestVersionName) == -1) {
showAppUpdateDialog();
}
} catch (InterruptedException | ExecutionException e) {
e.printStackTrace();
}
【问题讨论】:
-
适用于特定应用?
-
是的特定应用程序
-
你能粘贴调用这个异步任务的函数的代码吗?
-
您是如何修复 compareVersionNames 错误的?
-
你好兄弟,直到今天你还在使用 asyntask,还是因为 asyntask 已经被弃用,你已经找到了替代方案。
标签: android google-play version