Note that there are some explanatory texts on larger screens.

plurals
  1. POWebView.capturePicture failing with url parameters
    text
    copied!<p>[Android Newbie alert]</p> <p>I need to capture the contents of a WebView in a BitMap and I've run into a strange problem. My approach is to register a WebViewClient with the WebView, and in <em>onPageFinished</em> I call <em>capturePicture</em>. With a simple URL (e.g. <a href="http://www.yahoo.com" rel="nofollow noreferrer">http://www.yahoo.com</a>), it works fine. In other cases, capturePicture returns a Picture with height and width values = 0. The page loads fine, either way. The actual url I have to use has quite a few url parameters and I initially thought having any parameters was the problem, but that's not the case. Here's a few sample urls with comments indicating whether it works or not:</p> <ol> <li>w.loadUrl("<a href="http://www.yahoo.com" rel="nofollow noreferrer">http://www.yahoo.com</a>"); //yes</li> <li>w.loadUrl("<a href="http://search.yahoo.com/search?p=android" rel="nofollow noreferrer">http://search.yahoo.com/search?p=android</a>"); // usually not???</li> <li>w.loadUrl("<a href="http://www.yahoo.com?foo=bar" rel="nofollow noreferrer">http://www.yahoo.com?foo=bar</a>"); // nope</li> <li>w.loadUrl("<a href="http://www.google.com" rel="nofollow noreferrer">http://www.google.com</a>"); // yep</li> <li>w.loadUrl("<a href="http://www.google.com?q=android" rel="nofollow noreferrer">http://www.google.com?q=android</a>"); // yep</li> <li>w.loadUrl("<a href="http://www.google.com?foo=bar" rel="nofollow noreferrer">http://www.google.com?foo=bar</a>"); // yes</li> </ol> <p>The second case is particularly frustrating as it appears to not work. However, if I run the test app with #5 first, then switching the url to #2 and running it then works.</p> <p>Here's a snippet of an actual simplified test I created:</p> <blockquote> <pre><code>public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); </code></pre> </blockquote> <pre><code> w = new WebView(this); w.setWebViewClient(new WebViewClient() { public void onPageFinished(WebView webview, String url) { Picture picture = webview.capturePicture(); Log.d("Height", "" + picture.getHeight()); Log.d("Width", "" + picture.getWidth()); Bitmap b = Bitmap.createBitmap(picture.getWidth(), picture .getHeight(), Bitmap.Config.ARGB_8888); Canvas c = new Canvas(b); picture.draw(c); } }); w.getSettings().setJavaScriptEnabled(true); setContentView(w); //w.loadUrl("http://www.yahoo.com"); //yes w.loadUrl("http://search.yahoo.com/search?p=android"); // usually not??? //w.loadUrl("http://www.yahoo.com?foo=bar"); // nope //w.loadUrl("http://www.google.com"); // yep //w.loadUrl("http://www.google.com?q=android"); // yep //w.loadUrl("http://www.google.com?foo=bar"); // yes } </code></pre> <p>Has anyone run into this issue? Hopefully I'm just being an idiot and there's a simple solution or workaround?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload