I am using WebView to submit form values(I do not have access to API). Webview is invisible. User will fill just EditTexts. Webview fields will be filled using Javascript. The problem I have is CAPTCHA image. Web form has PNG image which contains CAPTCHA numbers.
HTML:
<img id="captcha_img" src="/service/INNCaptcha">
I want to take captcha image from WebView, and set it to ImageView. I tried this code:
webview.getSettings().setJavaScriptEnabled(true);
webview.setWebViewClient(new WebViewClient() {
@Override
public void onPageFinished(WebView view, String url) {
String javascript = "javascript: var form = document.getElementsByClassName('form');"
+ "var body = document.getElementsByTagName('body');"
+ "body[0].innerHTML = form[0].innerHTML;;";
view.loadUrl(javascript);
webview.setVisibility(View.VISIBLE);
//THIS PIECE OF CODE RETURNING NULL BITMAP
view.buildDrawingCache();
Bitmap bmap = ivCaptcha.getDrawingCache();
ivCaptcha.setImageBitmap(bmap);
}
});
Result: BitMap is null. I think I should identify exactly which image(PNG) I want to show. So my question is how to set image on ImageView from WebView in this case?
您必须在getDrawingCache();
之前调用setDrawingCacheEnabled (true)
getDrawingCache();
Check if you have enabled DOM on webview. Also, does it have a src
link?
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.