2012-10-14 58 views
5

我知道我的網絡應用程序的appcache很好用,因爲我已經在Chrome上嘗試過它,即使在Android上的Chrome瀏覽器上也能正常工作,但它不會在從webview中將它加載到我的Android應用中時。我有以下設置:Appcache在Android Webview上不下載代碼

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); 

但加載應用程序時,在logcat的我可以閱讀以下

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

很顯然應用程序緩存沒有工作= /難道我做錯了什麼?謝謝!

+0

這仍然困擾着我,我不能找到一種方法,使這項工作。有什麼建議麼?謝謝:) –

+0

只是猜測:嘗試在'setAppCacheMaxSize(1024 * 1024 * 16)'和'setAppCachePath(appCachePath)'之前調用'setAppCacheEnabled(true)'。此外:您使用的是哪個Android版本? –

+0

@Alberto Elias您是否設法找出緩存不工作的原因?我有完全相同的問題 – turtleboy

回答

0

建立數據庫應用程序緩存和domstore之前, 設置任何「參數」像一套*集之前路徑()/套*尺寸()*啓用()

那旁邊,它可能是不是一個好主意如果您在使用

getActivity()。getApplicationContext()時,堆在兩個彼此獨立管理的高速緩存。getCacheDir()。getAbsolutePath()

爲其中的WebView緩存管理器應存儲其數據的目錄

W如果活動的緩存管理器決定刪除webview的緩存管理器創建的文件,則不會通知webview的緩存管理器,並且可能會進一步依賴它的存在

可能會長時間工作,但有一天它可能會變成交替錯誤這是難以識別

0

這些是爲我工作的設置:

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); 
相關問題