5

When using build tools version 24 and Android device with N image (npd56n) I'm unable to install package using PackageManager#installPackage.

When URI with the file: scheme is passed to the method, -3 is returned, I assume it is the INSTALL_FAILED_INVALID_URI.

When the URI created with a FileProvider (content: scheme) is passed to the method, exception is thrown:

Caused by: java.lang.UnsupportedOperationException: Only file:// URIs are supported                                                                    

Any ideas?

mrtowel
  • 278
  • 2
  • 11
  • 1
    The `FileProvider` approach worked for me starting with NDP4 using `ACTION_INSTALL_PACKAGE`. See [this issue](https://code.google.com/p/android/issues/detail?id=205827) for more. – CommonsWare Jul 12 '16 at 14:38
  • 1
    @CommonsWare, the Android N [PackageManager source](https://github.com/android/platform_frameworks_base/blob/nougat-dev/core/java/android/app/ApplicationPackageManager.java) still seems to still explicitly prohibit non `file://` URIs. The `FileProvider` supplies `content://` URIs. Perhaps you referring to installation via `Intent` rather than via (reflective) call to `PackageManager.installPackage`? –  Sep 27 '16 at 19:05
  • @manyobject: Oh, I had assumed that `installPackage()` was just a convenience wrapper around invoking the installer activity. Yes, I was testing with `ACTION_INSTALL_PACKAGE`. – CommonsWare Sep 27 '16 at 19:07
  • 2
    @mrtowel, I strongly suspect that in your case the -3 return value is because the PackageManager does not have permissions to read the file you are attempting to install. [Changes in Android N](https://developer.android.com/about/versions/nougat/android-7.0-changes.html) mean that the file permissions are much stricter, specifically `File#setReadable(true, false)` is no longer sufficient to make a file in app private storage readable to other apps and `MODE_WORLD_READABLE` will throw an Exception. –  Sep 27 '16 at 21:01

1 Answers1

0

installPackage in PackageManager was deprecated on N