FileProvider and secondary external storage

后端 未结 5 1939
慢半拍i
慢半拍i 2021-01-02 19:17

How can I serve files from the SECONDARY external storage using the FileProvider?

The current implementation of the FileProvider handles on

5条回答
  •  失恋的感觉
    2021-01-02 19:42

    So I ended up doing the following:

    Try to create to Uri via FileProvider, If it fails due to:

    java.lang.IllegalArgumentException: Failed to find configured root that contains
    

    I'm just creating a regular Uri.

    Here's my code:

    try {
            uri = FileProvider.getUriForFile(context,
                    MY_AUTHORITY_STRING,
                    imageFile);
        } catch (Exception e) {
            CLog.d(TAG, e);
            uri = Uri.fromFile(imageFile);
        }
    

    I don't know why, but it's working, the FileProvider can't access the file (As it's in secondary external storage) and then the uri is created successfully in the catch clause.

    Weird Google...very weird.

提交回复
热议问题