diff options
| -rw-r--r-- | packages/SystemUI/src/com/android/systemui/clipboardoverlay/IntentCreator.java | 3 | ||||
| -rw-r--r-- | packages/SystemUI/tests/src/com/android/systemui/clipboardoverlay/IntentCreatorTest.java | 19 |
2 files changed, 18 insertions, 4 deletions
diff --git a/packages/SystemUI/src/com/android/systemui/clipboardoverlay/IntentCreator.java b/packages/SystemUI/src/com/android/systemui/clipboardoverlay/IntentCreator.java index 3d5e601f18f5..e342ac2f320d 100644 --- a/packages/SystemUI/src/com/android/systemui/clipboardoverlay/IntentCreator.java +++ b/packages/SystemUI/src/com/android/systemui/clipboardoverlay/IntentCreator.java @@ -47,7 +47,8 @@ class IntentCreator { shareIntent.putExtra(Intent.EXTRA_STREAM, clipData.getItemAt(0).getUri()); shareIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); } else { - shareIntent.putExtra(Intent.EXTRA_TEXT, clipData.getItemAt(0).coerceToText(context)); + shareIntent.putExtra( + Intent.EXTRA_TEXT, clipData.getItemAt(0).coerceToText(context).toString()); shareIntent.setType("text/plain"); } Intent chooserIntent = Intent.createChooser(shareIntent, null) diff --git a/packages/SystemUI/tests/src/com/android/systemui/clipboardoverlay/IntentCreatorTest.java b/packages/SystemUI/tests/src/com/android/systemui/clipboardoverlay/IntentCreatorTest.java index 08fe7c486529..2a4c0eb18d02 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/clipboardoverlay/IntentCreatorTest.java +++ b/packages/SystemUI/tests/src/com/android/systemui/clipboardoverlay/IntentCreatorTest.java @@ -16,13 +16,14 @@ package com.android.systemui.clipboardoverlay; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + import android.content.ClipData; import android.content.ComponentName; import android.content.Intent; import android.net.Uri; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; +import android.text.SpannableString; import androidx.test.filters.SmallTest; import androidx.test.runner.AndroidJUnit4; @@ -129,6 +130,18 @@ public class IntentCreatorTest extends SysuiTestCase { assertEquals("image/png", target.getType()); } + @Test + public void test_getShareIntent_spannableText() { + ClipData clipData = ClipData.newPlainText("Test", new SpannableString("Test Item")); + Intent intent = IntentCreator.getShareIntent(clipData, getContext()); + + assertEquals(Intent.ACTION_CHOOSER, intent.getAction()); + assertFlags(intent, EXTERNAL_INTENT_FLAGS); + Intent target = intent.getParcelableExtra(Intent.EXTRA_INTENT, Intent.class); + assertEquals("Test Item", target.getStringExtra(Intent.EXTRA_TEXT)); + assertEquals("text/plain", target.getType()); + } + // Assert that the given flags are set private void assertFlags(Intent intent, int flags) { assertTrue((intent.getFlags() & flags) == flags); |