use ACTION_GET_CONTENT for media selection again, fix uri permissions (#695)

This commit is contained in:
Konrad Pozniak 2018-06-28 22:22:29 +02:00 committed by GitHub
parent c7c2b5feb9
commit 1c5df27f91
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 25 additions and 5 deletions

View File

@ -861,10 +861,10 @@ public final class ComposeActivity
private void sendStatus(String content, Status.Visibility visibility, boolean sensitive,
String spoilerText) {
ArrayList<String> mediaIds = new ArrayList<>();
ArrayList<String> mediaUris = new ArrayList<>();
ArrayList<Uri> 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/*"};

View File

@ -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<String>,
mediaUris: List<String>,
mediaUris: List<Uri>,
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
}