Skip to content

Commit 841d30e

Browse files
committed
catch exceptions thrown at exporting or importing clipboard items
1 parent b94a69d commit 841d30e

File tree

1 file changed

+18
-2
lines changed

1 file changed

+18
-2
lines changed

app/src/main/kotlin/com/simplemobiletools/keyboard/activities/ManageClipboardItemsActivity.kt

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
package com.simplemobiletools.keyboard.activities
22

33
import android.app.Activity
4+
import android.content.ActivityNotFoundException
45
import android.content.Intent
56
import android.os.Bundle
67
import android.view.Menu
78
import android.view.MenuItem
9+
import android.widget.Toast
810
import com.google.gson.Gson
911
import com.google.gson.reflect.TypeToken
1012
import com.simplemobiletools.commons.dialogs.FilePickerDialog
@@ -109,7 +111,14 @@ class ManageClipboardItemsActivity : SimpleActivity(), RefreshRecyclerViewListen
109111
type = "text/plain"
110112
putExtra(Intent.EXTRA_TITLE, filename)
111113
addCategory(Intent.CATEGORY_OPENABLE)
112-
startActivityForResult(this, PICK_EXPORT_CLIPS_INTENT)
114+
115+
try {
116+
startActivityForResult(this, PICK_EXPORT_CLIPS_INTENT)
117+
} catch (e: ActivityNotFoundException) {
118+
toast(R.string.system_service_disabled, Toast.LENGTH_LONG)
119+
} catch (e: Exception) {
120+
showErrorToast(e)
121+
}
113122
}
114123
}
115124
} else {
@@ -154,7 +163,14 @@ class ManageClipboardItemsActivity : SimpleActivity(), RefreshRecyclerViewListen
154163
Intent(Intent.ACTION_GET_CONTENT).apply {
155164
addCategory(Intent.CATEGORY_OPENABLE)
156165
type = "text/plain"
157-
startActivityForResult(this, PICK_IMPORT_CLIPS_SOURCE_INTENT)
166+
167+
try {
168+
startActivityForResult(this, PICK_IMPORT_CLIPS_SOURCE_INTENT)
169+
} catch (e: ActivityNotFoundException) {
170+
toast(R.string.system_service_disabled, Toast.LENGTH_LONG)
171+
} catch (e: Exception) {
172+
showErrorToast(e)
173+
}
158174
}
159175
} else {
160176
handlePermission(PERMISSION_READ_STORAGE) {

0 commit comments

Comments
 (0)