views:

34

answers:

1

We have to port our software to android. One of the main feature of our software should be that the software can download a new version of itself from the net (our own server) and install it's new version too. All this thing should be done programmatically.

I'm new to android, so haven't got any clue how should it be done.

  • How to create apk? - solved
  • How to sign apk? - solved
  • How to download apk? - solved
  • How to copy the downloaded file overwriting /data/apk/my.software.name.apk? - unsolved
  • How to restart the software by the running version? - unsolved

Please advise! Thanks in advance!

A: 

You do not have to do this. You just upload the new version of your program on the Android Market, and people see it right away. Users who checked the option "update automatically" for your program upgrade automatically without having to give explicit consent ; others see "upgrade available" and can just click 'upgrade' to upgrade to the new version of your program.

If for some reason you're thinking that you want to force the update on the user with or without their consent though, you just cannot do it. You can download the apk and should be able to hand it to the package manager, which in turn will ask the user to confirm whether they actually want to install it - and then again, for that you need the user to have checked the "allow unknown sources" option in development options, else the package manager will downright refuse to do it. But android will not let you install a new package without the user explicitly requesting it, or explicitly allowing auto-updates through the market.

If you have some backward compatibility issue of some sort and want to disallow running of deprecated versions of your application, you can embed in your application some logic that will check on your server for version information and terminate if it's outdated, with a message "this version is outdated, you need to upgrade to continue using this application" or something. But no upgrading in the back of the user.

Jean
The software is produced for a customer directly not for the android market. I've read about the package manager and the "allow unknown sources" thing too. For us informing the user and ask them to upgrade by pressing an "upgrade" button is accepted, but the question is:How I can overwrite my old apk with the downloaded version while it is running and also has no rights to overwrite it?
Barna
Ah, in that case you can just hand the new APK to the package manager. This is done by launching an intent of type VIEW with the downloaded file URL (local one, file://sdcard/.../myfile.apk), which will invoke the handler for apk files, which is the package manager. You'll have a message "this application will replace an installed application, all previous user data will be saved" and the application will be terminated, then upgraded. It will have to be re-run by hand (re-running it automatically is possible by creating an auxiliary app, but quite complicated).
Jean
Anyhow, must it be downloaded onto a storagecard or could it be downloaded onto the device storage itself?
Barna
If there is any place on the phone where you have both the space and the right to write, I think it could also be downloaded on the device storage itself. I think.
Jean