Search code examples
androidencodingcp1251

Android set character encoding


How can I set the encoding of EditText value?

I tried this but it does not seem to work.

String test = new String(myField.getText().toString().getBytes(), "Cp1251");

The receiver still has invalid value.


Solution

  • A string is always internally (in the String class) stored as unicode.

    You should specify the encoding when you convert the string to bytes, and are sending the data.

    That is, invoke getBytes(String encoding) on the string, and send the resulting byte array to the receiver.