From 94c37a16c07aefe76173e94c1f74d7f4ad6d8764 Mon Sep 17 00:00:00 2001 From: Konrad Pozniak Date: Thu, 28 Jun 2018 22:22:29 +0200 Subject: [PATCH] use ACTION_GET_CONTENT for media selection again, fix uri permissions (#695) --- .../keylesspalace/tusky/ComposeActivity.java | 6 ++--- .../tusky/service/SendTootService.kt | 24 +++++++++++++++++-- 2 files changed, 25 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/com/keylesspalace/tusky/ComposeActivity.java b/app/src/main/java/com/keylesspalace/tusky/ComposeActivity.java index 81e0abac..b2346146 100644 --- a/app/src/main/java/com/keylesspalace/tusky/ComposeActivity.java +++ b/app/src/main/java/com/keylesspalace/tusky/ComposeActivity.java @@ -861,10 +861,10 @@ public final class ComposeActivity private void sendStatus(String content, Status.Visibility visibility, boolean sensitive, String spoilerText) { ArrayList mediaIds = new ArrayList<>(); - ArrayList mediaUris = new ArrayList<>(); + ArrayList mediaUris = new ArrayList<>(); for (QueuedMedia item : mediaQueued) { mediaIds.add(item.id); - mediaUris.add(item.uri.toString()); + mediaUris.add(item.uri); } Intent sendIntent = SendTootService.sendTootIntent(this, content, spoilerText, @@ -1008,7 +1008,7 @@ public final class ComposeActivity } private void initiateMediaPicking() { - Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT); + Intent intent = new Intent(Intent.ACTION_GET_CONTENT); intent.addCategory(Intent.CATEGORY_OPENABLE); String[] mimeTypes = new String[]{"image/*", "video/*"}; diff --git a/app/src/main/java/com/keylesspalace/tusky/service/SendTootService.kt b/app/src/main/java/com/keylesspalace/tusky/service/SendTootService.kt index 18357b1f..112a2ef8 100644 --- a/app/src/main/java/com/keylesspalace/tusky/service/SendTootService.kt +++ b/app/src/main/java/com/keylesspalace/tusky/service/SendTootService.kt @@ -4,8 +4,11 @@ import android.app.NotificationChannel import android.app.NotificationManager import android.app.PendingIntent import android.app.Service +import android.content.ClipData +import android.content.ClipDescription import android.content.Context import android.content.Intent +import android.net.Uri import android.os.Build import android.os.IBinder import android.os.Parcelable @@ -270,7 +273,7 @@ class SendTootService : Service(), Injectable { visibility: Status.Visibility, sensitive: Boolean, mediaIds: List, - mediaUris: List, + mediaUris: List, inReplyToId: String?, replyingStatusContent: String?, replyingStatusAuthorUsername: String?, @@ -287,7 +290,7 @@ class SendTootService : Service(), Injectable { visibility.serverString(), sensitive, mediaIds, - mediaUris, + mediaUris.map { it.toString() }, inReplyToId, replyingStatusContent, replyingStatusAuthorUsername, @@ -299,6 +302,23 @@ class SendTootService : Service(), Injectable { intent.putExtra(KEY_TOOT, tootToSend) + if(mediaUris.isNotEmpty()) { + // forward uri permissions + intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION) + val uriClip = ClipData( + ClipDescription("Toot Media", arrayOf("image/*", "video/*")), + ClipData.Item(mediaUris[0]) + ) + mediaUris + .drop(1) + .forEach { mediaUri -> + uriClip.addItem(ClipData.Item(mediaUri)) + } + + intent.clipData = uriClip + + } + return intent }