WebView.capturePicture failing with url parameters
<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">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("http://www.yahoo.com"); //yes</li>
<li>w.loadUrl("http://search.yahoo.com/search?p=android"); // usually not???</li>
<li>w.loadUrl("http://www.yahoo.com?foo=bar"); // nope</li>
<li>w.loadUrl("http://www.google.com"); // yep</li>
<li>w.loadUrl("http://www.google.com?q=android"); // yep</li>
<li>w.loadUrl("http://www.google.com?foo=bar"); // 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>

<p>Thanks!</p>
