From 49c433e211c1b3ab2164cdd6491734c4be3e7013 Mon Sep 17 00:00:00 2001 From: Koji Fukui Date: Mon, 28 Mar 2022 18:02:04 +0900 Subject: [PATCH] Set an edit uri to data of ACTION_EDIT Symptom: Can't transit to edit screen when "Edit" button on ShareSheet is pressed. Root cause: ACTION_SEND intent for shared image is usually sent with image uri in EXTRA_STREAM extra. But it not always has the uri in data. ChooserActivity creates ACTION_EDIT intent for "Edit" button from the ACTION_SEND intent. So it not always has the uri in data. Most of image edit app suppose to get image uri from data. They usually don't suppose to get it from EXTRA_STREAM extra. So image is not edited. Solution: Copy image uri from EXTRA_STREAM extra to data when ChooserActivity creates ACTION_EDIT intent. Bug: 220161786 Test: Take screenshot. Tap share. Tap Edit, which opens screenshot in Photos. Change-Id: Id6ce93efacd54a86d870595ae32b4e6efcec0c04 --- .../com/android/internal/app/ChooserActivity.java | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/core/java/com/android/internal/app/ChooserActivity.java b/core/java/com/android/internal/app/ChooserActivity.java index 7bb1ed8abc0a5..9699c606d4168 100644 --- a/core/java/com/android/internal/app/ChooserActivity.java +++ b/core/java/com/android/internal/app/ChooserActivity.java @@ -1176,6 +1176,19 @@ public class ChooserActivity extends ResolverActivity implements final Intent resolveIntent = new Intent(originalIntent); resolveIntent.setComponent(cn); resolveIntent.setAction(Intent.ACTION_EDIT); + String originalAction = originalIntent.getAction(); + if (Intent.ACTION_SEND.equals(originalAction)) { + if (resolveIntent.getData() == null) { + Uri uri = resolveIntent.getParcelableExtra(Intent.EXTRA_STREAM); + if (uri != null) { + String mimeType = getContentResolver().getType(uri); + resolveIntent.setDataAndType(uri, mimeType); + } + } + } else { + Log.e(TAG, originalAction + " is not supported."); + return null; + } final ResolveInfo ri = getPackageManager().resolveActivity( resolveIntent, PackageManager.GET_META_DATA); if (ri == null || ri.activityInfo == null) {