Android - WebView html5 local storage not persista

2020-06-23 10:17发布

问题:

I have an application that uses HTML5 local storage. The data in local storage is persistent throughout the app, while the app is open or closed. However, when the app was updated from the store, the local storage was erased. Is there a way to prevent the loss of local storage during app updates? Thanks!

mWebView = (WebView) findViewById(R.id.mWebView);
WebSettings mWebSettings = mWebView.getSettings();
mWebSettings.setAllowFileAccess(true);        
mWebSettings.setDatabaseEnabled(true);
mWebSettings.setDatabasePath("/data/data/"+this.getPackageName()+"/databases/");
mWebSettings.setDomStorageEnabled(true);
mWebSettings.setJavaScriptEnabled(true);

回答1:

There are answers to this posted here

The answer given by Mr Boyfox was

webView.getSettings().setDomStorageEnabled(true);
webView.getSettings().setDatabaseEnabled(true);
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) {
    webView.getSettings().setDatabasePath("/data/data/" + webView.getContext().getPackageName() + "/databases/");
}