【问题标题】:app cache doesn't work in the android device (works well on the chrome browser)应用程序缓存在 android 设备中不起作用(在 chrome 浏览器上运行良好)
【发布时间】:2012-07-11 19:12:29
【问题描述】:

我正在尝试使用应用缓存来验证性能。

我在不同的网站上得到了指导。 (例如http://xguru.net/621 ...)

制作 cache.man 文件,设置 mime-type 为 text/cache-manifest。

问题是……

它在谷歌 chrome 浏览器上运行良好,但在我的安卓手机上不运行。

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

(我把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
);

最后,这是我在安卓手机上看到的日志。

[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 应用程序上。 但我无法处理它。

给我一​​个使用应用缓存的提示..请...

【问题讨论】:

  • 遇到了同样的失败...删除了清单中的所有条目,因此它应该只缓存母版页:检查、下载、错误。

标签: android web-applications application-cache


【解决方案1】:

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

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

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-02-01
    • 2019-07-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多