Skip to content

Commit

Permalink
music: fix file document path extraction
Browse files Browse the repository at this point in the history
Apparently on Android 14 you need to reassemble the document URI and
then extract it's ID to get a path object. Really not sure why.
  • Loading branch information
OxygenCobalt committed Jan 1, 2024
1 parent bf9667f commit 68584ba
Showing 1 changed file with 9 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,15 @@ interface DocumentPathFactory {

class DocumentPathFactoryImpl @Inject constructor(private val volumeManager: VolumeManager) :
DocumentPathFactory {
override fun unpackDocumentUri(uri: Uri) = fromDocumentId(DocumentsContract.getDocumentId(uri))
override fun unpackDocumentUri(uri: Uri): Path? {
// Abuse the document contract and extract the encoded path from the URI.
// I've seen some implementations that just use getDocumentId. That no longer seems
// to work on Android 14 onwards. But spoofing our own document URI and then decoding
// it does for some reason.
val docUri = DocumentsContract.buildDocumentUri(uri.authority, uri.pathSegments[1])
val docId = DocumentsContract.getDocumentId(docUri)
return fromDocumentId(docId)
}

override fun unpackDocumentTreeUri(uri: Uri): Path? {
// Convert the document tree URI into it's relative path form, which can then be
Expand Down

0 comments on commit 68584ba

Please sign in to comment.