Skip to content

Commit

Permalink
Return the full uri as name to allow parse
Browse files Browse the repository at this point in the history
Since the folder isn't static, like with File, using just the name won't trace back to the physical item.
  • Loading branch information
AbandonedCart committed May 7, 2024
1 parent bd39ebb commit 6c1076b
Showing 1 changed file with 3 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,7 @@ object TagArray {
@Throws(IOException::class)
fun writeBytesToDocument(
context: Context, directory: DocumentFile, name: String, tagData: ByteArray?
): String? {
): Uri? {
// displayName – name of new document, without any file extension appended; the underlying provider may choose to append the extension
// The underlying provider does NOT provide an extension, therefore one IS appended
val newFile = directory.createFile(
Expand All @@ -400,7 +400,7 @@ object TagArray {
newFile?.let { file ->
context.contentResolver.openOutputStream(file.uri).use { it?.write(tagData) }
}
return newFile?.name
return newFile?.uri
}

fun writeBytesWithName(context: Context, fileName: String?, directory: String, tagData: ByteArray?) : String? {
Expand All @@ -410,7 +410,7 @@ object TagArray {
val rootDocument = browserRootDocument()?.let { uri ->
DocumentFile.fromTreeUri(context, Uri.parse(uri))
} ?: throw NullPointerException()
writeBytesToDocument(context, rootDocument, name, tagData)
writeBytesToDocument(context, rootDocument, name, tagData)?.toString()
} else {
val destination = Storage.getDownloadDir("TagMo", directory)
destination.mkdirs()
Expand Down

0 comments on commit 6c1076b

Please sign in to comment.