Programmatically check Play Store for app updates
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.
Android get Google Play Store app version
Just replace your code
.get()
.select("div[itemprop=softwareVersion]")
.first()
.ownText();
with below:
.get()
.select(".hAyfc .htlgb")
.get(3)
.ownText();
it will work..!
How to inform the users of an Android app that a new version is available in the Google Play Store through Notification
To achieve this you can use the In App Update API.
You can find out how to implement it here in Google's documentation: https://developer.android.com/guide/playcore/in-app-updates
Programmatically trigger app update from Google play
Usually update is installed within 24 hours, provided the user maintains active connection with internet and sufficient battery. Android boxes do not have any battery, so automatic updates via google play (without any user interaction) are not reliable.
Use this code for issuing auto update without playstore.
Add this permission: <uses-permission android:name="android.permission.ACCESS_SUPERUSER" />
Use the following function:
public static void installAPK(String filename) {
File file = new File(filename);
if (file.exists()) {
Runtime.getRuntime().exec("chmod 777 " + filename);
String command;
command = "pm install -r " + filename;
Process proc = Runtime.getRuntime().exec(new String[]{"su", "-c", command});
proc.waitFor();
}
}
Note: This would work only if you are not requesting any extra permissions for the app since last install.
Related Topics
Listview Subobject Clickable Confilct
How to "Select Android Sdk" in Android Studio
Coloring Buttons in Android with Material Design and Appcompat
What Are My Options for Storing Data When Using React Native? (iOS and Android)
How to Show a Dialog to Confirm That the User Wishes to Exit an Android Activity
Get Bitmap Attached to Imageview
Android Layout Replacing a View with Another View on Run Time
Common Class for Asynctask in Android
Is There a List of Screen Resolutions for All Android Based Phones and Tablets
How to Delete a Whole Folder and Content
How to Change Color of Textinputlayout's Label and Edittext Underline Android
Java.Lang.Illegalargumentexception: View Not Attached to Window Manager
Change Drawable Color Programmatically
How to Remove a Button or Make It Invisible in Android
Firebase Fcm Force Ontokenrefresh() to Be Called