iPaulPro / aFileChooser

[DEPRECATED] Android library that provides a file explorer to let users select files on external storage.
Apache License 2.0
1.79k stars 850 forks source link

Fix for external SDCard on Android M #79

Closed jahertor closed 8 years ago

jahertor commented 8 years ago

Starting from Android M, the external SD Card used as portable storage shows the SDCard ID as DocumentsContract first parameter.

So docId has the following format: XXXX-XXXX:path/to/the/file And the real path would be: /storage/XXXX-XXXX/path/to/the/file

if (type.matches("[A-F0-9]{4}-[A-F0-9]{4}")) {
     return "/storage/".concat(type).concat("/").concat(split[1]);
}

Tested on Moto X Play 6.0. Someone can confirm that it's the same for other devices? I don't like at all handwrite the "storage" path, and maybe the type is not always an SDCard ID.

We should discuss this before merge.

jahertor commented 8 years ago

I just see https://github.com/iPaulPro/aFileChooser/pull/78 that fix the problem. It loops the mounted volumes using reflection of android.os.storage.StorageVolume and return the path for the first occurence.