Application cache in HTML5 doesn't work in Android PhoneGap application

后端 未结 3 2034
悲&欢浪女
悲&欢浪女 2020-12-18 17:38

I\'m trying to use application cache in HTML5 for Android PhoneGap Application, but this doesn\'t work, it doesn\'t feel with ApplicationCahce Events.

functi         


        
相关标签:
3条回答
  • 2020-12-18 17:44

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

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

    in your onCreate() method.

    You may also need to call:

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

    Please note the cache directory must exist before you call setAppCachePath().

    Read up 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)

    0 讨论(0)
  • 2020-12-18 17:52

    For pathToCacheDir, use:

    String pathToCacheDir = this.getApplicationContext().getCacheDir().getAbsolutePath()
    
    0 讨论(0)
  • 2020-12-18 17:53

    did you set the correct mime-type? At first I use the '.txt' like thie:

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

    It works well in iOS, Chrome but 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>
    
    0 讨论(0)
提交回复
热议问题