Skip to content

Commit

Permalink
Merge pull request #120 from santiwanti/fix/android_path
Browse files Browse the repository at this point in the history
fix the path retrieval on Android
  • Loading branch information
santiwanti authored Sep 26, 2024
2 parents c5859a0 + ef9a6e2 commit 6da0c2d
Showing 1 changed file with 11 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,17 @@ public actual data class PlatformFile(
context.getFileName(uri) ?: throw IllegalStateException("Failed to get file name")
}

public actual val path: String? =
uri.path
// On some devices uri.path doesn't seem to work and instead this OpenableColumns.DISPLAY_NAME
// monstrosity has to be used.
public actual val path: String?
get() = context.contentResolver.let {
it.query(uri, null, null, null, null)?.use { cursor ->
val nameIndex = cursor.getColumnIndex(OpenableColumns.DISPLAY_NAME);
cursor.moveToFirst()
val name = cursor.getString(nameIndex)
File(context.filesDir, name).path
}
}

public actual suspend fun readBytes(): ByteArray = withContext(Dispatchers.IO) {
context
Expand Down

0 comments on commit 6da0c2d

Please sign in to comment.