fatih
fatih

Reputation: 1181

Can an Android app upgrade itself?

Is it possible to update application from itself in Android? The app in question is a system app, so I can execute privileged commands. Also note that I don't want to show any notification to user, so everything should work in the background.

Upvotes: 2

Views: 1684

Answers (3)

Hans-Christoph Steiner
Hans-Christoph Steiner

Reputation: 2682

It is actually pretty easy for an app to update itself, the hard part is doing it without putting up a prompt to the user. The app needs to download the APK, then send it to the PackageManager API to install it. Android will then put up the install prompt. There is a library to handle that part:

As for doing it with prompting, the app needs privileged access. If the device is rooted, the app can request root access. The app can also be flashed as a "priv-app" so that it has privileged access. Or you can do it like F-Droid: flash the Privileged Extension as a "priv-app", and make your app send install/uninstall requests to Privileged Extension.

Otherwise, you need to download binary code, and dynamically load it, like @yusuf-x said. Be aware that Google is working to make that impossible in each new release of Android.

Upvotes: 2

Fdroid is an open source application repository. Their client app can install/update/delete apps from the fdroid repository, including itself.

See the code for the installer part of the client app here: https://gitlab.com/fdroid/fdroidclient/tree/master/app/src/main/java/org/fdroid/fdroid/installer

Upvotes: 0

Yusuf X
Yusuf X

Reputation: 14633

Use the Java ClassLoader to dynamically load code that was push or pulled down. – Yusuf X just now edit. I've used this for just such a purpose on Android.

Upvotes: 0

Related Questions