作者热门文章
- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
我见过一些应用程序,如海豚浏览器(不是高清版,普通版)使用缓存到 sd 的 web View ,但我似乎无法弄清楚如何做到这一点,有谁知道如何这样做还是给我指明正确的方向?任何帮助是极大的赞赏!谢谢:)
最佳答案
这篇文章详细描述了如何将 webview 缓存存储更改为使用 sd 卡: http://www.devahead.com/blog/2012/01/saving-the-android-webview-cache-on-the-sd-card/
我已经在我的应用程序中对其进行了测试,并证明它可以工作。
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();
}
}
关于android - 如何将 webView 缓存移动到 SD?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3389002/
我是一名优秀的程序员,十分优秀!