Skip to content

Commit

Permalink
Catched possible exception that can cause a crash
Browse files Browse the repository at this point in the history
Closes #1654
  • Loading branch information
patrickunterwegs committed Dec 8, 2024
1 parent 4c9de45 commit 4d02af0
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions app/src/main/java/at/techbee/jtx/MainActivity2.kt
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import kotlinx.serialization.json.Json
import net.fortuna.ical4j.model.TimeZoneRegistryFactory
import java.io.FileNotFoundException
import java.time.ZonedDateTime
import kotlin.time.Duration.Companion.minutes

Expand Down Expand Up @@ -278,9 +279,14 @@ class MainActivity2 : AppCompatActivity() {
Intent.ACTION_VIEW -> {
if (intent.type == "text/calendar") {
val ics = intent.data ?: return
this.contentResolver.openInputStream(ics)?.use { stream ->
globalStateHolder.icalString2Import.value =
stream.readBytes().decodeToString()
try {
this.contentResolver.openInputStream(ics)?.use { stream ->
globalStateHolder.icalString2Import.value =
stream.readBytes().decodeToString()
}
} catch (e: FileNotFoundException) {
Toast.makeText(applicationContext, e.localizedMessage, Toast.LENGTH_SHORT).show()
//Log.e("MainActivity2", e.stackTraceToString())
}
}
}
Expand Down

0 comments on commit 4d02af0

Please sign in to comment.