androidcommonsware-cwacandroid-fileproviderandroid-7.0-nougat

Does Android's FileProvider actually support external-files-path?


I've run into the FileUriExposedException stuff where you try to send a file:/// Uri to another app (in this case the camera), and I should be using a FileProvider instead (causes a crash on api 24 Nougat).

In our app, we generate a File using Context's getExternalFilesDir(String) method:

context.getExternalFilesDir("attachments");

The FileProvider documentation leads me to believe I should be using external-files-path in my paths.xml if I want the functionality to be the same as is now.

<?xml version="1.0" encoding="utf-8"?>
<paths>
    <external-files-path
        name="attachments"
        path="attachments/" />
</paths>

But after googling some more, I found a few things that make me think there's issues with FileProvider, or at least FileProvider's documentation...

So

  1. Am I right in thinking I should use external-files-path if I want to match how my app currently works?
  2. Is the documentation/FileProvider really broken/incorrect and I should use something like cwac-provider instead?

UPDATE

For completeness, as @CommonsWare recommended below, using the 24.2.0 version of support-v4 is working for me.


Solution

  • Am I right in thinking I should use external-files-path if I want to match how my app currently works?

    Yes. Though do note that getExternalFilesDir() does not officially support "attachments" as a parameter, so do not be surprised if your app breaks someday.

    Is the documentation/FileProvider really broken/incorrect

    Well, I see the code for external-files-path support in the sources JAR for 24.2.0 of the new support-core-utils artifact. support-v4, as of 24.2.0, has been subdivided into a series of separate artifacts, and FileProvider lives in support-core-utils.

    So, try using 24.2.0 of support-v4 (or support-core-utils if you do not need all of support-v4).