Search code examples
androidapktermux

Install apk on Termux and wait for it to finish OR check whether apk is installed


In Termux I am installing several apk's using

xdg-open myapp.apk

and I want to make sure it actually happens, ie that the resulting install window doesn't disappear and ideally that the user was successful (chose to install it). Instead, my script immediately continues, leaving the installation to go on in the background and maybe not happen.

I would like to ask the OS whether the app is installed, or have it complete the installation before continuing.


Solution

  • How to check if APK is installed: if device is rooted - tsudo pm list packages | grep my.package.id How to install APK - if device is rooted: tsudo pm install mypackage.apk (you will need to install tsudo beforehand).

    For non-rooted devices it is seemingly impossible to know if certain app is installed - most likely for security reasons.

    Installing on non-rooted devices works with xdg-open, but only after you permit installing from untrusted sources in Android preferences for Termux app. And Termux should be active for it to work. (Termux-floating window or SSH won't work, unless main Termux window is active.)