catch file related exceptions

This commit is contained in:
tibbi 2022-04-10 23:11:21 +02:00
parent fc837af84f
commit f0c4a0ac0f

View File

@ -15,6 +15,7 @@ import android.os.Bundle
import android.os.Handler import android.os.Handler
import android.view.Menu import android.view.Menu
import android.view.MenuItem import android.view.MenuItem
import android.widget.Toast
import androidx.appcompat.widget.SearchView import androidx.appcompat.widget.SearchView
import androidx.core.view.MenuItemCompat import androidx.core.view.MenuItemCompat
import androidx.viewpager.widget.ViewPager import androidx.viewpager.widget.ViewPager
@ -440,7 +441,14 @@ class MainActivity : SimpleActivity(), RefreshContactsListener {
Intent(Intent.ACTION_GET_CONTENT).apply { Intent(Intent.ACTION_GET_CONTENT).apply {
addCategory(Intent.CATEGORY_OPENABLE) addCategory(Intent.CATEGORY_OPENABLE)
type = "text/x-vcard" type = "text/x-vcard"
startActivityForResult(this, PICK_IMPORT_SOURCE_INTENT)
try {
startActivityForResult(this, PICK_IMPORT_SOURCE_INTENT)
} catch (e: ActivityNotFoundException) {
toast(R.string.system_service_disabled, Toast.LENGTH_LONG)
} catch (e: Exception) {
showErrorToast(e)
}
} }
} else { } else {
handlePermission(PERMISSION_READ_STORAGE) { handlePermission(PERMISSION_READ_STORAGE) {
@ -500,7 +508,13 @@ class MainActivity : SimpleActivity(), RefreshContactsListener {
putExtra(Intent.EXTRA_TITLE, file.name) putExtra(Intent.EXTRA_TITLE, file.name)
addCategory(Intent.CATEGORY_OPENABLE) addCategory(Intent.CATEGORY_OPENABLE)
startActivityForResult(this, PICK_EXPORT_FILE_INTENT) try {
startActivityForResult(this, PICK_EXPORT_FILE_INTENT)
} catch (e: ActivityNotFoundException) {
toast(R.string.system_service_disabled, Toast.LENGTH_LONG)
} catch (e: Exception) {
showErrorToast(e)
}
} }
} }
} else { } else {