Mal*_*Lim 6 android caching webview
我已经看到一些应用程序,如海豚浏览器(不是高清版本,正常的)利用缓存到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();
}
}
Run Code Online (Sandbox Code Playgroud)
嗯,该WebSettings对象有很多set...Path()方法。目前尚不清楚其中是否有任何用于实际缓存。还有一个CacheManager对象,它有一堆与缓存相关的静态方法,但没有明显的方法来更改缓存位置。
| 归档时间: |
|
| 查看次数: |
3551 次 |
| 最近记录: |