2013-02-15 65 views
1

我使用Phonegap在Android中使用缓存的经验。Android使用缓存和Phonegap的离线和在线应用程序

1. I want to create one app which should work online as well as offline. 
    2. If internet connectivity is there it should use otherwise use the history. 

现在它与在线..但我需要在离线工作我的应用程序。用于检查网络连接:

function onDeviceReady() { 
    navigator.network.isReachable("phonegap.com", reachableCallback, {}); 
    navigator.notification.alert("Server Is Ready"); 


} 

     // Check network status 
// 
function reachableCallback(reachability) { 
    // There is no consistency on the format of reachability 
    var networkState = reachability.code || reachability; 
    var states = {}; 
    states[NetworkStatus.NOT_REACHABLE] = 'No network connection'; 
    states[NetworkStatus.REACHABLE_VIA_CARRIER_DATA_NETWORK] = 'Carrier data connection'; 
    states[NetworkStatus.REACHABLE_VIA_WIFI_NETWORK] = 'WiFi connection'; 

    alert('Connection type: ' + states[networkState]); 
    } 

任何一个可以帮助我来访问我的我的应用程序,而没有任何nwtwork连接(离线)

回答

3

使用此:中 <html manifest="cache.manifest">代替<html>

并在名为cache.manifest的同一目录中创建一个新文件。

该文件的内容应该是这样的

CACHE MANIFEST 的index.html blabla.png

+0

确定。但是我没有清楚这句话:“该文件的内容应该如下所示:CACHE MANIFEST ##必需的第一行index.html blabla.png” – sherin 2013-02-15 09:42:31

+2

“cache.manifest”的内容必须采用指定的格式。第一个必须是'CACHE MANUFEST',其他行需要是你想要缓存的文件的名称。 – VladHQ 2013-02-15 09:44:37

+1

新行应该是这样的:'CACHE MANIFEST \ newline \ file.html \ new line \ etc.html' – VladHQ 2013-02-15 09:46:58