I'm using this code to get scandinavian characters posted to php correctly.
Issue here is that StandardCharsets.UTF_8 is not supported before API 19
byte[] postData = urlParameters.getBytes(StandardCharsets.UTF_8); DataOutputStream wr = new DataOutputStream( con.getOutputStream()); wr.write( postData );
Field requires API level 19 (Current min is 14): java.nio.charset.StandardCharsets#UTF_8
How should I do this with API lower than 19?
Introduction. When working with Strings in Java, we oftentimes need to encode them to a specific charset, such as UTF-8. UTF-8 represents a variable-width character encoding that uses between one and four eight-bit bytes to represent all valid Unicode code points.
US_ASCII. public static final Charset US_ASCII. Seven-bit ASCII, a.k.a. ISO646-US, a.k.a. the Basic Latin block of the Unicode character set.
Use forName static method of Charset class:
byte[] postData = urlParameters.getBytes(Charset.forName("UTF-8"));
List of standard charsets you can find in documentation.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With