安卓设备上应用缓存无法正常工作(在谷歌浏览器上可以正常工作)

6
我正在尝试使用应用程序缓存来提高性能。
我在各种网站上得到了指导。(例如:http://xguru.net/621 ...)
制作cache.man文件,将mime类型设置为text/cache-manifest。
问题是...
它在Google Chrome浏览器中运行良好,但在我的Android手机上无法运行。
我在ICS和Gingerbread上进行了测试。
这是清单文件。
CACHE MANIFEST
# manifest version v0.1 

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

NETWORK:
* 

然后,我这样设置我的 Webview。
getSettings().setAppCacheEnabled(true);
getSettings().setDomStorageEnabled(true);
getSettings().setPluginsEnabled(true);
getSettings().setCacheMode(WebSettings.LOAD_DEFAULT);

我将缓存模式改为了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
);

最后,这是我在我的安卓手机上看到的日志。
[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) 

图片已下载,但在最后一行遇到错误。因此它总是未缓存状态。
我猜问题出现在webview设置或Android应用程序上。但我无法处理它。
请给我一个提示如何使用应用程序缓存...谢谢...

出现了相同的故障...已删除清单中的所有条目,因此应该只缓存主页面:正在检查、下载、出错。 - Marvin Emil Brach
1个回答

2

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

    String appCachePath = getApplicationContext().getCacheDir().getAbsolutePath();
    webView.getSettings().setAppCachePath(appCachePath);

我为了测试又移除了那些行:同样的错误 - 再次添加:没有错误!


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接