diff --git a/engine/src/flutter/shell/platform/android/io/flutter/plugin/common/StandardMessageCodec.java b/engine/src/flutter/shell/platform/android/io/flutter/plugin/common/StandardMessageCodec.java index 485af3e0af..e2a5bc7cef 100644 --- a/engine/src/flutter/shell/platform/android/io/flutter/plugin/common/StandardMessageCodec.java +++ b/engine/src/flutter/shell/platform/android/io/flutter/plugin/common/StandardMessageCodec.java @@ -234,9 +234,9 @@ public class StandardMessageCodec implements MessageCodec { } else { throw new IllegalArgumentException("Unsupported Number type: " + value.getClass()); } - } else if (value instanceof String) { + } else if (value instanceof CharSequence) { stream.write(STRING); - writeBytes(stream, ((String) value).getBytes(UTF8)); + writeBytes(stream, value.toString().getBytes(UTF8)); } else if (value instanceof byte[]) { stream.write(BYTE_ARRAY); writeBytes(stream, (byte[]) value); diff --git a/engine/src/flutter/shell/platform/android/test/io/flutter/plugin/common/StandardMessageCodecTest.java b/engine/src/flutter/shell/platform/android/test/io/flutter/plugin/common/StandardMessageCodecTest.java index 7234630ae1..96f7908848 100644 --- a/engine/src/flutter/shell/platform/android/test/io/flutter/plugin/common/StandardMessageCodecTest.java +++ b/engine/src/flutter/shell/platform/android/test/io/flutter/plugin/common/StandardMessageCodecTest.java @@ -3,6 +3,7 @@ package io.flutter.plugin.common; import static org.junit.Assert.assertArrayEquals; import static org.junit.Assert.assertEquals; +import android.text.SpannableString; import java.nio.ByteBuffer; import java.util.ArrayList; import org.junit.Test; @@ -108,4 +109,17 @@ public class StandardMessageCodecTest { float[] values = (float[]) codec.decodeMessage(message); assertArrayEquals(expectedValues, values, 0.01f); } + + @Test + public void itEncodesCharSequences() { + StandardMessageCodec codec = new StandardMessageCodec(); + + CharSequence cs = new SpannableString("hello world"); + + ByteBuffer message = codec.encodeMessage(cs); + message.flip(); + + String value = (String) codec.decodeMessage(message); + assertEquals(value, "hello world"); + } }