Fix editing previously exported notes not working properly

OutputStream for existing files with "content://" path needs to be opened in truncate mode, its description: "If the file already exists and is a regular file and is opened for writing, it will be truncated to length 0."
Streams for files with "/storage" don't seem to be affected by this issue and don't need the truncate mode.

See more at https://developer.android.com/reference/android/os/ParcelFileDescriptor#parseMode(java.lang.String).
This commit is contained in:
Andrii Chubko 2021-08-22 11:03:40 +03:00
parent 3c2195127e
commit de60443c21

View File

@ -875,7 +875,7 @@ class MainActivity : SimpleActivity() {
private fun exportNoteValueToUri(uri: Uri, content: String, callback: ((success: Boolean) -> Unit)? = null) {
try {
val outputStream = contentResolver.openOutputStream(uri)
val outputStream = contentResolver.openOutputStream(uri, "wt")
outputStream!!.bufferedWriter().use { out ->
out.write(content)
}