Сохранение файлов внешнего кэша

Я пытаюсь сохранить кэшированные файлы webView в каталог на SD-карте. Я использую HTML5 и файл кэш-манифеста на сервере. Я установил внешний каталог на SD-карту с помощью метода setAppCachePath, но кеш загружается в каталог приложений по умолчанию «data/data/myApp/cache/webiewCache», а не в каталог, который я установил с помощью метода setAppCachePath. Внешний каталог существует, но данные в него не попадают. Любые идеи или предложения? Ниже приведены методы, которые я реализую.

Спасибо за помощь.

public class DocumentView extends Activity {
/**
 * -- Called when the activity is first created.
 * ================================================
 **/
@Override
public void onCreate(final Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    String t = getIntent().getStringExtra("TITLE");
    activityTitle.setText(t);

    String l = getIntent().getStringExtra("LABEL");
    CreateCacheDirectory();

    String lbl = getIntent().getStringExtra("TITLE");
    pd = ProgressDialog.show(this, "" + lbl, "Retrieving data from server",
            true);

    // -- Set up the WebView ==========================================
    final String url = getIntent().getStringExtra("url");// get url that
                                                            // passed from
                                                            // previous
                                                            // Activity
    mWebView = (WebView) findViewById(R.id.webView1);
    mWebView.getSettings().setDomStorageEnabled(true);

    // Set cache size to 8 mb by default. should be more than enough
    mWebView.getSettings().setAppCacheMaxSize(1024 * 1024 * 8);
    // The DEFAULT location for the cache
    mWebView.getSettings().setAppCachePath(
            extStorageDirectory + "/myCo/myApp/cache/" + l);
    // Cache settings
    mWebView.getSettings().setAllowFileAccess(true);
    mWebView.getSettings().setAppCacheEnabled(true);
    mWebView.getSettings()
            .setCacheMode(WebSettings.LOAD_CACHE_ELSE_NETWORK);
    // Misc webView settings
    mWebView.getSettings().setJavaScriptEnabled(true);

    // Check to see if there is a saved state
    if (savedInstanceState != null) {
        mWebView = (WebView) findViewById(R.id.webView1);
        mWebView.restoreState(savedInstanceState);
    } else { // If not, load the new URL from the intent bundle
        mWebView = (WebView) findViewById(R.id.webView1);
        mWebView.loadUrl(url);
        // Show the progress to the user
        mWebView.setWebChromeClient(new WebChromeClient() {
            public void onProgressChanged(WebView view, int progress) {
                activity.setProgress(progress * 100);

                if (progress == 100)
                    pd.dismiss();
            }

            @Override
            // Tell the client that the Application Cache has exceeded its
            // max size
            public void onReachedMaxAppCacheSize(long spaceNeeded,
                    long totalUsedQuota,
                    WebStorage.QuotaUpdater quotaUpdater) {
                quotaUpdater.updateQuota(spaceNeeded * 2);
            }

        });
        // Set the WebViewClient that will receive various notifications and
        // requests
        mWebView.setWebViewClient(new WebViewClient() {
            @Override
            public void onReceivedError(WebView view, int errorCode,
                    String description, String failingUrl) {
                // The redirect
                if (url.equals(failingUrl)) {
                    // error.html is the place we are redirected to by the
                    // server if we are online
                    mWebView.loadUrl("http:www.myCo/error.html");
                    return;
                } else if (url.equals(failingUrl)) { // The cache failed –
                                                        // We
                                                        // don't have an
                                                        // offline
                                                        // version to show
                    // This code removes the ugly android's
                    // "can't open page"
                    // and simply shows a dialog stating we have no network
                    view.loadData("", "text/html", "UTF-8");
                    // TODO -->showDialog(DIALOG_NONETWORK);
                }
            }

            // Set the WebViewClient that will receive various notifications
            // and requests
            @Override
            public boolean shouldOverrideUrlLoading(WebView view, String url) {
                view.loadUrl(url);
                return true;
            }
        });
    }
    slidingDrawer();// Load the slidingDrawer
    quickAction();// Load the QuickAction Bar interface
    tableOfContenants();// Load the TOC button interface
}

person Community    schedule 22.06.2011    source источник
comment
У меня точно такая же проблема. Вы решили это?   -  person Luis A. Florit    schedule 27.03.2014


Ответы (1)


person    schedule
comment
ссылка сейчас не работает. можешь дать альтернативную ссылку? - person prateek; 08.10.2015
comment
Я думаю, может быть, это ссылка unusual.life/development/html5-cache-android- веб-просмотр - person Henrik Kirk; 09.10.2015