0

Android の PhoneGap アプリケーションは、キャッシュされたファイルを使用しませんでした。ただし、HTML5 アプリケーション キャッシュは有効になっており、イベントを正しくトリガーします。

HTML5 Application Cache を使用する Web サイトがありました。

索引ファイル:

<!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;
}

appcache ファイル:

CACHE MANIFEST
#v1

CACHE:
site.css

Chrome、iOS Web Broswer、iOS の PhoneGap、Android 2.1 Web Broswer でうまく動作します。しかし、Android の PhoneGap では機能しません。

コマンドラインで Android PhoneGap アプリケーションを作成し、起動 URL を自分の Web サイトに変更するだけです。アプリケーションは、アプリケーション キャッシュ イベントを正しくトリガーします。

// 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!イベントは、キャッシュが変更されなかったことを示しています。ただし、アプリケーション キャッシュは使用しません。どうしたの?

4

1 に答える 1

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");
    }
}
于 2013-04-30T16:19:07.973 に答える