Trying to send a base64 image to JavaScript is proving challenging as I keep encountering an error in Android Studio:
W/chromium: [WARNING:navigator_impl.cc(280)] Refusing to load URL as it exceeds 2097152 characters.
Despite attempting to use loadDataWithBaseURL, I am struggling to get the JavaScript to execute properly - leaving me uncertain if it's a viable solution.
The code I'm using works for some images but fails with larger ones, resulting in the aforementioned error.
If anyone has any insights or solutions, they would be greatly appreciated!
if (resultCode == RESULT_OK)
{
Uri selectedImage = intent.getData();
myWebView.loadUrl("javascript:setFileUri('" + selectedImage.toString() + "')");
String path = getRealPathFromURI(this, selectedImage);
//myWebView.loadUrl("javascript:setFilePath('" + path + "')");
Bitmap bm = BitmapFactory.decodeFile(path);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
bm.compress(Bitmap.CompressFormat.JPEG, 100, baos); //bm is the bitmap object
byte[] b = baos.toByteArray();
String encodedImage = Base64.encodeToString(b, Base64.DEFAULT);
myWebView.loadUrl("javascript:setFilePath('" + encodedImage + "')");
}