0

Basically, my question is somewhat similar to this, and I've used the solution given to that. The problem is, it will only work if the file came from the internal storage, and this is the cause of it:

in this part of the code (in the solution in the question I mentioned):

        if (isExternalStorageDocument(uri)) {
            final String docId = DocumentsContract.getDocumentId(uri);
            final String[] split = docId.split(":");
            final String type = split[0];

            if ("primary".equalsIgnoreCase(type)) {
                return Environment.getExternalStorageDirectory() + "/" + split[1];
            }
            // TODO handle non-primary volumes
        }

there is no following else statement. I've searched for ways to access that non-primary volumes but I can't find any answer.

Community
  • 1
  • 1
hehe
  • 1,294
  • 13
  • 26

1 Answers1

0

The code supplied in that question and answer are awful. There is no requirement for the Uri to point to a file, let alone a file that you can access, let alone a file whose path you can derive from the Uri itself. A Uri with a content scheme is an opaque handle, nothing more.

Use ContentResolver and openInputStream() (or openOutputStream()) to get a stream on the content identified by the Uri.

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
  • yes, I think I've read your comment somewhere about this. But I'll try that openInputStream that you mentioned then I'll give an update. – hehe Feb 07 '17 at 15:32