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"/>