catch exceptions thrown at exporting or importing clipboard items

This commit is contained in:
tibbi 2022-04-02 17:35:00 +02:00
parent b94a69d1de
commit 841d30eb56
1 changed files with 18 additions and 2 deletions

View File

@ -1,10 +1,12 @@
package com.simplemobiletools.keyboard.activities package com.simplemobiletools.keyboard.activities
import android.app.Activity import android.app.Activity
import android.content.ActivityNotFoundException
import android.content.Intent import android.content.Intent
import android.os.Bundle import android.os.Bundle
import android.view.Menu import android.view.Menu
import android.view.MenuItem import android.view.MenuItem
import android.widget.Toast
import com.google.gson.Gson import com.google.gson.Gson
import com.google.gson.reflect.TypeToken import com.google.gson.reflect.TypeToken
import com.simplemobiletools.commons.dialogs.FilePickerDialog import com.simplemobiletools.commons.dialogs.FilePickerDialog
@ -109,7 +111,14 @@ class ManageClipboardItemsActivity : SimpleActivity(), RefreshRecyclerViewListen
type = "text/plain" type = "text/plain"
putExtra(Intent.EXTRA_TITLE, filename) putExtra(Intent.EXTRA_TITLE, filename)
addCategory(Intent.CATEGORY_OPENABLE) addCategory(Intent.CATEGORY_OPENABLE)
try {
startActivityForResult(this, PICK_EXPORT_CLIPS_INTENT) startActivityForResult(this, PICK_EXPORT_CLIPS_INTENT)
} catch (e: ActivityNotFoundException) {
toast(R.string.system_service_disabled, Toast.LENGTH_LONG)
} catch (e: Exception) {
showErrorToast(e)
}
} }
} }
} else { } else {
@ -154,7 +163,14 @@ class ManageClipboardItemsActivity : SimpleActivity(), RefreshRecyclerViewListen
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"
try {
startActivityForResult(this, PICK_IMPORT_CLIPS_SOURCE_INTENT) startActivityForResult(this, PICK_IMPORT_CLIPS_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) {