I am using this code to get the Google Play Store app version but this is causing my app to hang. Please specify another way to get the app version or how I can use this code to make the app not hang and run successfully.
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;
}
}
This is my code to get the app version from 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();
}
Just replace your code
.get()
.select("div[itemprop=softwareVersion]")
.first()
.ownText();
with below:
.get()
.select(".hAyfc .htlgb")
.get(3)
.ownText();
it will work..!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With