Use chooser intent for sharing saved pages

This commit is contained in:
arkon 2021-07-24 11:56:55 -04:00
parent f2fca0f13d
commit 649209890d
3 changed files with 13 additions and 11 deletions

View File

@ -131,7 +131,7 @@ class NotificationReceiver : BroadcastReceiver() {
*/ */
private fun shareImage(context: Context, path: String, notificationId: Int) { private fun shareImage(context: Context, path: String, notificationId: Int) {
dismissNotification(context, notificationId) 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) { private fun shareFile(context: Context, uri: Uri, fileMimeType: String, notificationId: Int) {
dismissNotification(context, notificationId) dismissNotification(context, notificationId)
context.startActivity(uri.toShareIntent(fileMimeType)) context.startActivity(uri.toShareIntent(context, fileMimeType))
} }
/** /**

View File

@ -688,12 +688,7 @@ class MangaController :
useCoverAsBitmap(activity) { coverBitmap -> useCoverAsBitmap(activity) { coverBitmap ->
val cover = presenter.shareCover(activity, coverBitmap) val cover = presenter.shareCover(activity, coverBitmap)
val uri = cover.getUriCompat(activity) val uri = cover.getUriCompat(activity)
startActivity( startActivity(uri.toShareIntent(activity))
Intent.createChooser(
uri.toShareIntent(),
activity.getString(R.string.action_share)
)
)
} }
} catch (e: Exception) { } catch (e: Exception) {
Timber.e(e) Timber.e(e)

View File

@ -1,15 +1,22 @@
package eu.kanade.tachiyomi.util.system package eu.kanade.tachiyomi.util.system
import android.content.ClipData import android.content.ClipData
import android.content.Context
import android.content.Intent import android.content.Intent
import android.net.Uri 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 val uri = this
return Intent(Intent.ACTION_SEND).apply {
val shareIntent = Intent(Intent.ACTION_SEND).apply {
putExtra(Intent.EXTRA_STREAM, uri) putExtra(Intent.EXTRA_STREAM, uri)
clipData = ClipData.newRawUri(null, uri) clipData = ClipData.newRawUri(null, uri)
setType(type) 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
} }
} }