18

I made an Android/Phonegap app, and it is running fine on all devices with several android OS versions, except on some Gingerbread (2.3) phones. I am using Phonegap 1.9.

Debugging the code, I realized an illegal access exception on Javascript, every time I use the HTML5 localStorage.getItem() and localStorage.setItem() methods.

How can I enable the localStorage features on those Android devices?

HitOdessit
  • 7,198
  • 4
  • 36
  • 59
Gabriel Mendez
  • 1,115
  • 1
  • 9
  • 28

3 Answers3

8

The illegal exception was caused by JSON.parse() methods when the .getItem() returns null. Just be careful to validate it. Android 2.3, HTML5 localStorage and Phonegap are working perfectly now.

Gabriel Mendez
  • 1,115
  • 1
  • 9
  • 28
0

Check the code for your WebView's WebSettings, i.e check the following are called:

WebSettings settings = webView.getSettings();

settings.setJavaScriptEnabled(true);

settings.setDatabaseEnabled(true);

settings.setDatabasePath(this.getApplicationContext()
        .getDir("database", Context.MODE_PRIVATE).getPath());

settings.setDomStorageEnabled(true);
THelper
  • 15,333
  • 6
  • 64
  • 104
gheese
  • 1,170
  • 1
  • 11
  • 17
  • I had a hard time by trying to figure out where those settings are. Under phonegap, we need to call super.appView.getSettings() for accessing them. However, is necessary to call super.init() before do it. Otherwise, appView comes null. Let me try by changing those values as you said. – Gabriel Mendez Oct 19 '12 at 05:02
  • Tested already. All those settings are true, but I am not able to store/retrieve anything still. – Gabriel Mendez Nov 16 '12 at 17:44
0

This validation work for me. :) (javascript in android 2.3 use phonegap)

Storage.prototype.getArray = function(key) {
        if (this.getItem(key)) {
            return JSON.parse(this.getItem(key)) 
        } else {
            //console.log("no error null value");
        }

    }