Glad You're Ready. Let's Get Started!

Let us know how we can contact you.

Thank you!

We'll respond shortly.

  • Blog Navigation
Android WebView loadData vs loadDataWithBaseURL

We spent some time trying to figure out why some html content would not load in our app’s WebView. We found trivial html can be loaded into a WebView using the loadData(String, String, String) method. Rendering complex pages with Javascript is a problem. It turns out the loadData() method requires the html to be URI escaped (RTFM? Bah!). There are additional characters that need to be escaped too, requiring some nasty boilerplate.

The simpler solution (workaround?) is to use loadDataWithBaseURL(String, String, String, String, String). Calls to this method do not require escaping. Pass along a garbage base url (or null), and an empty or null history url for success and profit.

webView.loadDataWithBaseURL("blarg://ignored", getData(), "text/html", "utf-8", "");
  1. Dave Sims says:

    Also, loadDataWithBaseUrl will allow you load local resources. I ran into this recently when I couldn’t figure out why my WebView template wouldn’t load zepto from a local html template:

    …and that was it — loadData doesn’t allow loading assets but loadDataWithBaseUrl does.

Post a Comment

Your Information (Name required. Email address will not be displayed with comment.)

* Copy This Password *

* Type Or Paste Password Here *

Share This