2012-07-12 10 views
6

Sto tentando di utilizzare la cache delle app per approvare le prestazioni.non funziona nel dispositivo Android (funziona bene con il browser Chrome)

Sono stato guidato in vari siti. (ad esempio http://xguru.net/621 ...)

creare il file cache.man, impostare mime-type come text/cache-manifest.

problema è ...

funziona bene al browser Chrome di Google, ma non funziona nel mio telefono Android.

Ho eseguito il test su ICS e Gingerbread.

Questo è il file manifest.

CACHE MANIFEST 
# manifest version v0.1 

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

NETWORK: 
* 

e quindi ho impostato la mia webview in questo modo.

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

(ho cambiato il CacheMode a LOAD_NORMAL, NO_CACHE, ma non è diverso.)

per vedere lo stato della cache, io uso questo sito. 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 
); 

Infine, questo è il log che vedo sul mio telefono 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) 

Le immagini vengono scaricate ma viene visualizzato l'errore nell'ultima riga. Quindi è sempre in un uncached.

Immagino che il problema sia nell'impostazione webview o nell'applicazione Android. Ma non posso gestirlo.

darmi un suggerimento per utilizzare la cache app .. plz ...

+0

ha ottenuto lo stesso errore ... ha rimosso tutte le voci nel manifest in modo che dovrebbe solo memorizzare nella cache la pagina master: controllo, download, errore. –

risposta

2

Indirettamente la risposta legati da yugidroid mi ha portato alla linea giusta. Il blog che è legata nella risposta indica cosa fare:

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

ho rimosso quelle linee ancora per il test: lo stesso errore - readded: nessun errore!

Problemi correlati