Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/189.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 使用loadDataWithBaseUrl()时如何设置缓存WebView?_Android - Fatal编程技术网

Android 使用loadDataWithBaseUrl()时如何设置缓存WebView?

Android 使用loadDataWithBaseUrl()时如何设置缓存WebView?,android,Android,舱单包括: final ConnectivityManager cm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE); final NetworkInfo active = cm.getActiveNetworkInfo(); if (active != null && active.isConnected()) { String appCache

舱单包括:

    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", ""); }

但当我脱机打开webview时,webview返回Null。请帮帮我

请参阅本文,以了解我认为涵盖您正在尝试执行的操作的扩展讨论。

支持的链接已断开
<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"/>