Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android - WebView html5 local storage not persistant after app update

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);
like image 707
lgdroid57 Avatar asked Nov 02 '22 05:11

lgdroid57


1 Answers

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/");
}
like image 173
David Glance Avatar answered Nov 11 '22 11:11

David Glance