Browse Source

Use chooser intent for sharing saved pages

arkon 3 years ago
parent
commit
649209890d

+ 2 - 2
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))
     }
 
     /**

+ 1 - 6
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)

+ 10 - 3
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
     }
 }