Java android new string

Java android new string … here is a solution to the problem.

Java android new string

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

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

return str;
}

The problem is, it requires API 9:

The call requires API level 9 (currently minimum 8): new java.lang.String

But I also want to make my application available to API 8 users. Are there any possibilities or alternatives?

Solution

You can use > new String(bytes, “UTF8”) (constructor String(byte[], String)). It is always available (API level 1+).

Related Problems and Solutions