Skip to content

Commit 266ef2e

Browse files
committed
catch and show exceptions thrown at file related intents
1 parent 61a550c commit 266ef2e

File tree

1 file changed

+13
-3
lines changed
  • app/src/main/kotlin/com/simplemobiletools/notes/pro/activities

1 file changed

+13
-3
lines changed

app/src/main/kotlin/com/simplemobiletools/notes/pro/activities/MainActivity.kt

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package com.simplemobiletools.notes.pro.activities
22

33
import android.annotation.SuppressLint
44
import android.app.Activity
5+
import android.content.ActivityNotFoundException
56
import android.content.Context
67
import android.content.Intent
78
import android.content.pm.ShortcutInfo
@@ -41,9 +42,9 @@ import com.simplemobiletools.notes.pro.extensions.*
4142
import com.simplemobiletools.notes.pro.fragments.TextFragment
4243
import com.simplemobiletools.notes.pro.helpers.*
4344
import com.simplemobiletools.notes.pro.models.Note
45+
import kotlinx.android.synthetic.main.activity_main.*
4446
import java.io.File
4547
import java.nio.charset.Charset
46-
import kotlinx.android.synthetic.main.activity_main.*
4748
import java.util.*
4849
import kotlin.collections.ArrayList
4950

@@ -623,7 +624,12 @@ class MainActivity : SimpleActivity() {
623624
Intent(Intent.ACTION_OPEN_DOCUMENT).apply {
624625
addCategory(Intent.CATEGORY_OPENABLE)
625626
type = "text/*"
626-
startActivityForResult(this, PICK_OPEN_FILE_INTENT)
627+
628+
try {
629+
startActivityForResult(this, PICK_OPEN_FILE_INTENT)
630+
} catch (e: ActivityNotFoundException) {
631+
toast(R.string.no_app_found)
632+
}
627633
}
628634
}
629635
}
@@ -814,7 +820,11 @@ class MainActivity : SimpleActivity() {
814820
putExtra(Intent.EXTRA_TITLE, "${mCurrentNote.title.removeSuffix(".txt")}.txt")
815821
addCategory(Intent.CATEGORY_OPENABLE)
816822

817-
startActivityForResult(this, PICK_EXPORT_FILE_INTENT)
823+
try {
824+
startActivityForResult(this, PICK_EXPORT_FILE_INTENT)
825+
} catch (e: ActivityNotFoundException) {
826+
toast(R.string.no_app_found)
827+
}
818828
}
819829
}
820830
}

0 commit comments

Comments
 (0)