Base64 support for different API levels Base64 support for different API levels android android

Base64 support for different API levels


Use android.util.Base64 will resolve your problem its available from API 8

data = android.util.Base64.decode(str, android.util.Base64.DEFAULT);

Example usage:

Log.i(TAG, "data: " + new String(data));


You should be using the android.util.Base64 class. It is supported from API 8,

The Base64.getDecoder() function is part of java.util.Base64 and new in Java8.


fun String.toBase64(): String {    return String(        android.util.Base64.encode(this.toByteArray(), android.util.Base64.DEFAULT),        StandardCharsets.UTF_8    )}fun String.fromBase64(): String {    return String(        android.util.Base64.decode(this, android.util.Base64.DEFAULT),        StandardCharsets.UTF_8    )}