Pivotal Labs

Main menu

Skip to primary content
Skip to secondary content
  • About
  • Case Studies
  • Team
    • Executives
    • Locations
      • San Francisco (HQ)
      • Boston
      • Boulder
      • Denver
      • London
      • Los Angeles
      • New York
  • Community
    • Blogs
    • Tech Talks
    • Events
  • Careers
    • Lifestyle
    • Principles & Practices
    • Benefits
    • FAQ
    • Apply
  • Contact
    • Press Room
    • Press Releases
    • In The News
    • Press Kit
  • All
  • Labs
  • Standup
  • Tracker

Android WebView loadData vs loadDataWithBaseURL

Tyler Schultz
Saturday, September 10, 2011

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", "");
  • 0 Shares
  • Share on Facebook
  • Share on Twitter

One comment

  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.

    September 19, 2011 at 8:29 am

Add New Comment Cancel reply

Your email address will not be published.

Tyler Schultz

Tyler Schultz
San Francisco

Recent Posts

  • [Standup][SF] 09/21/12: Get older faster
  • Ah, ah, ah. Now, that was silly. Wouldn’t you agree, my bats? Ah, ah, ah.
  • [SF][Standup] 09/19/12: ActiveAdmin vs. RailsAdmin… Arrrggg!
Subscribe to Tyler's Feed

Author Topics

rails (5)
time (2)
css (1)
heroku (2)
javascript (1)
activerecord (1)
android (3)
robolectric (1)
tdd (1)
agile (7)
amazon (1)
default scope (1)
hudson (1)
rspec (1)
  • About
  • Case Studies
  • Team
  • Community
  • Careers
  • Contact
  • Labs
  • Events

Contact Us

contact@pivotallabs.com
+1 415-77-PIVOT
TwitterLinkedInFacebook

Pivotal Tracker

Tracker is the award-winning agile project management tool that enables real-time collaboration around a shared, prioritized backlog.
Visit pivotaltracker.com >