How do I update my application’s APK when the user requests it?

Asked

Viewed 8,992 times

2

Explanation:

I have an application that is constantly made quite changes, and every time I do, I get a new version with the same Private Key(Keystore), I mean, when I send the new *.APK install on the device no settings are lost and the application is simply updated. So far so good.

Question:

However, I don’t want the user to have to download a new *.APK on my website and later install every time it is necessary to update it, I would like to make a "Update" button and when click, transfer the new *.APK with a progress bar monitoring the end of the download for the device, and automatically installing it, with another progress bar monitoring the end of the installation(if it is not possible can be an "ajax" that would be that progress that is rotating without forecast), how should I do this?

Important detail:

I don’t want to use Google Play to do this for me because some users who own my application cannot, at a certain point, use, for example, version 1.21, and only 1.20, while other users can already upgrade to version 1.21.

Also, I would not like the update to be performed automatically, because I need the user to finish all the services in their application before being able to update. And it should only update when prompted to click the button.

  • Why not just put your app in the play store and let google do it for you?

  • Because it is not all users who can update my application at certain times, some users can only use version 1.20 for example and others can already use 1.21.

  • You can make different versions available to each group of users through the play store.

  • But even so, I can’t let them update when they want, my application that should control if it can be updated, IE, it should only be updated when there is no open service in the application, only when the user finishes all the services he can update. He should be aware of this update and the version he should download should be compatible (I check this)

  • I read your question and wondered why you don’t ask to terminate all services the application is running when the user clicks "update". (warning the user that the app will end all activities)

2 answers

2

You can even have an app button that downloads an apk, but the user will have to access this apk and request the update manually. Only the operating system can update an application. No app has this level of permission as it would be a serious security breach, especially if your APK requires new permissions.

The Play Store offers all the features needed to make new versions available to users, being smart enough not to conflict with any running service.

If you think your application will behave unexpectedly during an update, you need to reproduce this error and post the code and the exception here.

I recommend not trying to reinvent the wheel and use the Play Store.

  • But for example: in my application the user has open requests, which are in the database, so he could not update until sending these requests to the server, because it will I changed everything the request part in the update, hence his requests will be all wrong, understand?

  • @Pauloroberto If you’re talking about Sqlite, you can easily treat it in the method onUpgrade.

1

You can download the apk and have it installed normally:

Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(Uri.fromFile(file), "application/vnd.android.package-archive");
startActivityForResult(intent, RC_INSTALL);

Or you can create an app that carries a new one. apk and installs with the same code above, should only be tested in case of update (because installation works).

  • download and have install alone with all that android freshness that the user has to interact, I’ve managed, but I’d like for example click update fills a progress bar and ready is updated, dai renicia app and cabou. i want to skip that part of opening with installer package to accept install see what it will use that next install scheme etc.

  • ? wrong link? I found nothing related in any comment on this page.

  • The idea is that your APK has the functions of checking updates, updating, and calling a main Activity from an external Jar (DEX). The upgrade process would involve you only switching the Jar (it does not involve user interaction). You may need this: http://android-developers.blogspot.com.br/2011/07/custom-class-loading-in-dalvik.html

  • I’m sorry, but I couldn’t understand it very well... if you edited your answer to clarify what you gave me would be great :)

  • Functions of your APK: 1. Check for updates; 2.Update; 3.Call your main Activity; All your app code would be in files. jar (including your Main Activity) and not in .apk. When you first install your app, you load these together. external jar (which are in theory your app). The update process would modify these .jar. It became clearer?

  • more or less, because for me it is the apk that is the application but if it turns jar what will change? like I don’t know how to turn my application into a jar, it would be the same to compile and develop?

  • You create an android project and another common Java project (with import for android lib). The java project generates a jar. This jar you will import in your Android project. I put the 'custom class loading' link because maybe you will need it. Unfortunately, I saw this working on a project where I no longer work and I did not have much contact, so I can not pass more detailed information technically.

Show 2 more comments

Browser other questions tagged

You are not signed in. Login or sign up in order to post.