在您的应用程序build.gradle文件中包含JSoup:
dependencies {
compile 'org.jsoup:jsoup:1.8.3'
}
并获得当前版本,例如:
currentVersion = getPackageManager().getPackageInfo(getPackageName(), 0).versionName;
并执行以下线程:
private class GetVersionCode extends AsyncTask {
@Override
protected String doInBackground(Void... voids) {
String newVersion = null;
try {
newVersion = Jsoup.connect("https://play.google.com/store/apps/details?id=" + MainActivity.this.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 newVersion;
}
}
@Override
protected void onPostExecute(String onlineVersion) {
super.onPostExecute(onlineVersion);
if (onlineVersion != null && !onlineVersion.isEmpty()) {
if (Float.valueOf(currentVersion) < Float.valueOf(onlineVersion)) {
//show dialog
}
}
Log.d("update", "Current version " + currentVersion + "playstore version " + onlineVersion);
}
有关更多详细信息,请访问:http : //revisitingandroid.blogspot.in/2016/12/programmatically-check-play-store-for.html