Auto Update APK version on Android Phone - android

If a user downloads my app (a .apk file) onto their android phone from the market place,
Where does the .apk file end up on their phone?
When they're running my application, if I detect that there is a new later version of the application available is it possible to from within the application that they're running download the latest version off an ftp link (I can programmatically do that now) and then replace the existing .apk that they're now running with the newer version. [Not sure about this one at all.]
Is the existing application all in memory when it's being run, so that when i download the new version, I can delete its apk file without it being locked up and replace it with the later build and then restart the app?
What's the best way to handle this scenario? I have an app where I want to ensure that users are on the latest version before they use it.

Apps are stored in /data/app see https://android.stackexchange.com/questions/3002/where-in-the-file-system-are-applications-installed.
IMHO, You should let the market manage updates for you, there's no need to bother doing anything by hand and as an user I would be "angry" if some app start downloading stuff on my phone without my consent, especially when abroad (some users are paying their datas).

If this user has rooted phone, you may use code provided in this answer: Android silent apk update.
If not, user has to be prompted, and you may start an activity with an intent (as usual), but also, before calling startActivity(intent), call intent.setDataAndType(Uri.fromFile(...)).

Related

check if an android app is malware before installation

I want to access the apk file of any app before installation.
In more details: in google play store when the user clicks on Install button I want my application to access the apk file of the application that the user wants to download, and analyze this apk file and be able to whether allow the installation or stop it.
is that possible and if so how to approach this
On Android this functionality was introduced in Android 4.2. It is usually used by anti-malware products like Google Play Protect is known as a "Package Verifier". There is a good blog post on it here.
The short answer is this has to be done as part of the phone manufacturing process as it is so critical to security. So the answer is it can be done, but if you write this code you will need to get a phone manufacturer to include your code as part of a phone system image.
Most third party anti-malware products instead rely on analyzing the APK after the install happens by listening to the package added notification.
Definitely not possible in the way that you want. Android's OS is pretty well locked down. You might be able to do something if the device was rooted but at that point you may as well write your own OS fork. You can attempt to do someting with https://developer.android.com/reference/android/content/Intent.html#ACTION_PACKAGE_ADDED broadcast but you will not be able to analyze the apk freely nor will you be able to stop the installation of it.

Updating android app not listed on play store?

For a customer of mine, we have developed an app which is provided with a tablet as a default launcher. Now every so often we want to update the app - preferably without access to the tablet - so pretty much remotely. The app is not listed on play store, it's being installed as a .apk file by us in-house on the tablet and then sent to the customer.
How do I go about being able to force updates to it? App has internet connectivity, it's written in Cordova or Android native (we have 2 apps).
You can use the cordova File plugin to gain access and permission to write files to disk, then include a function that checks a value on your server to determine if the app is up to date or not. If the app is not running the current version... then your app can call a function that downloads the updated app pages/scripts and saves them locally.
To be safe, i would recommend implementing a dynamic splash screen (of your own) that checks to see if there are any downloaded update-files to be transferred to the active app directory.
So the next time the app starts, the splash screen will just stay up a little longer and let the user know that an update is in progress... whilst your update function copy, edit and replace the files in the background.
This is something you should test thoroughly before shipping as it can sometimes break your application if the app is suspended during a file write.
You can read more about the cordova file plugin here: https://cordova.apache.org/docs/en/latest/reference/cordova-plugin-file/

Auto Updating Sideloaded Android App on Start

We have an Android app (.apk) published to a publicly accessible URL, any user who knows the URL can download and install the app.
The app is already installed on the relevant user phones and allowing sideload option from the settings is turned on.
How can I force the app, on start, to check for update and replace the existing app if found, then restart the app (to pick up the latest version)?
Is there a standard solution or a software package? Should I be thinking in a different way?
I am using Xamarin Forms, however, I am happy with Xamarin Android or any Java-based solution.
One thing you could do is to have a small plain text file in the same server where the APK is, that contains the version number of the APK available on the server. The runing app then just reads that text file and compares against its own version number.
If the version on the server is newer (has a higher version number), you simply download the new APK to a temp dir and install the APK programatically using the method outlined here: Android: install .apk programmatically
The way to go is HockeyApp. It´s a distribution system that does exactly what you are looking for. Besides, you get a useful crash logger and some statistics, etc. It´s free for 2 apps.
Once you install and configure their SDK in your Android app, an activity will popup telling the user a new update is available if there is any.
The user can install the new version with a button tap. Simple.
The setup process involves installing a nuget package and write a few lines of code in your main Activity class.

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.
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).
You have a couple of options, depending upon your target system.
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.
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.
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).
Yes but as far as I remember only if you had Root privileges in order to have access to the INSTALL_PACKAGES permission.

Can I allow the user to uninstall an update of my android app?

For instance, Hangout allows you (on an old phone) to uninstall the updates to downgrade it to GTalk.
Can I allow the user to do so with my app?
I mean, I will push an update on the store, will we be able to uninstall this update and restore to the previous version?
No, you cannot. What you're describing only works in situations where the downgrade is resident in the device's /system partition (meaning it was pre-installed when the device firmware was built). Unless you're building your own ROM with the application resident, the old version won't be there to downgrade to.
Note that when building ROMs there are two ways to provide applications -- one by simply placing the APK into the right directory in /system, and the other by placing it somewhere that some other code locates and performs a pm install on. The downgrade feature is only possible when the APK has simply been placed where it needs to be with no pm install required.
As far as my understanding goes in the case of Hangouts/GTalk: GTalk is most likely installed as a system app, Hangouts is an update to GTalk which also renames the application. As with every application installed as a system app and updated via Google Play, the user may decide to remove the update (same as uninstalling any non-system app), thus restoring the factory-version of that app.
When updating an application which was previously installed via Google Play, the old version does not remain in the system. Therefore, I doubt that restoring an old version is possible when using Google Play to distribute your app.
If you really want your users to be able to go back to previous version, you should consider hosting older versions of your app on some sort of web server / dropbox / ftp / etc. Users may then grab those files and do a manual downgrade.

Categories

Resources