Fix crash on no camera app found

Change-Id: I09888ed8192fae484a8c19f92cedfcca0e6498a9
This commit is contained in:
SpiritCroc 2022-07-17 19:03:54 +02:00
parent 98924094fb
commit ef55a8450f

View file

@ -16,11 +16,14 @@
package im.vector.app.features.attachments package im.vector.app.features.attachments
import android.app.Activity import android.app.Activity
import android.content.ActivityNotFoundException
import android.content.Context import android.content.Context
import android.content.Intent import android.content.Intent
import android.net.Uri import android.net.Uri
import android.os.Bundle import android.os.Bundle
import android.widget.Toast
import androidx.activity.result.ActivityResultLauncher import androidx.activity.result.ActivityResultLauncher
import im.vector.app.R
import im.vector.app.core.dialogs.PhotoOrVideoDialog import im.vector.app.core.dialogs.PhotoOrVideoDialog
import im.vector.app.core.platform.Restorable import im.vector.app.core.platform.Restorable
import im.vector.app.features.settings.VectorPreferences 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 { PhotoOrVideoDialog(activity, vectorPreferences).show(object : PhotoOrVideoDialog.PhotoOrVideoDialogListener {
override fun takePhoto() { override fun takePhoto() {
try {
captureUri = MultiPicker.get(MultiPicker.CAMERA).startWithExpectingFile(context, cameraActivityResultLauncher) 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() { override fun takeVideo() {
try {
captureUri = MultiPicker.get(MultiPicker.CAMERA_VIDEO).startWithExpectingFile(context, cameraVideoActivityResultLauncher) 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()
}
} }
}) })
} }