catch exceptions thrown at getting file output stream

This commit is contained in:
tibbi 2018-01-28 21:01:54 +01:00
parent 43e2fe622f
commit dc33ffeef5
2 changed files with 8 additions and 2 deletions

View file

@ -6,7 +6,7 @@ buildscript {
propMinSdkVersion = 16 propMinSdkVersion = 16
propTargetSdkVersion = propCompileSdkVersion propTargetSdkVersion = propCompileSdkVersion
propVersionCode = 1 propVersionCode = 1
propVersionName = '3.8.11' propVersionName = '3.8.12'
kotlin_version = '1.2.21' kotlin_version = '1.2.21'
support_libs = '27.0.2' support_libs = '27.0.2'
} }

View file

@ -36,6 +36,7 @@ import com.simplemobiletools.commons.models.SharedTheme
import com.simplemobiletools.commons.views.MyTextView import com.simplemobiletools.commons.views.MyTextView
import kotlinx.android.synthetic.main.dialog_title.view.* import kotlinx.android.synthetic.main.dialog_title.view.*
import java.io.File import java.io.File
import java.io.FileNotFoundException
import java.io.FileOutputStream import java.io.FileOutputStream
import java.io.OutputStream import java.io.OutputStream
import java.util.* import java.util.*
@ -559,7 +560,12 @@ fun BaseSimpleActivity.getFileOutputStream(file: File, callback: (outputStream:
} }
if (document?.exists() == true) { if (document?.exists() == true) {
callback(applicationContext.contentResolver.openOutputStream(document.uri)) try {
callback(applicationContext.contentResolver.openOutputStream(document.uri))
} catch (e: FileNotFoundException) {
showErrorToast(e)
callback(null)
}
} else { } else {
val error = String.format(getString(R.string.could_not_create_file), file.absolutePath) val error = String.format(getString(R.string.could_not_create_file), file.absolutePath)
showErrorToast(error) showErrorToast(error)