0

This is how i install a apk file:

Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(uri, "application/vnd.android.package-archive");
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);

Now i want to install a apk file from sdcard, i'm getting the uri through Storage Access Framework (From Kitkat), but code does not working.

Uri uri1 = Uri.fromFile(file); //file class File
Uri uri2 = df.getUri(); //df class DocumentFile

The code with uri1 works, but not with uri2

Any workaround? Thanks

cgr
  • 519
  • 1
  • 7
  • 20
  • 1
    The last time I checked, the package installer will only accept `file://` `Uri` values. Since there is no requirement that the `Uri` you get from the Storage Access Framework actually be a file, you would need to copy the data to your own file (`getContentResolver().openInputStream()` plus Java I/O). That file would need to be on external storage, so both you and the package installer can access it. Then, use a `Uri` pointing to that file. With luck, they improved the package installer in 6.0 to support other schemes, but I doubt it. – CommonsWare Oct 08 '15 at 11:49
  • @CommonsWare i'll do that. Thanks a lot. – cgr Oct 09 '15 at 08:36

0 Answers0