Android WebView loadData vs loadDataWithBaseURL

September 10, 2011 Tyler Schultz

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", "");

About the Author


Mobile Platform Snapshot
Mobile Platform Snapshot

The mobile landscape is changing. Smartphones are outselling feature-phones in Canada and other parts of th...

New Tech Talk: MongoDB Redux
New Tech Talk: MongoDB Redux

Chris Westin, a mongoDB developer from 10gen, discusses more in-depth uses of mongoDB, reveals some of the ...

SpringOne 2022

Register Now