When you install the application in this way, you are not actually installing the application directly. It happens that you run the installer and pass the installer a link to the APK that you want to install. The installer is not part of your application code and does not have access to memory during your application.
The only way to do this, if you have an byte array containing the APK, is to write the byte array to a file, and then run the installer and pass it a URI that points to the file you wrote. After the installation is complete, you can delete the file (to do not leave random trash on the user phone).
source share