[Android Newbie alert]
I need to grab the contents of a WebView in BitMap, and I am having a strange problem. My approach is to register a WebViewClient with a WebView, and in onPageFinished I call capturePicture. With a simple URL (e.g. http://www.yahoo.com ), it works fine. In other cases, capturePicture returns an image with height and width = 0. The page loads fine, anyway. The actual url that I should use has quite a few url parameters, and initially I thought that having any parameters was a problem, but that is not the case. Here are some examples of URLs with comments indicating whether it works or not:
The second case is especially frustrating because it does not seem to work. However, if I first run the C # 5 test application, then the URL switches to # 2 and launches it.
Here is a snippet of the actual simplified test that I created:
public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState);
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 }
Has anyone encountered this problem? I hope I'm just an idiot and is there a simple solution or a workaround?
ted
source share