5

I know my web app's appcache works nicely because I've tried it on Chrome, even on Chrome for Android it works, but it doesn't when loading it in my Android app from a webview. I have the following settings:

    myWebView = (WebView) v.findViewById(R.id.webView);
    WebSettings webSettings = myWebView.getSettings();
    webSettings.setDomStorageEnabled(true);
    webSettings.setJavaScriptEnabled(true);
    webSettings.setSupportMultipleWindows(true);
    webSettings.setJavaScriptCanOpenWindowsAutomatically(true);
    webSettings.setAppCacheMaxSize(1024*1024*16);
    String appCachePath = getActivity().getApplicationContext().getCacheDir().getAbsolutePath();
    webSettings.setAppCachePath(appCachePath);
    webSettings.setAllowFileAccess(true);
    webSettings.setAppCacheEnabled(true);
    webSettings.setCacheMode(WebSettings.LOAD_DEFAULT);
    webSettings.setDatabaseEnabled(true);
    String databasePath = "/data/data/" + getActivity().getPackageName() + "/databases/";
    webSettings.setDatabasePath(databasePath);
    webSettings.setGeolocationEnabled(true);
    webSettings.setSaveFormData(true);

But when loading the app, in logcat I can read the following

10-15 01:21:43.815: E/SQLiteLog(14278): (1) no such table: CacheGroups 10-15 01:21:43.815: D/WebKit(14278): ERROR: 10-15 01:21:43.815: D/WebKit(14278): Application Cache Storage: failed to execute statement "DELETE FROM CacheGroups" error "no such table: CacheGroups" 10-15 01:21:43.815: D/WebKit(14278): external/webkit/Source/WebCore/loader/appcache/ApplicationCacheStorage.cpp(558) : bool WebCore::ApplicationCacheStorage::executeSQLCommand(const WTF::String&) 10-15 01:21:43.815: E/SQLiteLog(14278): (1) no such table: Caches 10-15 01:21:43.815: D/WebKit(14278): ERROR: 10-15 01:21:43.815: D/WebKit(14278): Application Cache Storage: failed to execute statement "DELETE FROM Caches" error "no such table: Caches" 10-15 01:21:43.815: D/WebKit(14278): external/webkit/Source/WebCore/loader/appcache/ApplicationCacheStorage.cpp(558) : bool WebCore::ApplicationCacheStorage::executeSQLCommand(const WTF::String&) 10-15 01:21:43.815: E/SQLiteLog(14278): (1) no such table: Origins 10-15 01:21:43.815: D/WebKit(14278): ERROR: 10-15 01:21:43.815: D/WebKit(14278): Application Cache Storage: failed to execute statement "DELETE FROM Origins" error "no such table: Origins" 10-15 01:21:43.815: D/WebKit(14278): external/webkit/Source/WebCore/loader/appcache/ApplicationCacheStorage.cpp(558) : bool WebCore::ApplicationCacheStorage::executeSQLCommand(const WTF::String&) 10-15 01:21:43.815: E/SQLiteLog(14278): (1) no such table: DeletedCacheResources

And obviously AppCache isn't working =/ Am I doing anything wrong? Thanks!

Alberto Elias
  • 891
  • 2
  • 8
  • 17
  • This is still bothering me, I just can't find a way to make this work. Any suggestions? Thanks :) – Alberto Elias Nov 04 '12 at 19:08
  • Just guessing: try to call `setAppCacheEnabled(true)` before `setAppCacheMaxSize(1024*1024*16)` and `setAppCachePath(appCachePath)`. Besides: which Android version are you using? – Marvin Emil Brach Nov 30 '12 at 08:15
  • @Alberto Elias Hi did you manage to find out why the cache was not working? i have the exact same problem – turtleboy Feb 13 '13 at 20:10

2 Answers2

0

set up db before appcache and domstore, set any "parameter" like set*Path()/set*Size() before set*Enabled()

beside that, it might be not a good idea if you stack two independently managed caches on each other when using

getActivity().getApplicationContext().getCacheDir().getAbsolutePath()

as the directory where the webview's cache manager should store its data

When the activity's cache manager decides to delete a file that the webview's cache manager has created, the webview's cache manager isn't notified and might further rely on it's existence

might work for long, but someday it might become a alternating bug that is hard to identify

0

These are the settings that work for me:

CookieSyncManager.createInstance(contextForDialog);
webView = (WebView) findViewById(R.id.webView1);

WebSettings settings = webView.getSettings();

settings.setRenderPriority(RenderPriority.HIGH);
settings.setCacheMode(WebSettings.LOAD_DEFAULT);

settings.setSaveFormData(true);
settings.setLoadsImagesAutomatically(true);
settings.setJavaScriptEnabled(true);
settings.setDatabaseEnabled(true);
settings.setDomStorageEnabled(true);
settings.setAppCacheMaxSize(1024*1024*1024*8);
String sDataPath = context.getDir("database", Context.MODE_PRIVATE).getPath();
settings.setDatabasePath(sDataPath);
settings.setAppCachePath(sDataPath);
settings.setAllowFileAccess(true);
settings.setAppCacheEnabled(true);
settings.setAllowFileAccess(true);
settings.setGeolocationEnabled(true);
settings.setSavePassword(true);

webView.setFocusable(true);
webView.setFocusableInTouchMode(true);
settings.setDatabaseEnabled(true);
settings.setAllowContentAccess(true);
settings.setLoadsImagesAutomatically(true);
webView.addJavascriptInterface(this, "AndroidInterface");
WebView.setWebViewClient(new routeNavClient());
webView.setWebChromeClient(new webChromeClient());
CookieManager c = CookieManager.getInstance();
c.setAcceptCookie(true);
Dave S
  • 849
  • 7
  • 7