簡體   English   中英

應用程序緩存在Android設備中不起作用(在Chrome瀏覽器上運行良好)

[英]app cache doesn't work in the android device (works well on the chrome browser)

我正在嘗試使用應用緩存來批准性能。

我在不同的網站上受過指導。 (例如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:
* 

然后,我像這樣設置我的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
);

最后,這是我在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) 

圖像已下載但我們在最后一行收到錯誤。 所以它始終處於未緩存狀態。

我想問題出在webview設置或android應用程序上。 但我無法處理它。

給我一個使用app緩存的提示.. plz ...

間接地,由yugidroid鏈接的答案導致我走向正確的路線。 答案中鏈接的博客顯示了該做什么:

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

我再次刪除這些行進行測試:同樣的錯誤 - 讀取:沒有錯誤!

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM