webview没有缓存在galaxy grand 2上

时间:2014-05-17 19:02:42

标签: android caching webview offline-caching

实际上我正在制作一个需要缓存网站页面的程序,如果没有连接,它应该离线打开缓存页面,它在我的galaxy s4上工作正常,但在galaxy grand 2上页面是未加载,而是加载默认错误页面 这是我的代码,并提前感谢您的帮助。

protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);
    setContentView(R.layout.exchange_app);
    b= (Button)findViewById(R.id.button1);
    tv = (EditText)findViewById(R.id.editText2);
    webView=(WebView) findViewById(R.id.webView1);
    imageView= (ImageView)findViewById(R.id.imageView1);
    webView.getSettings().setJavaScriptEnabled(true);

    webView.setWebChromeClient(new WebChromeClient() {
          @Override
          public void onReachedMaxAppCacheSize(long spaceNeeded, long totalUsedQuota,
                       WebStorage.QuotaUpdater quotaUpdater)
          {
                quotaUpdater.updateQuota(spaceNeeded * 2);
          }
    });

    webView.getSettings().setDomStorageEnabled(true);
    // webView.getSettings().setAllowFileAccessFromFileURLs(true);
//   webView.getSettings().setAllowUniversalAccessFromFileURLs(true);
//   webView.getSettings().LOAD_CACHE_ELSE_NETWORK
    // 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.
    // UPDATE: no hardcoded path. Thanks to Kevin Hawkins
    String appCachePath = getApplicationContext().getCacheDir().getAbsolutePath();
    webView.getSettings().setAppCachePath(appCachePath);
    webView.getSettings().setAllowFileAccess(true);
    webView.getSettings().setAppCacheEnabled(true);
    webView.getSettings().setCacheMode(WebSettings.LOAD_DEFAULT);
    webView.loadUrl("http://www.syria-stocks.us/dollarrange/test3.php");

    //readWebpage(tv);

 webView.setWebViewClient(new WebViewClient() {

        @Override
        public void onPageFinished(WebView view, String url) {
            webView.setVisibility(WebView.VISIBLE);
            super.onPageFinished(view, url);


        }

        @Override
        public void onReceivedError(WebView view, int errorCode,
                String description, String failingUrl) {
            // TODO Auto-generated method stub
            webView.setVisibility(WebView.INVISIBLE);
            super.onReceivedError(view, errorCode, description, failingUrl);
            if (webView.getSettings().getCacheMode()!=WebSettings.LOAD_CACHE_ONLY){
                webView.getSettings().setCacheMode( WebSettings.LOAD_CACHE_ONLY );
             webView.loadUrl("http://www.syria-stocks.us/dollarrange/test3.php");
    Toast.makeText(getApplicationContext(), "no connection", Toast.LENGTH_SHORT).show();

        }
        }

         });

目录下载:

05-17 21:37:51.594: D/WebView(29190): onSizeChanged - w:720 h:556
05-17 21:37:53.934: V/WebViewInputDispatcher(29190): blockWebkitDraw
05-17 21:37:53.934: V/WebViewInputDispatcher(29190): blockWebkitDraw lockedfalse
05-17 21:37:54.234: D/webview(29190): blockWebkitViewMessage= false
05-17 21:37:54.704: V/WebViewInputDispatcher(29190): blockWebkitDraw
05-17 21:37:54.704: V/WebViewInputDispatcher(29190): blockWebkitDraw lockedfalse
05-17 21:37:55.004: D/webview(29190): blockWebkitViewMessage= false
05-17 21:38:05.414: I/webclipboard(29190): clipservice:      android.sec.clipboard.ClipboardExManager@426b2cf0
05-17 21:38:05.414: V/webkit(29190): BrowserFrame constructor: this=Handler    (android.webkit.BrowserFrame) {426b9528}
05-17 21:38:05.424: D/WebView(29190): loadUrlImpl: called
05-17 21:38:05.424: D/webcore(29190):  CORE loadUrl: called
05-17 21:38:05.424: D/webkit(29190): Firewall not null
05-17 21:38:05.424: D/webkit(29190): euler: isUrlBlocked = false
05-17 21:38:05.424: I/GATE(29190): <GATE-M>DEV_ACTION_ERROR</GATE-M>
05-17 21:38:05.434: V/webkit(29190): reportError errorCode(-2) desc(Couldn't find the URL.)

0 个答案:

没有答案