Html5 cache problems with android webview

感情迁移 提交于 2020-01-06 05:43:24

问题


Hello I tried to cache my web application with my android device. I tried everything but nothing will work. The Cache will not refresh only on android devices and not on other devices! Below you see all the settings I've set to cache the web application.

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    web = (WebView) findViewById(R.id.webview);
    web.setWebViewClient(new myWebClient());
    web.getSettings().setJavaScriptEnabled(true);

    web.getSettings().setCacheMode(web.getSettings().LOAD_NORMAL);
    web.setScrollBarStyle(WebView.SCROLLBARS_OUTSIDE_OVERLAY);
    web.getSettings().setUserAgentString(getString(R.string.user_agent_suffix));   


    web.getSettings().setAppCachePath("http://192.168.0.62/lastversion/cache.manifest");
    web.getSettings().setAllowFileAccess(true);
    web.getSettings().setAppCacheEnabled(true);
    web.getSettings().setDomStorageEnabled(true);
    web.loadUrl("http://192.168.0.62/lastversion/");

}

here I set my cache:

<html manifest="cache.manifest">

I hope someone can help me. Thanks


回答1:


web.getSettings().setAppCachePath() set's the local directory where to store the cached files not where to load the manifest from.

The manifest has to be referenced in the HTML file you want to cache:

    <html manifest="cache.manifest">

What do you mean with: "Cache will not refresh only on android devices and not on other devices!" The cached files only will be updated if the content of the manifest has changed.
http://appcachefacts.info/
http://jonathanstark.com/blog/2009/09/27/debugging-html-5-offline-application-cache/
http://dev.opera.com/articles/view/offline-applications-html5-appcache/



来源:https://stackoverflow.com/questions/10800224/html5-cache-problems-with-android-webview

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!