[android-developers] AppCache not working in WebView with loadDataWithBaseURL()

2012-07-10 Thread Andy Erickson
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 htmlhtml +
headscript src='sourced_js.js' +
  onload='console.log(\sourced_js.js onload\);' +
/script +
link rel='stylesheet' href='style.css' / +   // doesn't load offline
/headbody +
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 android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Re: [android-developers] AppCache not working in WebView with loadDataWithBaseURL()

2012-07-10 Thread Andy Erickson
However, specifying this base URL allows the iframed HTML to load from the 
AppCache, so it looks like some domain information is being extracted from 
the URL.  Is there any reason why the iframe element should load from the 
AppCache while the other elements do not?

On Tuesday, July 10, 2012 3:53:34 AM UTC-7, Mark Murphy (a Commons Guy) 
wrote:

 On Mon, Jul 9, 2012 at 2:12 PM, Andy Erickson wrote: 
  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. 

 All the base URL is there for is to resolve relative URL references 
 AFAIK. I will be rather surprised if what you are trying to do is 
 supported. 

 -- 
 Mark Murphy (a Commons Guy) 
 http://commonsware.com | http://github.com/commonsguy 
 http://commonsware.com/blog | http://twitter.com/commonsguy 

 Android Training in DC: http://marakana.com/training/android/ 


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