Peter
Peter

Reputation: 11920

Can an Android app auto-upgrade itself?

The device my Android app is running does not have Playstore on it. The plan is to pre-install the software when shipping the device. I am now looking for a strategy to upgrade the application.

I found this useful link to install an Android app from the apk file:

Android: install .apk programmatically

I am thinking I will use this logic to auto-upgrade my app. I am wondering if it is even possible. I am thinking the upgrade will first try to uninstall existing version but will fail as the executable is still running and the file may be locked. Is there a better way? Regards.

Upvotes: 2

Views: 7444

Answers (4)

htafoya
htafoya

Reputation: 19273

Yes but as far as I remember only if you had Root privileges in order to have access to the INSTALL_PACKAGES permission.

Upvotes: 0

Ricky
Ricky

Reputation: 7889

Peter, we've just implemented the same thing.

Users have the software pre-installed on their device and we host update APK's on the companies servers.

From the app they can then check for updates where we have a WCF service which extracts the APK file (essentially a .zip) and returns the manifest details. From there we have the version of the APK and can compare it against the local version.

If the user decides to upgrade they can download the APK and you can automatically launch it. At which point the user will be told the application is going to be updated. There are no file locks etc, the app will just close and restart using the new version.

Note: Downgrading is not "automatic". The user would have to first uninstall the app. For upgrades, however, it's a simple case of downloading and launching the APK version (the user will be told they need to allow installations from unknown sources if this is not checked).

Upvotes: 6

serv-inc
serv-inc

Reputation: 38247

If your app is open-source, F-Droid would solve the problem for you.

F-Droid is an installable catalogue of FOSS (Free and Open Source Software) applications for the Android platform. The client makes it easy to browse, install, and keep track of updates on your device.

Mainly, it updates your app when necessary. (Or just have a look at its source code for inspiration on how to do it).

Upvotes: 0

Knossos
Knossos

Reputation: 16058

You have a couple of options, depending upon your target system.

  1. Use the link you posted. This will provide the user with a traditional install dialog, whereby the user can choose to install or not. You should avoid doing that automatically, as APKs can be large and you might irritate the user if they don't want updates.

  2. You can install updates magically, but you will require the firmware signing key (or possibly root, but I haven't tested that). That will not ask for consent from the user. You will need to add additional code using reflection to access the installation methods of Android. If you go this way, you should build an opt-out/in mechanism.

Upvotes: 0

Related Questions