Skip to content

Commit f0c4a0a

Browse files
committed
catch file related exceptions
1 parent fc837af commit f0c4a0a

File tree

1 file changed

+16
-2
lines changed
  • app/src/main/kotlin/com/simplemobiletools/contacts/pro/activities

1 file changed

+16
-2
lines changed

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

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import android.os.Bundle
1515
import android.os.Handler
1616
import android.view.Menu
1717
import android.view.MenuItem
18+
import android.widget.Toast
1819
import androidx.appcompat.widget.SearchView
1920
import androidx.core.view.MenuItemCompat
2021
import androidx.viewpager.widget.ViewPager
@@ -440,7 +441,14 @@ class MainActivity : SimpleActivity(), RefreshContactsListener {
440441
Intent(Intent.ACTION_GET_CONTENT).apply {
441442
addCategory(Intent.CATEGORY_OPENABLE)
442443
type = "text/x-vcard"
443-
startActivityForResult(this, PICK_IMPORT_SOURCE_INTENT)
444+
445+
try {
446+
startActivityForResult(this, PICK_IMPORT_SOURCE_INTENT)
447+
} catch (e: ActivityNotFoundException) {
448+
toast(R.string.system_service_disabled, Toast.LENGTH_LONG)
449+
} catch (e: Exception) {
450+
showErrorToast(e)
451+
}
444452
}
445453
} else {
446454
handlePermission(PERMISSION_READ_STORAGE) {
@@ -500,7 +508,13 @@ class MainActivity : SimpleActivity(), RefreshContactsListener {
500508
putExtra(Intent.EXTRA_TITLE, file.name)
501509
addCategory(Intent.CATEGORY_OPENABLE)
502510

503-
startActivityForResult(this, PICK_EXPORT_FILE_INTENT)
511+
try {
512+
startActivityForResult(this, PICK_EXPORT_FILE_INTENT)
513+
} catch (e: ActivityNotFoundException) {
514+
toast(R.string.system_service_disabled, Toast.LENGTH_LONG)
515+
} catch (e: Exception) {
516+
showErrorToast(e)
517+
}
504518
}
505519
}
506520
} else {

0 commit comments

Comments
 (0)