java - 关于android的webview的缓存设置
迷茫
迷茫 2017-04-18 10:33:33
0
1
361
File sdcache = getExternalCacheDir(); WebSettings webSettings = webview.getSettings(); webSettings.setJavaScriptEnabled(true); webSettings.setAllowFileAccess(true); webSettings.setAppCachePath(sdcache.toString()); webSettings.setAppCacheEnabled(true); webSettings.setAppCacheMaxSize(1024*1024*10); webSettings.setCacheMode(WebSettings.LOAD_CACHE_ONLY); webview.setWebViewClient(new WebViewClient(){ @Override public boolean shouldOverrideUrlLoading(WebView view, String url) { // TODO Auto-generated method stub return super.shouldOverrideUrlLoading(view, url); } @Override public void onPageFinished(WebView view, String url) { // TODO Auto-generated method stub super.onPageFinished(view, url); } @Override public void onReceivedSslError(WebView view, SslErrorHandler handler, SslError error) { // TODO Auto-generated method stub //super.onReceivedSslError(view, handler, error); } });

代码如上面写的 设置了缓存的路径SD卡的(manifest中配置了权限) 路径为:/storage/sdcard0/Android/data/com.example.webviewtest/cache 服务端用的是html5的application cache 那个玩意 在配置了 当我把缓存模式设置成使用本地缓存的时候 网页就加载不错来 报错net::ERR_CAHCE_MISS应该是网页没有被缓存到本地吧 去对应的路径下找也没有缓存的东西 ,请问这是什么情况啊

迷茫
迷茫

业精于勤,荒于嬉;行成于思,毁于随。

reply all (1)
左手右手慢动作

The problem is here

webSettings.setAppCachePath(sdcache.toString());

toString()是什么?文件路径可不是这么取啊!
sdcache.getAbsolutePath()That’s right!

    Latest Downloads
    More>
    Web Effects
    Website Source Code
    Website Materials
    Front End Template
    About us Disclaimer Sitemap
    php.cn:Public welfare online PHP training,Help PHP learners grow quickly!