【问题标题】:The PhoneGap app in Android didn't use the HTML5 Application CacheAndroid 中的 PhoneGap 应用程序没有使用 HTML5 应用程序缓存
【发布时间】:2013-04-30 08:05:39
【问题描述】:

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 应用程序,只需将启动 url 修改为我的网站。 Application会正确触发应用缓存事件:

// 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 文件!并且事件显示缓存没有修改。 但它不使用应用程序缓存。 它有什么问题?

【问题讨论】:

    标签: html cordova mobile application-cache


    【解决方案1】:

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

    我使用的是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");
        }
    }
    

    【讨论】:

      猜你喜欢
      • 2012-09-24
      • 2017-08-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-01-31
      • 2013-09-18
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多