Fixed crash in older Android versions if restore file does not exist

Correctly show backup file name also in older Android versions
This commit is contained in:
Juha Heinanen
2022-03-25 11:16:58 +02:00
parent 7a3291fc40
commit 1dfe0591ef

View File

@ -574,7 +574,10 @@ object Utils {
name = cursor.getString(index)
cursor.close()
}
return name
return if (name == "")
"$uri".substringAfterLast("/")
else
name
}
fun saveBitmap(bitmap: Bitmap, file: File): Boolean {
@ -690,7 +693,13 @@ object Utils {
fun decryptFromUri(ctx: Context, uri: Uri, password: String): ByteArray? {
var plainData: ByteArray? = null
var stream = ctx.contentResolver.openInputStream(uri) as FileInputStream
var stream: FileInputStream
try {
stream = ctx.contentResolver.openInputStream(uri) as FileInputStream
} catch(e: Exception) {
Log.w(TAG, "decryptFromUri could not open stream: $e")
return null
}
try {
ObjectInputStream(stream).use {
val content = it.readObject() as ByteArray