Android 4.0 & # 8594; 4.3 (included) - web storage lost between web browsing pages

I am working on an Android project that relies on WebView to view several HTML pages stored on a device and send web view inputs when it is needed to store them in a database.

Each page contains controls related to jQuery towards the previous / next pages, each page contains inputs of different types (flags, text fields, etc.).

The final page contains Submit buttons that use JSInterface to save the results inside SQLite DB.

Another button (on the custom top navigation bar) offers the same system.

The results can be changed by accessing the first page with all the saved entries, the jQuery system will fill in the corresponding entries.

For more details, I use SDK 19 and compile with 4.4.2 , but I worked with SDK 15 > and compile in 4.2.2 , where I had no problem.

If someone needs to see what is being done on a simplified system, check out JSBin .


Problem

I use SessionStorage to store input between pages that I used to work with cookies, but they became unreliable when there were more than 150 key / value pairs.

My problem is that on some devices, SessionStorage disappears between pages.


Test protocol

1st case - Only the first page remains

If I stay only on the first page, fill in the entries, then send the results, everything will be fine. Returning for modification offers me a completely filled first page.

The second case - moving between pages

After filling out page 1, I go to page 2 and fill in the new entries, and then move between the pages to see if the entries on each individual page are lost. Everything is in place, but if I send the results, only the current page entries will be transferred.


Android Version Test Results

  • 3.2 - Works

  • 4.1.2 - Doesn't work

  • 4.2.1 - Doesn't work

  • 4.3 - Doesn't work

  • 4.4.2 - Works


Proven Solutions

  • Overriding WebViewClient shouldOverrideUrlLoading method to return False - Doesn't work

  • Using LocalStorage instead of SessionStorage hasn't changed anything

Insights

Switching from sessionStorage to localStorage did not help.

I found useful information about the versions of WebKit used by Android:

Android 3.2.1 uses a rather old version, but it works (v534.13)

Android , from 4.0 to 4.3 , share the same WebKit engine (v534.30)

Android 4.4 uses a completely new version (v537.36) that explains why it works.

Not one step to fix, but it gives a more accurate idea of ​​the problem and the device that it affects.

Decision

Since SDK 16, the new security setting was forced to prohibit Javascript code to access content from any source.

if(Build.VERSION.SDK_INT >= 16) { setting.setAllowUniversalAccessFromFileURLs(true); } 

Kudos to ksasq for finding this!

[EDIT 02/18/2014]

After some testing, I pointed the problem to TargetSdkVersion, BuildTarget does not change anything.

It is set to 15 , WebStorage is working as intended.

If it is set to 16 or higher, WebStorage gets confused.

+6
source share
3 answers

There have been some changes between ICS (SDK 15) and JellyBean (SDK 16) in the WebView security model and how it handles javascript from the file: // origin. Try to call

 WebSettings.setAllowUniversalAccessFromFileURLs(true) 

to confirm that you are working with files: // URLs and trust the content you display. I believe that due to the upgrade to Chromium WebView in 4.4, something else has changed in the base implementation so as not to require these settings.

+4
source

I'm sorry that the webstorage api has a problem on Android, because I will be using it in the next few days.

As you already explored, Android 4.4 uses the brand new WebView, which is based on ChromeBrowser, where many web technologies like webScoket, etc., other than the localStorage api, are already well supported.

Having said that, reading your complaints, the localStorage api has a problem for android4.0-4.2 (which I also set as the target devices), I thought that use the FileSystem api instead.

http://www.html5rocks.com/en/tutorials/file/filesystem/

However, looking on the Internet, it is so unsure that this api works well, and finally I found this.

Using local storage in an Android web browser

https://github.com/didimoo/AndroidLocalStorage

+2
source

I understand that the session store exists, and the window that created it is still open, and the local store is constantly between sessions. So does the browser look at the window to stay open when navigating between two local files? This may be open to interpretation. Looking at your code, it seems pretty easy to change it to use local storage rather than session storage, so what would it be?

+1
source

All Articles