How to use html2canvas in android in order to take a screenshot of an element in webview

我们两清 提交于 2019-12-11 16:53:32

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!