2013-04-30 92 views
0

Android中的PhoneGap应用程序未使用缓存文件。 但HTML5应用程序缓存已启用并正确触发事件。Android中的PhoneGap应用程序未使用HTML5应用程序缓存

我做了一个网站使用HTML5应用程序缓存:

索引文件:

<!DOCTYPE html> 
<html manifest="cache.appcache"> 
<head> 
    <link rel="stylesheet" type="text/css" href="site.css"> 
</head> 
<body> 
    <div> 
     Hello World 
    </div> 
</body> 
</html> 

css文件:

div{ 
    background-color: red; 
} 

应用程序缓存文件:

CACHE MANIFEST 
#v1 

CACHE: 
site.css 

它运作良好在Chrome,iOS Web上Broswer,iOS中的PhoneGap,Android 2.1 Web Broswer。 但它在Android的PhoneGap中无法使用!

我使用命令行创建了Android PhoneGap应用程序,只是将启动网址修改为我的网站。 应用程序将正确地触发应用程序缓存事件:

// Fired after the first cache of the manifest. 
appCache.addEventListener('cached', handleCacheEvent, false); 

// Checking for an update. Always the first event fired in the sequence. 
appCache.addEventListener('checking', handleCacheEvent, false); 

// An update was found. The browser is fetching resources. 
appCache.addEventListener('downloading', handleCacheEvent, false); 

我并没有修改cache.appcache文件!事件表明缓存没有修改。 但它不使用应用程序缓存。 它有什么问题?

回答

0

2.5的PhoneGap的发布说明告诉我们,它支持应用程序缓存,并解决了问题。(在旧版本中,你需要编写一些代码,使应用程序缓存)

我使用的PhoneGap 2.6 ,应用程序缓存不起作用,但是当我编写一些代码来启用它时,它运行良好。

这样的代码:

public class HelloWorld extends DroidGap { 
    @Override 
    public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     // Set by <content src="index.html" /> in config.xml 

     super.init(); 
     android.webkit.WebSettings settings = super.appView.getSettings(); 
     String appCachePath = this.getCacheDir().getAbsolutePath(); 
     settings.setAppCachePath(appCachePath); 
     settings.setAllowFileAccess(true); 
     settings.setAppCacheEnabled(true); 

     // super.loadUrl(Config.getStartUrl()); 
     super.loadUrl("http://192.168.0.104:8080/cache/index.html"); 
    } 
} 
相关问题