From 74363ff8235764c0dc15ebb6b3dce42a6f52b56d Mon Sep 17 00:00:00 2001 From: Tobias Preuss Date: Fri, 31 Dec 2021 22:28:46 +0100 Subject: [PATCH] Let ShareCompat.IntentBuilder create the chooser intent for sharing content. + Although the system's intent chooser normally takes care of cases when no app is found we still keep the safeguard here to be prepared for exotic devices behaving different. Signed-off-by: Tobias Preuss --- changelog.d/4745.misc | 1 + .../app/core/utils/ExternalApplicationsUtil.kt | 18 ++++++++++-------- 2 files changed, 11 insertions(+), 8 deletions(-) create mode 100644 changelog.d/4745.misc diff --git a/changelog.d/4745.misc b/changelog.d/4745.misc new file mode 100644 index 0000000000..458422d112 --- /dev/null +++ b/changelog.d/4745.misc @@ -0,0 +1 @@ +Open share UI provides by the system when sharing media or text. \ No newline at end of file diff --git a/vector/src/main/java/im/vector/app/core/utils/ExternalApplicationsUtil.kt b/vector/src/main/java/im/vector/app/core/utils/ExternalApplicationsUtil.kt index 8185808484..06da70f391 100644 --- a/vector/src/main/java/im/vector/app/core/utils/ExternalApplicationsUtil.kt +++ b/vector/src/main/java/im/vector/app/core/utils/ExternalApplicationsUtil.kt @@ -305,26 +305,28 @@ fun shareMedia(context: Context, file: File, mediaMimeType: String?) { return } - val sendIntent = ShareCompat.IntentBuilder(context) + val chooserIntent = ShareCompat.IntentBuilder(context) .setType(mediaMimeType) .setStream(mediaUri) - .intent + .setChooserTitle(R.string.share) + .createChooserIntent() - sendShareIntent(context, sendIntent) + createChooser(context, chooserIntent) } fun shareText(context: Context, text: String) { - val sendIntent = ShareCompat.IntentBuilder(context) + val chooserIntent = ShareCompat.IntentBuilder(context) .setType("text/plain") .setText(text) - .intent + .setChooserTitle(R.string.share) + .createChooserIntent() - sendShareIntent(context, sendIntent) + createChooser(context, chooserIntent) } -private fun sendShareIntent(context: Context, intent: Intent) { +private fun createChooser(context: Context, intent: Intent) { try { - context.startActivity(Intent.createChooser(intent, context.getString(R.string.share))) + context.startActivity(intent) } catch (activityNotFoundException: ActivityNotFoundException) { context.toast(R.string.error_no_external_application_found) }