2012-07-12 7 views
6

Tôi đang cố gắng sử dụng bộ nhớ cache của ứng dụng để phê duyệt hiệu suất.bộ nhớ cache ứng dụng không hoạt động trên thiết bị Android (hoạt động tốt trên trình duyệt chrome)

Tôi đã được hướng dẫn ở các trang web khác nhau. (ví dụ: http://xguru.net/621 ...)

tạo tệp cache.man, đặt loại mime là văn bản/bộ nhớ cache-tệp kê khai.

Sự cố là ...

nó hoạt động tốt trên trình duyệt Chrome của Google, nhưng không hoạt động trong điện thoại Android của tôi.

Tôi đã thử nghiệm tại ICS và Gingerbread.

Đây là tệp kê khai.

CACHE MANIFEST 
# manifest version v0.1 

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

NETWORK: 
* 

và sau đó, tôi đặt chế độ xem web của tôi như thế này.

getSettings().setAppCacheEnabled(true); 
getSettings().setDomStorageEnabled(true); 
getSettings().setPluginsEnabled(true); 
getSettings().setCacheMode(WebSettings.LOAD_DEFAULT); 

(Tôi đã thay đổi cacheMode để LOAD_NORMAL, NO_CACHE, nhưng nó không phải là khác nhau.)

Để xem tình trạng bộ nhớ cache, tôi sử dụng trang web này. 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 
); 

Cuối cùng, Đây là nhật ký tôi nhìn thấy trên điện thoại Android của mình.

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

Hình ảnh được tải xuống nhưng chúng tôi gặp lỗi ở dòng cuối cùng. Vì vậy, nó luôn luôn trong một uncached.

Tôi đoán sự cố xảy ra trên cài đặt webview hoặc ứng dụng android. Nhưng tôi không thể xử lý nó.

cho tôi một lời khuyên để sử dụng bộ nhớ cache ứng dụng .. plz ...

+0

có cùng lỗi ... đã xóa tất cả các mục trong tệp kê khai, do đó, nó sẽ chỉ lưu vào bộ nhớ cache trang chính: kiểm tra, tải xuống, lỗi. –

Trả lời

2

gián tiếp câu trả lời được liên kết bởi yugidroid dẫn tôi vào dòng ngay. Blog được liên kết trong câu trả lời cho thấy những việc cần làm:

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

Tôi đã gỡ bỏ những dòng nữa để thử nghiệm: cùng một lỗi - readded: không có lỗi!