1
    final ConnectivityManager cm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
    final NetworkInfo active = cm.getActiveNetworkInfo();
    if (active != null && active.isConnected()) {
        String appCachePath = getApplicationContext().getCacheDir()
                .getAbsolutePath();
        webview.getSettings().setAppCachePath(appCachePath);
        webview.getSettings().setCacheMode(
                WebSettings.LOAD_DEFAULT);
        webview.getSettings().setAppCacheMaxSize(1024 * 0124 * 8);
        webview.loadDataWithBaseURL("", "<html><head><title>Cache Test</title></head><body><p>This is Icon</p><br/><img src='http://google.com.us/images/icons/product/chrome-48.png'></body></html>", "text/html", "UTF-8", "");
    } else {
        webview.getSettings().setCacheMode(WebSettings.LOAD_CACHE_ONLY);
        webview.loadDataWithBaseURL("", "<html><head><title>Cache Test</title></head><body><p>This is Icon</p><br/><img src='http://google.com.us/images/icons/product/chrome-48.png'></body></html>", "text/html", "UTF-8", ""); }

清单有:

<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>

但是当我离线打开 webview 时,webview 返回“Null”。请帮我!

4

1 回答 1

0

请参阅此http://alex.tapmania.org/2010/11/html5-cache-android-webview.html进行扩展讨论,我认为该讨论涵盖了您正在尝试做的事情。

于 2013-03-09T11:22:15.353 回答