假设一个 Uri 可以是以下之一:
- 来自存储访问框架的 DocumentFile 的 Uri(即 DocumentFile.getUri())。
- 来自常规文件的 Uri(即 Uri.fromFile(File))
它在这两种情况下都指目录下的文件。
有没有一种直接的方法来获取其父目录的 Uri 而无需尝试两者中的每一个来查看哪个有效?
[编辑]:这是 SAF 的示例:
乌里:
content://com.android.externalstorage.documents/tree/0000-0000%3Atest/document/0000-0000%3Atest%2Ffoo%2FMovies%2FRR%20parking%20lot%20a%202018_02_22_075101.mp4
获取路径():
/tree/0000-0000:test/document/0000-0000:test/foo/Movies/RR 停车场 a 2018_02_22_075101.mp4
获取路径段():
0 = "tree"
1 = "0000-0000:test"
2 = "document"
3 = "0000-0000:test/foo/Movies/RR parking lot a 2018_02_22_075101.mp4"
父文件夹应该是 test/foo/Movies。
以下是常规文件的示例:
乌里:
file:///storage/emulated/0/foo/Movies/RR%20parking%20lot%20a%202018_02_22_081351.mp4
获取路径():
/storage/emulated/0/foo/Movies/RR 停车场 a 2018_02_22_081351.mp4
获取路径段():
0 = "storage"
1 = "emulated"
2 = "0"
3 = "foo"
4 = "Movies"
5 = "RR parking lot a 2018_02_22_081351.mp4"