Update: Storing and loading the value from localStorage works fine on all
devices while on the *same page*, however, not between different pages. In
my example, I can store and retrieve the value on 01_home.html, but when I
go to another page in the android_asset folder, I cannot retrieve it
anymore (on LG and Samsung device). Works fine on Nexus 4 though.
What is the reason for the different behaviour? Different WebKit version,
different Android version, vendor?
On Tuesday, 30 September 2014 11:56:11 UTC+2, Mathias Lin wrote:
>
> I have a html5 application that I wrap in a WebView. To store and retrieve
> user input values between pages, I use the *localStorage* html5 feature.
>
> It works fine on my Nexus 4 (Android 4.4.4), but it does not work on
> Samsung Galaxy Tab 2 (Android 4.3.x) (= nothing happens, but also no error
> in logcat). Or, to be more clear: *on Samsung, it does not work if the
> html pages are loaded from within the app's asset folder*. It does work
> though if I put the pages on a web server, as below in the outcommented
> line.
>
> However, on Nexus 4, loading from file:///android_asset/ and also if I
> load the pages on a desktop browser (Chrome, Firefox) from file:// path, it
> is also working.
>
> (I had another user reported the issue on a LG device, so it does not seem
> to be Samsung specific).
>
> Below are the settings of the web view.
>
> webView = (WebView)this.findViewById(R.id.webView);
> webViewClient = new MyWebViewClient(this);
> webViewClient.setSm(sm);
> webView.setWebViewClient(webViewClient);
> WebSettings webSettings = webView.getSettings();
> webSettings.setJavaScriptEnabled(true);
> webSettings.setDomStorageEnabled(true);
> webView.getSettings().setJavaScriptEnabled(true);
> webView.getSettings().setDomStorageEnabled(true);
> webView.getSettings().setPluginState(WebSettings.PluginState.ON);
> webView.getSettings().setAppCacheEnabled(false);
> webView.getSettings().setCacheMode(WebSettings.LOAD_NO_CACHE);
> webView.getSettings().setUseWideViewPort(true);
> webView.getSettings().setLoadWithOverviewMode(true);
> webView.getSettings().setBuiltInZoomControls(false);
> webView.getSettings().setSupportZoom(false);
> webView.getSettings().setDefaultZoom(WebSettings.ZoomDensity.FAR);
>
> webView.loadUrl("file:///android_asset/01_home.html"); // does NOT work!
> // webView.loadUrl("http://192.168.178.33/01_home.html"); // does work!
>
> Local storage code in the pages:
>
> // storingvar data = document.getElementById('data').value;
> window.localStorage.setItem((1), data);
> // reading
> document.getElementById('data').value = window.localStorage.getItem(1);
>
>
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
---
You received this message because you are subscribed to the Google Groups
"Android Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.