No puedo acceder al almacenamiento cuando compilo para targetSdkVersion v29.
Aquí está mi configuración de gradle:
compileSdkVersion 29
buildToolsVersion "29.0.2"
...
minSdkVersion 15
targetSdkVersion 29
TEN WRITE_EXTERNAL_STORAGEEN CUENTA que se otorga el permiso y la misma configuración funciona bien cuando se construye para targetSdkVersion 28.
Aquí está mi implementación:
val outputFolder = File(baseFolder + File.separator + "Output Folder")
if (!outputFolder.exists()) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
Files.createDirectory(outputFolder.toPath()) //This allways returns false with targetSdkVersion 29
} else {
if (!outputFolder.mkdirs()) {
Log.e("SaveRaw", "Unable to create folder for audio recording")
}
}
}
outputFile = File("$baseFolder/Output Folder/$filename")
try {
fileOutputStream = FileOutputStream(outputFile)
} catch (e: FileNotFoundException) {
e.printStackTrace() // allways throwing exception here, even if Output Folder exists
}
y aquí está la excepción:
W/System.err: java.io.FileNotFoundException: /storage/emulated/0/Chirp Auto Tester/2019_10_17 10:44:43.raw: open failed: EACCES (Permission denied)
W/System.err: at libcore.io.IoBridge.open(IoBridge.java:496)
at java.io.FileOutputStream.<init>(FileOutputStream.java:235)
at java.io.FileOutputStream.<init>(FileOutputStream.java:186)
Espero que alguien tenga una respuesta, ¿qué me estoy perdiendo aquí?
Actualizar:
Aquí es de donde baseFolderviene. Tenga en cuenta que getExternalStorageDirectoryes un método obsoleto.
val baseFolder: String = if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) {
Environment.getExternalStorageDirectory().absolutePath
} else {
context.filesDir.absolutePath
}
Gracias
targetSdkVersion 28. ¡Esto no es un problema de permiso!
targetSdkVersion 28entonces? Según el error, sí, es un problema relacionado con los permisos, pero no porque no se otorguen los permisos.