From 5fd3317197fbd46628ae5a596331dc9a0e185537 Mon Sep 17 00:00:00 2001 From: Tobias Preuss Date: Thu, 16 Dec 2021 23:34:08 +0100 Subject: [PATCH 1/3] Use property access syntax. Signed-off-by: Tobias Preuss --- .../java/im/vector/app/core/utils/ExternalApplicationsUtil.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 bdaf520ba12..818482043fc 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 @@ -308,7 +308,7 @@ fun shareMedia(context: Context, file: File, mediaMimeType: String?) { val sendIntent = ShareCompat.IntentBuilder(context) .setType(mediaMimeType) .setStream(mediaUri) - .getIntent() + .intent sendShareIntent(context, sendIntent) } From 70b07471cf555327ba2b9c090dfe08033167ccee Mon Sep 17 00:00:00 2001 From: Tobias Preuss Date: Thu, 16 Dec 2021 23:13:18 +0100 Subject: [PATCH 2/3] Use ShareCompat.IntentBuilder in "shareText()" utility function. Signed-off-by: Tobias Preuss --- .../im/vector/app/core/utils/ExternalApplicationsUtil.kt | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) 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 818482043fc..8185808484a 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 @@ -314,10 +314,10 @@ fun shareMedia(context: Context, file: File, mediaMimeType: String?) { } fun shareText(context: Context, text: String) { - val sendIntent = Intent() - sendIntent.action = Intent.ACTION_SEND - sendIntent.type = "text/plain" - sendIntent.putExtra(Intent.EXTRA_TEXT, text) + val sendIntent = ShareCompat.IntentBuilder(context) + .setType("text/plain") + .setText(text) + .intent sendShareIntent(context, sendIntent) } From 74363ff8235764c0dc15ebb6b3dce42a6f52b56d Mon Sep 17 00:00:00 2001 From: Tobias Preuss Date: Fri, 31 Dec 2021 22:28:46 +0100 Subject: [PATCH 3/3] 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 00000000000..458422d1123 --- /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 8185808484a..06da70f391c 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) }