anggrayudi / anggrayudi/SimpleStorage

CreateMode.REPLACE not respected when missing permissions

未关闭
#160 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看
主要语言
Kotlin
星标
867
派生
104
平均合并
22 天 6 小时
30 天内合并 PR
1

描述

This is somewhat related to #159 but expresses itself in a different manner.

Assume you have a function to create some file. However this function tries to create a file that already exists, and was created with scoped storage or manually by the user, even if the app has granted the permissions of that folder. Then CreateMode.REPLACE is not respected. The code below creates a file named "hello (1).txt".

This is a limitation of using the MediaStore API, but I still thing this should be docummented as a pitfall of CreateMode.REPLACE or MediaStoreCompat.

```kotlin
fun testAlreadyCreated(context : Context) {
val file = MediaStoreCompat.createDownload(
context = context,
file = FileDescription(
name = "hello",
"test",
mimeType = "text/plain"
),
mode = CreateMode.REPLACE
)?.toStorageFile(context)

println("file created with the name = ${file?.name}" )
file?.openOutputStream()?.writer()?.use { writer ->
writer.write("Hello World!")
writer.flush()
}
}
```

贡献指南

打开贡献指南

评估

这个 Issue 还没有评估数据。

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。