Is it possible to programmatically install an Android application from a byte array?

I know that I can install the Android application programmatically using the code below, which passes the APK URI . Can I install the application without transferring the URI of the APK file? For example, getting a byte array of an APK file and installing it?

File appFile = new File("application.apk"); Intent installIntent = new Intent(Intent.ACTION_VIEW); installIntent.setDataAndType(Uri.fromFile(appFile),"application/vnd.android.package-archive"); startActivity(installIntent); 
+4
source share
1 answer

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).

+2
source

Source: https://habr.com/ru/post/1442304/


All Articles