0

The PhoneGap application in Android didn't use the cached file. But the HTML5 Application Cache is enabled and trigger event correctly.

I had a website use HTML5 Application Cache:

index file:

<!DOCTYPE html>
<html manifest="cache.appcache">
<head>
    <link rel="stylesheet" type="text/css" href="site.css">
</head>
<body>
    <div>
        Hello World
    </div>
</body>
</html>

css file:

div{
    background-color: red;
}

appcache file:

CACHE MANIFEST
#v1

CACHE:
site.css

It works well in Chrome, iOS Web Broswer, PhoneGap in iOS, Android 2.1 Web Broswer. But it doesn't work in PhoneGap in Android!

I created the Android PhoneGap Application with command line,and just modify the startup url to my website. The Application will trigger the application cache event correctly:

// Fired after the first cache of the manifest.
appCache.addEventListener('cached', handleCacheEvent, false);

// Checking for an update. Always the first event fired in the sequence.
appCache.addEventListener('checking', handleCacheEvent, false);

// An update was found. The browser is fetching resources.
appCache.addEventListener('downloading', handleCacheEvent, false);

I didn't modify the cache.appcache file! And the event shows that the cache didn't modify. But it doesn't use the application cache. What's wrong with it?

Dozer
  • 5,025
  • 11
  • 36
  • 52

1 Answers1

0

the PhoneGap release note for 2.5 tell us the it supported the application cache,and fixed the problem.(in the old version you need to write some code and enable the application cache)

I use the PhoneGap 2.6, the application cache didn't work, but when I writen some code to enable it,it works well.

code like this:

public class HelloWorld extends DroidGap {
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // Set by <content src="index.html" /> in config.xml

        super.init();
        android.webkit.WebSettings settings = super.appView.getSettings();
        String appCachePath = this.getCacheDir().getAbsolutePath();
        settings.setAppCachePath(appCachePath);
        settings.setAllowFileAccess(true);
        settings.setAppCacheEnabled(true);

        // super.loadUrl(Config.getStartUrl());
        super.loadUrl("http://192.168.0.104:8080/cache/index.html");
    }
}
Dozer
  • 5,025
  • 11
  • 36
  • 52