Rafael Costa
11/11/2022, 7:01 PM@SuppressLint("NewApi", "ObsoleteSdkInt")
internal fun ByteArray.toBase64Str(): String {
// Both these methods (from java util and android util) seem to
// do exactly the same.
// The second doesn't work on Unit tests and the first doesn't work
// on older devices.
// Also, on unit tests SDK_INT is 0, but we're running on the developer's machine
// So we can still use java.util in that case
return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O || Build.VERSION.SDK_INT == 0) {
java.util.Base64.getUrlEncoder().encodeToString(this)
} else {
android.util.Base64.encodeToString(this, Base64.URL_SAFE or Base64.NO_WRAP)
}
}
Rafael Costa
11/11/2022, 7:10 PMSDK_INT == 0
, meaning always use the android version on non-testsephemient
11/11/2022, 7:11 PMephemient
11/11/2022, 7:12 PMRafael Costa
11/11/2022, 7:12 PMRafael Costa
11/11/2022, 7:13 PMephemient
11/11/2022, 7:13 PMephemient
11/11/2022, 7:14 PMjava.util.Base64
and let the Android toolchain desugar it as necessary. unfortunately that's no the case now, but there's a feature request: https://issuetracker.google.com/issues/171293709Rafael Costa
11/11/2022, 7:15 PMRafael Costa
11/11/2022, 7:15 PMRafael Costa
11/11/2022, 7:16 PMideally you could just useInteresting, I'll check this. It's not a solution right now, but it's good to check for sure 🙂and let the Android toolchain desugar it as necessary. unfortunately that's no the case now, but there's a feature request: https://issuetracker.google.com/issues/171293709java.util.Base64
ephemient
11/11/2022, 7:16 PMRafael Costa
11/11/2022, 7:18 PMephemient
11/11/2022, 7:19 PMRafael Costa
11/11/2022, 7:19 PMRafael Costa
11/11/2022, 7:20 PMRafael Costa
11/11/2022, 7:25 PMephemient
11/27/2022, 12:32 PM