From 649209890d0a7db70dac23bb536d4e40cd8d4b00 Mon Sep 17 00:00:00 2001 From: arkon Date: Sat, 24 Jul 2021 11:56:55 -0400 Subject: [PATCH] Use chooser intent for sharing saved pages --- .../data/notification/NotificationReceiver.kt | 4 ++-- .../eu/kanade/tachiyomi/ui/manga/MangaController.kt | 7 +------ .../tachiyomi/util/system/IntentExtensions.kt | 13 ++++++++++--- 3 files changed, 13 insertions(+), 11 deletions(-) diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/notification/NotificationReceiver.kt b/app/src/main/java/eu/kanade/tachiyomi/data/notification/NotificationReceiver.kt index 1d6cadb866..f8315e7f93 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/notification/NotificationReceiver.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/notification/NotificationReceiver.kt @@ -131,7 +131,7 @@ class NotificationReceiver : BroadcastReceiver() { */ private fun shareImage(context: Context, path: String, notificationId: Int) { dismissNotification(context, notificationId) - context.startActivity(File(path).getUriCompat(context).toShareIntent()) + context.startActivity(File(path).getUriCompat(context).toShareIntent(context)) } /** @@ -143,7 +143,7 @@ class NotificationReceiver : BroadcastReceiver() { */ private fun shareFile(context: Context, uri: Uri, fileMimeType: String, notificationId: Int) { dismissNotification(context, notificationId) - context.startActivity(uri.toShareIntent(fileMimeType)) + context.startActivity(uri.toShareIntent(context, fileMimeType)) } /** diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaController.kt index d0468d0097..721ae1d331 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaController.kt @@ -688,12 +688,7 @@ class MangaController : useCoverAsBitmap(activity) { coverBitmap -> val cover = presenter.shareCover(activity, coverBitmap) val uri = cover.getUriCompat(activity) - startActivity( - Intent.createChooser( - uri.toShareIntent(), - activity.getString(R.string.action_share) - ) - ) + startActivity(uri.toShareIntent(activity)) } } catch (e: Exception) { Timber.e(e) diff --git a/app/src/main/java/eu/kanade/tachiyomi/util/system/IntentExtensions.kt b/app/src/main/java/eu/kanade/tachiyomi/util/system/IntentExtensions.kt index 84513930a4..5b159a1c33 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/util/system/IntentExtensions.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/util/system/IntentExtensions.kt @@ -1,15 +1,22 @@ package eu.kanade.tachiyomi.util.system import android.content.ClipData +import android.content.Context import android.content.Intent import android.net.Uri +import eu.kanade.tachiyomi.R -fun Uri.toShareIntent(type: String = "image/*"): Intent { +fun Uri.toShareIntent(context: Context, type: String = "image/*"): Intent { val uri = this - return Intent(Intent.ACTION_SEND).apply { + + val shareIntent = Intent(Intent.ACTION_SEND).apply { putExtra(Intent.EXTRA_STREAM, uri) clipData = ClipData.newRawUri(null, uri) setType(type) - flags = Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_GRANT_READ_URI_PERMISSION + flags = Intent.FLAG_GRANT_READ_URI_PERMISSION + } + + return Intent.createChooser(shareIntent, context.getString(R.string.action_share)).apply { + flags = Intent.FLAG_ACTIVITY_NEW_TASK } }