在Android设备上达到并包括4.4.2,默认浏览器和Chrome支持HTML5缓存清单。但是,在这些相同的设备上,WebView组件似乎不支持HTML5缓存清单。有人知道我怎样才能让WebView组件支持HTML5清单吗?如何让webview使用HTML5缓存清单?
25
A
回答
0
试试这个代码:
private void enableHTML5AppCache() {
webView.getSettings().setDomStorageEnabled(true);
// Set cache size to 8 mb by default. should be more than enough
webView.getSettings().setAppCacheMaxSize(1024*1024*8);
// This next one is crazy. It's the DEFAULT location for your app's cache
// But it didn't work for me without this line
webView.getSettings().setAppCachePath("/data/data/"+ getPackageName() +"/cache");
webView.getSettings().setAllowFileAccess(true);
webView.getSettings().setAppCacheEnabled(true);
webView.getSettings().setCacheMode(WebSettings.LOAD_DEFAULT);
}
Here的链接。
0
@Override
public void onReceivedError(WebView view, int errorCode,
String description, String failingUrl)
{
// The magic redirect
if("http://HTML5app.com/app/".equals(failingUrl)) {
// main.html is the place we are redirected to by the server if we are online
mWebView.loadUrl("http://HTML5app.com/app/main.html");
return;
}
else if("http://HTML5app.com/app/main.html".equals(failingUrl)) {
// The cache failed - We don't have an offline version to show
// This code removes the ugly android's "can't open page"
// and simply shows a dialog stating we have no network
view.loadData("", "text/html", "UTF-8");
showDialog(DIALOG_NONETWORK);
}
}
以上方法将被用来处理在离线情况下重定向。 [为了实现appcache和路径,请参阅之前的评论。
1
webView.getSettings().setDomStorageEnabled(true);
// Set cache size to 8 mb by default. should be more than enough
webView.getSettings().setAppCacheMaxSize(1024*1024*8);
// This next one is crazy. It's the DEFAULT location for your app's cache
// But it didn't work for me without this line
webView.getSettings().setAppCachePath("/data/data/"+ getPackageName() +"/cache");
webView.getSettings().setAllowFileAccess(true);
webView.getSettings().setAppCacheEnabled(true);
webView.getSettings().setCacheMode(WebSettings.LOAD_DEFAULT);
相关问题
- 1. HTML5缓存清单
- 2. HTML5缓存清单缓存一切
- 3. HTML5缓存清单异常
- 4. iPhone和HTML5缓存清单
- 5. html5缓存清单设置
- 6. HTML5清单缓存问题
- 7. 如何使用CakePHP使用html5缓存清单?
- 8. HTML5应用程序清单不清除缓存清单更改
- 9. 如何清除UWP WebView缓存?
- 10. 如何为WebView清空缓存?
- 11. 我的HTML5应用程序缓存清单是缓存一切
- 12. html5缓存清单与head.js兼容吗?
- 13. 移动Safari中的HTML5缓存清单
- 14. HTML5缓存清单和预取
- 15. HTML5缓存清单和内容类型
- 16. HTML5缓存清单后退页面
- 17. HTML5缓存(清单)网络部分
- 18. HTML5缓存清单未上传
- 19. WebView缓存清除问题
- 20. 清除WebView缓存xamarin IOS
- 21. 如何使用JavaScript清除应用程序缓存(HTML5功能)?
- 22. Ttitanium webview和HTML5应用程序缓存
- 23. 使用HTML5缓存清单缓存.aspx页面时出现404错误
- 24. Android可以缓存缓存清单HTML5视频离线吗?
- 25. HTML5缓存清单工程通过HTTP但没有使用https
- 26. 使用HTML5缓存清单来提高性能?
- 27. 缓存清单uncache
- 28. 如何清除UIWebView的HTML5应用程序缓存
- 29. HTML5应用程序缓存:如何从定义清单的缓存中排除HTM文件
- 30. 当浏览器清除缓存时清除HTML5 Web存储?
我发现结果在这里:http://alex.tapmania.org/?p=110 – 2011-01-09 19:47:42
可能是最不直观的方面我好像从发布解决方案您必须手动设置WebView的appCachePath,否则它将无法工作。你不会知道为什么它不起作用。它不会。 – KevinH 2012-02-27 16:43:07