Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pass image from HTML via Android javascript interface

My app loads a small HTML document that contains one image in a webview. How can I fetch this image and use it as a Bitmap object in my app?

I'm already using a JavaScriptInterface together with my webview for getting some other information, like passing booleans. Is it possible to pass an image aswell via the JavaScriptIterface? Is it a good idéa or is there a better way?

like image 213
prograde Avatar asked May 06 '26 21:05

prograde


1 Answers

Take a look at this question: Get image data in JavaScript?

You might be able to draw the image on a (I presume hidden) Canvas, then Base64-encode it with toDataURL and pass that as a string through the JS interface then decode it on the Java side. I imagine it'll be slow, but it's worth a try.

like image 94
kabuko Avatar answered May 09 '26 12:05

kabuko



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!