Reputation: 137
I have a force update in my android application, where it checks the version name of my app on the play store and also, verifies with my app update. If the google play store version differs from the current version it displays a popup message for the update.
When the user presses the update button on the popup, it redirects to the play store. The issue is, on google play store, in some devices, the 'Update' button is not displayed and the 'Open' button is displayed.
I tried clearing the cache, and it worked. But it's not very convenient for the user to do the same. And on how many devices, do I have to keep doing this.
This is my code below, for verifying the app version:
protected String doInBackground(String... urls) {
try {
newVersion = Jsoup.connect("https://play.google.com/store/apps/details?id=" + <Your package name> + "&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.hAyfc:nth-child(4) > span:nth-child(2) > div:nth-child(1) > span:nth-child(1)")
.first()
.ownText();
return newVersion;
} catch (Exception e) {
e.printStackTrace();
return "";
}
}
And this is the code for redirecting to google play store:
try {
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.setData(Uri.parse("market://details?id=" + context.getPackageName()));
startActivity(intent);
dialog.dismiss();
} catch (Exception e) {
e.printStackTrace();
}
As I have already told you that in some devices its working fine, while in some, I had to clear the Google Play Store cache.
What could be the desired solution?
Thanks in advance.
Upvotes: 0
Views: 357
Reputation: 44821
What you are doing is not recommended at all.
You are trying to scrape the website searching for specific HTML or CSS tags which are auto-generated and could vary every time they build the play site and between different version of PlayStore based on server which serves the page, this could break your logic in any moment.
The correct way to handle this scenario is using the In-app Update Library for Android API >= 21 (Lollipop) and for Android < 21 using your own backend with a REST API which can be queried to get the latest available version (but you need to handle this manually).
The problem you are seeing is probably related to the fact that your logic is reading wrong values from PlayStore in some cases. Something already reported in similar libraries here and here which use hardcoded scraping.
Upvotes: 1