anggrayudi / anggrayudi/SimpleStorage

CreateMode.REPLACE not respected when missing permissions

Offen
#160 0 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen
Vorherrschende Sprache
Kotlin
Sterne
867
Forks
104
Ø Merge
22 T. 6 Std.
Gemergte PRs (30 T.)
1

Beschreibung

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()
}
}
```

Beitragsleitfaden

Beitragsleitfaden öffnen

Bewertung

Dieses Issue wurde noch nicht bewertet.

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.