5

Uri が次のいずれかであるとします。

  • Storage Access Framework の DocumentFile からの Uri (つまり、DocumentFile.getUri())。
  • 通常のファイルからの Uri (つまり、Uri.fromFile(File))

どちらの状況でも、ディレクトリの下のファイルを参照します。

2つのそれぞれを試してどちらが機能するかを確認せずに、親ディレクトリの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

getPath():

/tree/0000-0000:test/document/0000-0000:test/foo/Movies/RR駐車場a 2018_02_22_075101.mp4

getPathSegments():

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

getPath():

/storage/emulated/0/foo/Movies/RR駐車場a 2018_02_22_081351.mp4

getPathSegments():

0 = "storage"
1 = "emulated"
2 = "0"
3 = "foo"
4 = "Movies"
5 = "RR parking lot a 2018_02_22_081351.mp4"
4

1 に答える 1