Reputation: 59
I am facing an issue in fetching the latest version code of my app from the playstore. I have app apk as well as wear apk uploaded on the playstore. Now when I call playstore to get the latest version of the mobile app available, if provide response as:
It varies according to the device
So is there any way to get the the latest version code of the mobile app?
Below is the code I am using to retrieve the latest version code of the 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);
}
}
}
}
Upvotes: 2
Views: 1410
Reputation: 1978
you get "Varies with device" because application run a different version on devices
if there is version number then you can get version number otherwise not possible
Upvotes: 1