Greetings!  I've been stumped on a WebView AppCache problem for a while 
now.  I'm attempting to use loadDataWithBaseURL() to load literal HTML 
sourcing JS, CSS, images, and iframes into a WebView.  At the same time I 
am using the HTML5 AppCache to store this content locally.  My problem is 
that when the device is offline, no content except the HTML sourced in the 
iframe is loaded from the AppCache.  I am certain that AppCache is enabled 
and that the content is being stored in the AppCache (I poked around with 
adb shell).  I am also specifying a correct base URL.  My code resembles 
this:

public class ExampleActivity extends Activity {
  ...
  // HTML to be inserted into the WebView with loadDataWithBaseURL()
  public static final String ALL_HTML = 
    "<!DOCTYPE html><html>" +
    "<head><script src='sourced_js.js' "+
      "onload='console.log(\"sourced_js.js onload\");'>" +
    "</script>" +
    "<link rel='stylesheet' href='style.css' />" +   // doesn't load offline
    "</head><body>" +
    "<iframe src='manifest.html'></iframe>" +        // loads
    "<img src='android.jpg' />" +                    // doesn't load
    "<img src='android.gif' />" +                    // doesn't load
    "</body></html>";

  public void onCreate(Bundle savedInstanceState) {
    ...
    WebView webView = new WebView(content);
    webView.clearCache(true);

    WebSettings settings = WebView.getSettings();
    settings.setAppCacheEnabled(true);
    settings.setJavaScriptEnabled(true);
  
    webView.loadDataWithBaseURL("http://my.website.come/path/to/content/";,
        ALL_HTML, "text/html", "utf-8", null);
  }
}

The manifest.html file is just responsible for sourcing the manifest.  It 
looks like:

<html manifest="manifest.appcache">
<head></head>
<body></body>
</html>

and manifest.appcache looks like:

CACHE MANIFEST

# Explicitly cached resources
# manifest.html is automatically cached
sourced_js.js
android.jpg
android.gif
style.css

NETWORK:
*

When online, all content loads.  When offline, only the iframe with 
manifest.html loads from the AppCache.  None of the images, stylesheets, or 
JavaScript in the original literal html load in the WebView from AppCache 
when the device is offline, but if I source those same contents in 
manifest.html, they DO load in the iframe.  As if these resources have to 
be sourced secondarily.

I'm positively stumped--Are there rules regarding when AppCache can be used 
with loadDataWithBaseURL()?

Thanks a ton!

Andy

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to