I’m trying to install an apk file present in internal/external storage.
This is my code:
final String fileuri = "file://" + absolutePath;
Log.v("FILE_BROWSER", "File to be installed: " + Uri.parse(fileuri).getPath());
final Intent promptInstall = new Intent(Intent.ACTION_VIEW);
promptInstall.setDataAndType(Uri.parse(fileuri), "application/vnd.android.package-archive");
promptInstall.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(promptInstall);
The apk file is sucessfully installed if the file is present on external storage. Eg. /mnt/sdcard/MyApp.apk
But if the apk file is present on internal storage (Eg. /data/data/com.myapp/files/MyApp.apk) then the installation fails. Error message is: Parse Error: There is a problem parsing the package
One solution can be copying the file to SDCARD and then installing it. But, in the scenario where SDCARD is unavailable, this trick will not work.
Any help on this guys? How can I install an apk present on internal storage directory if SDCARD is unavailable?
For this your .apk file has to
Context.MODE_WORLD_READABLEpermission.I am doing this to write .apk file in my application’s Internal Storage
And then to install it,
Here path is
path = getFilesDir().getAbsolutePath();And this works fine in my case..