Reputation: 583
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?
Upvotes: 3
Views: 948
Reputation: 157437
You can't. What you can do is to check for the sdk
version
if (Build.VERSION.SDK_INT >= 9) {
// Constructor with charset
} else {
// Constructor without charset, providing the charset as string
}
Froyo devices are something like 0.7%
Upvotes: 3
Reputation: 82461
You can use new String(bytes, "UTF8")
(The constructor String(byte[], String)
). It's always available (API level 1+).
Upvotes: 8