This follows on from a previous post, but is a slightly different questions, hence a new post.
I am trying to open a file on an Android Tablet SD card. From this documentation, I am using the Intent(Intent.ACTION_OPEN_DOCUMENT_TREE)
to browse to a folder.
However, when I selected the folder, the uri comes backing looking like
content://com.android.externalstorage.documents/tree/3BDD-1A1D%3AMusic%2Fmidi`.
Using URLDecoder.decode
this resolves to
content://com.android.externalstorage.documents/tree/3BDD-1A1D:Music/midi`.
Even if I select the internal
storage I get something like
content://com.android.externalstorage.documents/tree/primary:Music/midi`.
And if I use either of these paths, then appending a filename (which I know exists) to the end, I always get open failed: ENOENT (No such file or directory)
, no matter what I have tried with the path prefix.
My question is, how can I get a "proper formed" file path from this URI?
Update 1
I do actually want to search for files in this directory (I won't know what's there in advance in the actually working app) - trying to open a test files is just in my testing.
But even using this did not help:
val tree = DocumentFile.fromTreeUri(this, uri)!!
val path = tree.name
File(path ).walk().forEach {
val f = it
println(it)
}