我已经看到一些应用程序,如海豚浏览器(不是高清版本,正常的)利用缓存到SD的webview但我似乎无法弄清楚如何做到这一点,有谁知道如何做到这一点或指出我正确的方向?任何帮助是极大的赞赏!谢谢 :)
这篇文章详细描述了如何更改webview缓存存储以使用SD卡:http: //www.devahead.com/blog/2012/01/saving-the-android-webview-cache-on-the-sd-卡/
我已经在我的应用程序中对它进行了测试,并且它已被证明有效.
public class MainApplication extends Application { // ... @Override public File getCacheDir() { // NOTE: this method is used in Android 2.2 and higher File cachePath = this.getExternalCachePath(); return cachePath != null ? cachePath : super.getCacheDir(); } private File getExternalCachePath() { if (Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState())) { File externalStorageDir = Environment.getExternalStorageDirectory(); // {SD_PATH}/Android/data/com.package.name/cache File extStorageAppCachePath = new File(externalStorageDir, "Android" + File.separator + "data" + File.separator + this.getPackageName() + File.separator + "cache"); return extStorageAppCachePath; } return null; } } public class SomeWebViewActivity extends Activity { // ... @Override public File getCacheDir() { // Android 2.1 and lower return this.getApplicationContext().getCacheDir(); } }