应用程序缓存在Android设备中不起作用(在Chrome浏览器上运行良好)

jie*_*eun 6 android web-applications application-cache

我正在尝试使用应用缓存来批准性能.

我在不同的网站上受过指导.(例如http://xguru.net/621 ......)

make cache.man文件,将mime-type设置为text/cache-manifest.

问题是......

它在谷歌浏览器浏览器上运行良好,但在我的Android手机中不起作用.

我在ICS和Gingerbread进行了测试.

这是清单文件.

CACHE MANIFEST
# manifest version v0.1 

CACHE:
./programs.png
./video.png

NETWORK:
* 
Run Code Online (Sandbox Code Playgroud)

然后,我像这样设置我的webview.

getSettings().setAppCacheEnabled(true);
getSettings().setDomStorageEnabled(true);
getSettings().setPluginsEnabled(true);
getSettings().setCacheMode(WebSettings.LOAD_DEFAULT);
Run Code Online (Sandbox Code Playgroud)

(我将cacheMode更改为LOAD_NORMAL,NO_CACHE,但它没有区别.)

要查看缓存状态,我使用此站点. http://jonathanstark.com/blog/2009/09/27/debugging-html-5-offline-application-cache/

var cacheStatusValues = [];
cacheStatusValues[0] = 'uncached';
cacheStatusValues[1] = 'idle';
cacheStatusValues[2] = 'checking';
cacheStatusValues[3] = 'downloading';
cacheStatusValues[4] = 'updateready';
cacheStatusValues[5] = 'obsolete';

var cache = window.applicationCache;
cache.addEventListener('cached', logEvent, false);
cache.addEventListener('checking', logEvent, false);
cache.addEventListener('downloading', logEvent, false);
cache.addEventListener('error', logEvent, false);
cache.addEventListener('noupdate', logEvent, false);
cache.addEventListener('obsolete', logEvent, false);
cache.addEventListener('progress', logEvent, false);
cache.addEventListener('updateready', logEvent, false);

function logEvent(e) {
    var online, status, type, message;
    online = (navigator.onLine) ? 'yes' : 'no';
    status = cacheStatusValues[cache.status];
    type = e.type;
    message = 'online: ' + online;
    message+= ', event: ' + type;
    message+= ', status: ' + status;
    if (type == 'error' && navigator.onLine) {
        message+= ' (prolly a syntax error in manifest)';
    }
    console.log(message);
}

window.applicationCache.addEventListener(
    'updateready',
    function(){
        window.applicationCache.swapCache();
        console.log('swap cache has been called');
    },
    false
);
Run Code Online (Sandbox Code Playgroud)

最后,这是我在Android手机上看到的日志.

[cache Resource] app cache support! 
[cache Resource] DOWNLOADING 
[cache Resource] event online: yes, event: checking, status: uncached 
[cache Resource] event online: yes, event: downloading, status: uncached 
[cache Resource] event online: yes, event: progress, status: uncached 
[cache Resource] event online: yes, event: progress, status: uncached 
[cache Resource] event online: yes, event: error, status: uncached (prolly a syntax error in manifest) 
Run Code Online (Sandbox Code Playgroud)

图像已下载但我们在最后一行收到错误.所以它始终处于未缓存状态.

我想问题出在webview设置或android应用程序上.但我无法处理它.

给我一个使用app缓存的提示.. plz ...

Mar*_*ach 2

yugidroid 间接链接的答案引导我找到了正确的路线。答案中链接的博客显示了该怎么做:

    String appCachePath = getApplicationContext().getCacheDir().getAbsolutePath();
    webView.getSettings().setAppCachePath(appCachePath);
Run Code Online (Sandbox Code Playgroud)

我再次删除这些行进行测试:同样的错误 - 阅读:没有错误!