0

since my app will not be published in any store i would like to implement more of an own way to update my apk. Esp. for android app.

i dont mind about windows/iOs!

Goal should be

  1. Download the new .apk
  2. Start intent with the installation routine
  3. exit my app
  4. violá, new version installed :D

Is this a possibly solution or do any of you guys have a better more efficient/better way to handle this problem? Glad to hear some solutions! :)

Additional info: Any kind of store/application which needs the user to be logged in or have an account is , at least at the moment, not an option

Cruik
  • 190
  • 1
  • 12

1 Answers1

1

In your request, for the first step(Download the new .apk), you can put the apk file on the server and download it by the web request.

And for the second step, you can refer to my old answer about how to install the apk in your app. According to that, you can use the code to intall the new .apk file in your app.

Note: Please don't forget to add the following code to request the permission about installing app.

    <uses-permission android:name="android.permission.REQUEST_INSTALL_PACKAGES" />
    <uses-permission android:name="android.permission.INSTALL_PACKAGES" />

And this kind of permission is dangerous permission. You also need to request permission at the run-time.

For the step 3 and step 4, because you install the apk's new version not another app. The app will auto exit when the new version installed.

Actually, every step has many example codes on the internet. What you need to do is combining them with each other.

Liyun Zhang - MSFT
  • 8,271
  • 1
  • 2
  • 14
  • When i am doing it like you described in your answer and your link. i am getting the following exception: java.lang.IllegalArgumentException: Failed to find configured root that contains /data/data/ab.dev.lobi/cache/ab.dev.lobi.apk – Cruik Mar 29 '23 at 21:53
  • Where did you put the apk file? You can refer to this case about [FileProvider - IllegalArgumentException: Failed to find configured root](https://stackoverflow.com/questions/42516126/fileprovider-illegalargumentexception-failed-to-find-configured-root). @Cruik – Liyun Zhang - MSFT Mar 30 '23 at 02:07
  • yeah , after some research i found this SO Question. i solved my that Problem, but i saw that the Intent.ACTION_INSTALL_PACKAGE is deprecated. The dialog to update my app pops up, but after i clicked Install, the dialog shows that the installation failed. without any further explanation – Cruik Mar 30 '23 at 09:58
  • The code I provided can only install the signed apk file. So you try to install your apk file with other file such as the system file manager to check if the cause is your apk file not the code. @Cruik – Liyun Zhang - MSFT Mar 31 '23 at 06:41
  • the apk is 100& signed, i used the same to install the app in first place – Cruik Apr 01 '23 at 09:12
  • When you download the apk file, did you try to install it by the system file manager? @Cruik – Liyun Zhang - MSFT Apr 03 '23 at 09:07
  • what do you exactly mean? the downloaded apk canbe installed when i go to the file explorer and install it from there. if i use your code the dialog pops up and returns installation failed – Cruik Apr 04 '23 at 11:21
  • Did you test it on the emulator or physical device? – Liyun Zhang - MSFT Apr 05 '23 at 09:01
  • on both, API Level 29 – Cruik Apr 06 '23 at 10:06
  • Sorry for my careless, the Intent.ACTION_INSTALL_PACKAGE is deprecated. And according to [this answer which has the similar issue you need to use another api](https://stackoverflow.com/a/58089355/17455524). And I will convert it to C# xamarin tomorrow. @Cruik – Liyun Zhang - MSFT Apr 06 '23 at 10:15
  • 1
    Hello, there is an [existed case about the new api](https://stackoverflow.com/questions/59685804/android-packageinstaller-not-installing-apk), and you can also refer to [this answer](https://stackoverflow.com/a/69774124/1399272). @Cruik – Liyun Zhang - MSFT Apr 07 '23 at 08:54