From 3979027471de12aecd9753ec9f48f3c8fa572400 Mon Sep 17 00:00:00 2001 From: FatttSnake Date: Thu, 10 Oct 2024 01:21:18 +0800 Subject: [PATCH] Refactor(NativeWebApi): Change data transfer type from ByteArray to Base64 String --- .../kotlin/top/fatweb/oxygen/toolbox/util/NativeWebApi.kt | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/app/src/main/kotlin/top/fatweb/oxygen/toolbox/util/NativeWebApi.kt b/app/src/main/kotlin/top/fatweb/oxygen/toolbox/util/NativeWebApi.kt index 4e3c94e..c9c971d 100644 --- a/app/src/main/kotlin/top/fatweb/oxygen/toolbox/util/NativeWebApi.kt +++ b/app/src/main/kotlin/top/fatweb/oxygen/toolbox/util/NativeWebApi.kt @@ -8,6 +8,7 @@ import android.content.Context.CLIPBOARD_SERVICE import android.os.Build import android.os.Environment import android.provider.MediaStore +import android.util.Base64 import android.webkit.JavascriptInterface import android.webkit.WebView import androidx.activity.compose.ManagedActivityResultLauncher @@ -39,7 +40,9 @@ class NativeWebApi( } @JavascriptInterface - fun saveToDownloads(data: ByteArray, fileName: String): Boolean { + fun saveToDownloads(dataBase64: String, fileName: String): Boolean { + val data = Base64.decode(dataBase64, Base64.DEFAULT) + return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) { saveFileToDownloads(data = data, fileName = fileName) } else {