From 067a22883c627141004953c3858f4aac85606588 Mon Sep 17 00:00:00 2001 From: Valere Date: Mon, 16 Mar 2020 16:00:22 +0100 Subject: [PATCH] WorkAround / crash android 10 gif from keyboard fixes #1136 --- CHANGES.md | 4 +++- .../features/attachments/AttachmentsHelper.kt | 17 +++++++++++++---- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index d26237fd13..157f528747 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -8,7 +8,9 @@ Improvements 🙌: - Implementation of /join command Bugfix 🐛: - - Message transitions in encrypted rooms are jarring #518 + - Message transitions in encrypted rooms are jarring #518 + - Images that failed to send are waiting to be sent forever #1145 + - Fix / Crashed when trying to send a gif from the Gboard #1136 Translations 🗣: - diff --git a/vector/src/main/java/im/vector/riotx/features/attachments/AttachmentsHelper.kt b/vector/src/main/java/im/vector/riotx/features/attachments/AttachmentsHelper.kt index ba1197b787..c576ebe1b9 100644 --- a/vector/src/main/java/im/vector/riotx/features/attachments/AttachmentsHelper.kt +++ b/vector/src/main/java/im/vector/riotx/features/attachments/AttachmentsHelper.kt @@ -177,19 +177,28 @@ class AttachmentsHelper private constructor(private val context: Context, fun handleShareIntent(intent: Intent): Boolean { val type = intent.resolveType(context) ?: return false if (type.startsWith("image")) { - imagePicker.submit(IntentUtils.getPickerIntentForSharing(intent)) + imagePicker.submit(safeShareIntent(intent)) } else if (type.startsWith("video")) { - videoPicker.submit(IntentUtils.getPickerIntentForSharing(intent)) + videoPicker.submit(safeShareIntent(intent)) } else if (type.startsWith("audio")) { - videoPicker.submit(IntentUtils.getPickerIntentForSharing(intent)) + videoPicker.submit(safeShareIntent(intent)) } else if (type.startsWith("application") || type.startsWith("file") || type.startsWith("*")) { - filePicker.submit(IntentUtils.getPickerIntentForSharing(intent)) + filePicker.submit(safeShareIntent(intent)) } else { return false } return true } + private fun safeShareIntent(intent: Intent): Intent { + // Work around for getPickerIntentForSharing doing NPE in android 10 + return try { + IntentUtils.getPickerIntentForSharing(intent) + } catch (failure: Throwable) { + intent + } + } + private fun getPickerManagerForRequestCode(requestCode: Int): PickerManager? { return when (requestCode) { PICK_IMAGE_DEVICE -> imagePicker