0

I am developing an Android HTML5 application.

I am not using any of the Android API apart from loading my main.html file. The rest of the application runs through HTML5 and jQuery mobile.

I use localstorage in my app to store some user related data. When I test this in my local browser by loading the main.html file everything works well. But when I run the same application on Android simulator I don't see the values in the app which I am loading from localstorage.

@Override protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState); // 
    setContentView(R.layout.activity_main); 
    WebView webView = new WebView(this);
    WebSettings settings = webView.getSettings(); // TO enable JS      
    settings.setJavaScriptEnabled(true); // To enable Localstorage 
    settings.setDomStorageEnabled(true); 
    webView. webView.loadUrl("file:///android_asset/main.html"); 
    setContentView(webView); 
}

So my ultimate question whether a standalone android HTML 5 app supports localstorage or not?

If not what is the alternative apart from data storage?

rene
  • 41,474
  • 78
  • 114
  • 152
Shantanoo K
  • 765
  • 5
  • 15
  • 43

1 Answers1

0

You would need to use the below code to enable HTML5 Local store in android webview

settings.setDomStorageEnabled(true);

Also you'd need to make sure the target SDK is 2.1 or higher.

Details here : Android webview & localStorage

Community
  • 1
  • 1
Vikash Rathee
  • 1,776
  • 2
  • 25
  • 43