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」を返します。私を助けてください!