Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

java android new String

I have to convert a byte array to a string. Therefore I use this function:

public static String byteToString(byte[] bytes) {
    String str = new String(bytes, Charset.forName("UTF8"));

    return str;
}

The problem is, that it requires API 9:

Call requires API level 9 (current min is 8): new java.lang.String

but I want to provide my app to API 8 users too. Is there any possibility or alternative?

like image 980
Phil Avatar asked Aug 15 '26 18:08

Phil


1 Answers

You can use new String(bytes, "UTF8") (The constructor String(byte[], String)). It's always available (API level 1+).

like image 150
fabian Avatar answered Aug 18 '26 08:08

fabian



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!