From ef55a8450f8902204da8a0a2f20cdcc6dcb0313e Mon Sep 17 00:00:00 2001 From: SpiritCroc Date: Sun, 17 Jul 2022 19:03:54 +0200 Subject: [PATCH] Fix crash on no camera app found Change-Id: I09888ed8192fae484a8c19f92cedfcca0e6498a9 --- .../app/features/attachments/AttachmentsHelper.kt | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/vector/src/main/java/im/vector/app/features/attachments/AttachmentsHelper.kt b/vector/src/main/java/im/vector/app/features/attachments/AttachmentsHelper.kt index d0843b3b64..196b0b9d16 100644 --- a/vector/src/main/java/im/vector/app/features/attachments/AttachmentsHelper.kt +++ b/vector/src/main/java/im/vector/app/features/attachments/AttachmentsHelper.kt @@ -16,11 +16,14 @@ package im.vector.app.features.attachments import android.app.Activity +import android.content.ActivityNotFoundException import android.content.Context import android.content.Intent import android.net.Uri import android.os.Bundle +import android.widget.Toast import androidx.activity.result.ActivityResultLauncher +import im.vector.app.R import im.vector.app.core.dialogs.PhotoOrVideoDialog import im.vector.app.core.platform.Restorable import im.vector.app.features.settings.VectorPreferences @@ -103,11 +106,19 @@ class AttachmentsHelper(val context: Context, val callback: Callback) : Restorab ) { PhotoOrVideoDialog(activity, vectorPreferences).show(object : PhotoOrVideoDialog.PhotoOrVideoDialogListener { override fun takePhoto() { - captureUri = MultiPicker.get(MultiPicker.CAMERA).startWithExpectingFile(context, cameraActivityResultLauncher) + try { + captureUri = MultiPicker.get(MultiPicker.CAMERA).startWithExpectingFile(context, cameraActivityResultLauncher) + } catch (e: ActivityNotFoundException) { + Toast.makeText(activity, R.string.error_no_external_application_found, Toast.LENGTH_LONG).show() + } } override fun takeVideo() { - captureUri = MultiPicker.get(MultiPicker.CAMERA_VIDEO).startWithExpectingFile(context, cameraVideoActivityResultLauncher) + try { + captureUri = MultiPicker.get(MultiPicker.CAMERA_VIDEO).startWithExpectingFile(context, cameraVideoActivityResultLauncher) + } catch (e: ActivityNotFoundException) { + Toast.makeText(activity, R.string.error_no_external_application_found, Toast.LENGTH_LONG).show() + } } }) }