Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Programmatically check Play Store for app updates

Tags:

android

I have put my app on the Google Play Store. It has been installed by lots of my company's customers. I understand the mechanism of how the app is intended to upgrade.

The users should check the auto-update check box in the Playstore app for each app they want to auto-update. However some users have unchecked it or not checked it in the first place.

The app i have written is for the care industry and is used by carers to deliver homecare. Some of our customers my have 1200 carers. They would have to call all the carers into the office to update the phones individually. This is obviously unacceptable.

Is there a way to programmatically check if there is an updated version of my app on the Play Store?

Could i have code that runs every time the user starts the app that checks the Play Store? If there is an updated version then the user could be directed to the Playstore. This will mean it is not essential to have the auto-update checked.

like image 773
turtleboy Avatar asked Aug 08 '14 10:08

turtleboy


People also ask

How do you check app is updated or not in Android programmatically?

The users should check the auto-update check box in the Playstore app for each app they want to auto-update. However some users have unchecked it or not checked it in the first place.

Is there any official API to get app details from the Play Store?

Try this google official api: github.com/googlesamples/android-play-publisher-api/tree/master/…

Does Play Store automatically update apps?

By default, apps are updated automatically when the following constraints are met: The device is connected to a Wi-Fi network. The device is charging. The device is idle (not actively used).


2 Answers

Update 17 October 2019

https://developer.android.com/guide/app-bundle/in-app-updates

Update 24 april 2019:

Android announced a feature which will probably fix this problem. Using the in-app Updates API: https://android-developers.googleblog.com/2018/11/unfolding-right-now-at-androiddevsummit.html

Original:

As far a I know, there is no official Google API which supports this.

You should consider to get a version number from an API.

Instead of connecting to external APIs or webpages (like Google Play Store). There is a risk that something may change in the API or the webpage, so you should consider to check if the version code of the current app is below the version number you get from your own API.

Just remember if you update your app, you need to change the version in your own API with the app version number.

I would recommend that you make a file in your own website or API, with the version number. (Eventually make a cronjob and make the version update automatic, and send a notification when something goes wrong)

You have to get this value from your Google Play Store page (is changed in the meantime, not working anymore):

<div class="content" itemprop="softwareVersion"> x.x.x  </div> 

Check in your app if the version used on the mobile is below the version nummer showed on your own API.

Show indication that she/he needs to update with a notification, ideally.

Things you can do

Version number using your own API

Pros:

  • No need to load the whole code of the Google Play Store (saves on data/bandwidth)

Cons:

  • User can be offline, which makes checking useless since the API can't be accessed

Version number on webpage Google Play Store

Pros:

  • You don't need an API

Cons:

  • User can be offline, which makes checking useless since the API can't be accessed
    • Using this method may cost your users more bandwidth/mobile data
    • Play store webpage could change which makes your version 'ripper' not work anymore.
like image 126
Richard Lindhout Avatar answered Oct 21 '22 18:10

Richard Lindhout


Include JSoup in your apps build.gradle file :

dependencies {     compile 'org.jsoup:jsoup:1.8.3' } 

and get current version like :

currentVersion = getPackageManager().getPackageInfo(getPackageName(), 0).versionName; 

And execute following thread :

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=" + 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(".hAyfc .htlgb")                 .get(7)                 .ownText();         return newVersion;     } catch (Exception e) {         return newVersion;     }     }      @Override     protected void onPostExecute(String onlineVersion) {         super.onPostExecute(onlineVersion);         Log.d("update", "Current version " + currentVersion + "playstore version " + onlineVersion);         if (onlineVersion != null && !onlineVersion.isEmpty()) {             if (Float.valueOf(currentVersion) < Float.valueOf(onlineVersion)) {                 //show dialog             }         }     } 

For more details visit : http://revisitingandroid.blogspot.in/2016/12/programmatically-check-play-store-for.html

like image 23
Tarun Deep Attri Avatar answered Oct 21 '22 18:10

Tarun Deep Attri