Я пытаюсь сохранить кэшированные файлы 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
}