Good evening, the question arose how to make your ready-made android application installed on the user's machine can be updated if I added to the interface or eliminated a bug, etc., how to write it in the code?
- I did not understand what you asked) Even I wonder what exactly you mean - Roman Novoselov
- 2@RomanNovoselov, most likely the author means updating his own application, without the participation of the play market. There are applications that update themselves - Mr. Black
1 answer
Standard means and without root - in any way.
Usually this happens as follows: you post a new version of the application to the market, the user's device through the market is scheduled (by the market, that is, without your participation) checks all installed applications for updates and, if the user has the appropriate settings in the market, the market will install the update itself
According to en-SO , if you programmatically download a new apk, whose version is greater than the current version and the same package and certificate, then you can run the system Intent to update the application like this:
Intent intent = new Intent(Intent.ACTION_VIEW); Uri uri = Uri.fromFile(new File(pathToApk)); intent.setDataAndType(uri, "application/vnd.android.package-archive"); startActivity(intent); Next, the user will, in theory, confirm the installation of the update.
If the device is rutovan, then you can launch the installation of apk through the system without the participation of the user:
public static void installNewApk() { try { Runtime.getRuntime().exec(new String[] {"su", "-c", "pm install -r /mnt/internal/Download/fp.apk"}); } catch (IOException e) { System.out.println(e.toString()); System.out.println("no root"); } } You can implement the logic of launching this intent / command like this:
- When you first start the application, write to the internal resources (sharedPrefereneces) version number.
- Check the periodicity with whether you have a new version somewhere on the server.
- If yes, download apk and at the end launch the intent / command.
- I need to do without the market, but how does the update itself take the old is removed and the new one is installed and if so you can check by the version number of the application, say it was 1 became 2 you need to download and install it is clear that the program itself should check and check it and not the user? - Varg Sieg
- @VargSieg, supplemented the answer, although I am still not sure that I understood your task. - YurySPb ♦
- Everything is great what you need) - Varg Sieg
- I understand that when a new version was released, apk was downloaded from the "server", with the user's permission, and installed. - Vladimir VSeos
- one@YuriSPb understood sorry for the trouble. - Varg Sieg