问题
i'm trying to get screenshot of a captcha in webview, using html2canvas plugin
implementation 'cljsjs:html2canvas:0.4.1-0'
there's also html2canvas:1.0.0-alpha.12-1 but i can't use it because of this error
ERROR: Failed to resolve: html2canvas Affected Modules: app
Anyway,
i found this Android: Sending image URI from webview website to app
But i don't know how to use it
I tried to Toast the Image Uri to check if it's working or not
view.loadUrl("javascript:api.testImage(\t\t\t function()\n" +
"{\n" +
" html2canvas(document.querySelector(\"body > table.troisbords > tbody > tr > td > table > tbody > tr > td > div > blockquote > table > tbody > tr:nth-child(2) > td > form > table > tbody > tr:nth-child(4) > td:nth-child(2) > img\"), {\n" +
"\n" +
" onrendered: function(canvas) \n" +
" {\n" +
" var strDataURI = canvas.toDataURL(\"image/jpeg\");\n" +
" JSInterface.testImage(strDataURI);\n" +
" }\n" +
" });\n" +
"})();");
Using the method below, the toast shows undefined
class JSInterface {
@JavascriptInterface
public void testImage(String imageUri) {
Toast.makeText(Moyenne.this,imageUri, Toast.LENGTH_LONG).show();
}
}
来源:https://stackoverflow.com/questions/57029398/how-to-use-html2canvas-in-android-in-order-to-take-a-screenshot-of-an-element-in