1

New to Android programming. I need to develop an app getting screenshot of a webpage every time something change inside it. My first way was to extend WebView class and overrite onDraw() call. This allow me to know when web page change by get redraw request and take new screenshot. The problem is, obviously, onDraw is called only if the WebView control is currently visibile on the view but in my case I need to keep it hidden since I want to use only the webkit engine in background and show in the interface only the screenshot of the current page. If I keep hide the WebView no redraw event is delivered. So my question is if there is a way to make what I need? (hope to explained well my problem). Please note, "keep hide" mean I don't put the WebView control inside the layout interface but create separately by using something like "new WebView(this)" at app startup.

Thank you

Suppaman
  • 151
  • 1
  • 12

1 Answers1

0

Just render to a bitmap as these guys did: Converting a view to Bitmap without displaying it in Android?

Override onPageFinished and draw the view in there.

Community
  • 1
  • 1
eduyayo
  • 2,020
  • 2
  • 15
  • 35
  • Hi Thank you for your reply. The onPageFinished is called only once when the engine finished to load the HTML code but this doesn't mean all the page items was finished to load since some images could still need to be load and showed. In add of this I need to know every time there is a "dynamic" update of the page and need to be redrawed (for example some image was changed by javascript code internal to the page itself). – Suppaman Nov 17 '14 at 16:00
  • when you set your `WebViewClient`, override also the `onLoadResource`, you see where I´m going?. Just listen to whatever. Although you won´t really know whether it DID already download, you can wait for a safe timeout. – eduyayo Nov 17 '14 at 16:36
  • BTW, you can set a default RequestFactory to the HttpClient and know for sure if one specific url finished downloading by just handling the inputstream yourself. – eduyayo Nov 17 '14 at 16:36
  • Hi unfortunately, follow my example of javascript code changing some preloaded images into the page, your way doesn't work for me. Your suggestion was good but only for "static" pages. Usually javascript code preload all the images they need and change "on the fly" inside the page. Since the images are preloaded you can not see any changes by monitorig the http request... – Suppaman Nov 18 '14 at 08:08
  • you absolutelly can. the WebView MUST get the connections from the runtime, it won´t open connections out of it. If not from the httpClient, maybe using URLConnection but, it will. – eduyayo Nov 18 '14 at 15:47
  • Sorry, probably I was not clear in explain my problem. I need to "capture" the redraw event of the page. This mean every time something change (a bitmap is changed by some javascript code) I need to be "advised" for update my data. You suggestion is based to the assumption evety time something is changed a new connection will be estabilish for download the new element of the page. – Suppaman Nov 19 '14 at 09:46
  • (second part of reply) However usually javascript code preload all the images it need (than the http connection happen only once at begin) and store in memory for use later and optimize speed. Based to this example your way didn't help me since I need to capture the time when the image is changed on the visible page and not when is downloaded. – Suppaman Nov 19 '14 at 09:46
  • wah... even if you could (not sure you can) capture such repaint event in javascript, you won´t probably have it since the view is not showing and the browser won´t ever tell the script or the document to render itself... I *belive* you´re hopeless with such task. Maybe just show the page as it is with the webview and render the component non clickable – eduyayo Nov 19 '14 at 13:18