HTML5 application cache does not work in Android PhoneGap application

I am trying to use the application cache in HTML5 for the Android PhoneGap application, but this does not work, it does not feel when using ApplicationCahce events.

function logEvent(event) { console.log(event.type); } window.applicationCache.addEventListener('checking', logEvent, false); window.applicationCache.addEventListener('noupdate', logEvent, false); window.applicationCache.addEventListener('downloading', logEvent, false); window.applicationCache.addEventListener('progress', logEvent, false); window.applicationCache.addEventListener('cached', logEvent, false); window.applicationCache.addEventListener('updateready', logEvent, false); window.applicationCache.addEventListener('obsolete', logEvent, false); window.applicationCache.addEventListener('error', logEvent, false); 

In addition, this code runs on iOS PhoneGap and Android Browser and this link is for supported platforms. Cahce App Supported Platforms

So any suggestion would be helpful.

+1
source share
3 answers

I believe that the application cache is not included in the WebView by default. What you will need to do is in the Java class, which extends the DroidGap call:

 this.appView.getSettings().setAppCacheEnabled(true); 

in the onCreate () method.

You may also need to call:

 this.appView.getSettings().setAppCacheMaxSize(sizeInBytes); this.appView.getSettings().setAppCachePath(pathToCacheDir); 

Note that the cache directory must exist before calling setAppCachePath ().

Read on ...

http://developer.android.com/reference/android/webkit/WebSettings.html#setAppCacheEnabled(boolean ) http://developer.android.com/reference/android/webkit/WebSettings.html#setAppCacheMaxSize(long ) http: //developer.android.com/reference/android/webkit/WebSettings.html#setAppCachePath(java.lang.String )

+6
source

For pathToCacheDir use:

 String pathToCacheDir = this.getApplicationContext().getCacheDir().getAbsolutePath() 
+1
source

Have you set the correct mime type? First I use '.txt', for example thie:

 <!DOCTYPE html> <html manifest="cache.txt"> <head> 

It works great in iOS, Chrome, but it doesn't work in Android!

When I set the correct mime type, it works well ~

In tomcat, the default extension was ".appcache", and the default mime type was:

 <mime-mapping> <extension>appcache</extension> <mime-type>text/cache-manifest</mime-type> </mime-mapping> 
+1
source

All Articles