catching some exceptions related to startActivityForResult

This commit is contained in:
tibbi 2022-04-08 22:21:00 +02:00
parent 3f69bed95d
commit 0b1b32ca5d
3 changed files with 27 additions and 4 deletions

View File

@ -70,7 +70,7 @@ android {
} }
dependencies { dependencies {
implementation 'com.github.SimpleMobileTools:Simple-Commons:b0bdd457be' implementation 'com.github.SimpleMobileTools:Simple-Commons:d46a47635d'
implementation 'androidx.multidex:multidex:2.0.1' implementation 'androidx.multidex:multidex:2.0.1'
implementation 'androidx.constraintlayout:constraintlayout:2.1.3' implementation 'androidx.constraintlayout:constraintlayout:2.1.3'
implementation 'androidx.swiperefreshlayout:swiperefreshlayout:1.1.0' implementation 'androidx.swiperefreshlayout:swiperefreshlayout:1.1.0'

View File

@ -3,6 +3,7 @@ package com.simplemobiletools.calendar.pro.activities
import android.annotation.SuppressLint import android.annotation.SuppressLint
import android.app.Activity import android.app.Activity
import android.app.SearchManager import android.app.SearchManager
import android.content.ActivityNotFoundException
import android.content.Context import android.content.Context
import android.content.Intent import android.content.Intent
import android.content.pm.ShortcutInfo import android.content.pm.ShortcutInfo
@ -1056,7 +1057,14 @@ class MainActivity : SimpleActivity(), RefreshRecyclerViewListener {
Intent(Intent.ACTION_GET_CONTENT).apply { Intent(Intent.ACTION_GET_CONTENT).apply {
addCategory(Intent.CATEGORY_OPENABLE) addCategory(Intent.CATEGORY_OPENABLE)
type = "text/calendar" type = "text/calendar"
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) {
@ -1118,7 +1126,13 @@ class MainActivity : SimpleActivity(), RefreshRecyclerViewListener {
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 {

View File

@ -2,11 +2,13 @@ package com.simplemobiletools.calendar.pro.activities
import android.app.Activity import android.app.Activity
import android.app.TimePickerDialog import android.app.TimePickerDialog
import android.content.ActivityNotFoundException
import android.content.Intent import android.content.Intent
import android.media.AudioManager import android.media.AudioManager
import android.media.RingtoneManager import android.media.RingtoneManager
import android.os.Bundle import android.os.Bundle
import android.view.Menu import android.view.Menu
import android.widget.Toast
import com.simplemobiletools.calendar.pro.R import com.simplemobiletools.calendar.pro.R
import com.simplemobiletools.calendar.pro.dialogs.SelectCalendarsDialog import com.simplemobiletools.calendar.pro.dialogs.SelectCalendarsDialog
import com.simplemobiletools.calendar.pro.dialogs.SelectEventTypeDialog import com.simplemobiletools.calendar.pro.dialogs.SelectEventTypeDialog
@ -893,7 +895,14 @@ class SettingsActivity : SimpleActivity() {
Intent(Intent.ACTION_GET_CONTENT).apply { Intent(Intent.ACTION_GET_CONTENT).apply {
addCategory(Intent.CATEGORY_OPENABLE) addCategory(Intent.CATEGORY_OPENABLE)
type = "text/plain" type = "text/plain"
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) {