I'm working on an Android project which relies on the WebView to browse multiple HTML pages stored on the device and submit the inputs toward the webview when it's needed for storing them in a database.
Each page contains controls that are bound with jQuery towards previous / next pages, each page contains inputs of differents types (checkboxes, textfields, etc.).
The last page contains a Submit buttons that uses the JSInterface to save the results inside a SQLite DB.
Another button (in a custom top navigation bar) offers the same system.
Results can be modified by accessing the first page with all the saved inputs, a jQuery system will fill the corresponding inputs.
For more details, I'm using the SDK 19 and compiling against 4.4.2, but I used to work with the SDK 15 and compiling against 4.2.2 where I didn't have the issue.
If someone needs to see what is done, in a simplified system, check this JSBin.
I'm using SessionStorage to store the inputs between the pages, I used to work with cookies but they became unreliable when there was over 150 key/values pairs.
My problem is that on some devices, the SessionStorage disappear between pages.
If I stay on the first page only, fill the inputs then send the results, everything's fine. Coming back for modification offers me a fully filled first page.
After filling page 1, I move to page 2 and fill the new inputs then move between pages to see if the inputs are lost on each individual pages. Everything is in place, but if I send the results, only the current page inputs are transmitted.
3.2 - Works
4.1.2 - Doesn't work
4.2.1 - Doesn't work
4.3 - Doesn't work
4.4.2 - Works
Overriding the WebViewClient's shouldOverrideUrlLoading method to return False - Doesn't work
Using LocalStorage instead of SessionStorage didn't change a thing
Switching from sessionStorage to localStorage did not help.
I found some useful informations about the WebKit versions used by Android :
Android 3.2.1 uses a quite old version but it works (v534.13)
Android versions ranging from 4.0 to 4.3 share the same WebKit engine (v534.30)
Android 4.4 uses a brand new version (v537.36) of it, which explains why it works
Not a single step toward a fix BUT it gives a more precise view of the problem and the device it affects.
Since the SDK 16, a new security setting has been forced to prevent Javascript code to access content from any origin.
if(Build.VERSION.SDK_INT >= 16) {
setting.setAllowUniversalAccessFromFileURLs(true);
}
Kudos to ksasq for finding this !
[EDIT 18/02/2014]
After some testing, I pin pointed the problem to the TargetSdkVersion, the BuildTarget does not change anything.
It it's set to 15, the WebStorage works as intended.
If it's set to 16 or higher, the WebStorage is messing up.
Between ICS (SDK 15) and JellyBean (SDK 16) there were some changes in the WebView's security model and how it handles javascript from file:// origins. Please try to call
WebSettings.setAllowUniversalAccessFromFileURLs(true)
to acknowledge you are working from file:// URLs and trust the content you are displaying. I imagine that due to the upgrade to Chromium WebView in 4.4 something else changed in the underlying implementation to not require these settings.