locked
Local storage in webview in android app? RRS feed

  • Question

  • User37379 posted

    how can i enable local storage in webview in android app? is there any property for webview to enable it like setDomStorageEnabled in native android?

    Friday, March 7, 2014 7:55 AM

Answers

  • User27642 posted

    I need an answer to this as well - there doesn't seem to be a property for it, and I get JS errors that the LocalStorage object is null when I try to use it in a webview...

    • Marked as answer by Anonymous Thursday, June 3, 2021 12:00 AM
    Monday, March 10, 2014 3:42 PM

All replies

  • User27642 posted

    I need an answer to this as well - there doesn't seem to be a property for it, and I get JS errors that the LocalStorage object is null when I try to use it in a webview...

    • Marked as answer by Anonymous Thursday, June 3, 2021 12:00 AM
    Monday, March 10, 2014 3:42 PM
  • User27642 posted

    I believe I found the answer...here's how my WebView is configured in OnCreate:

    web_view = FindViewById<WebView>( Resource.Id.webview );
    web_view.Settings.JavaScriptEnabled = true;
    web_view.Settings.DatabaseEnabled = true;
    web_view.Settings.DomStorageEnabled = true;
    string dbPath = Application.Context.GetDir("database", FileCreationMode.Private).Path;
    web_view.Settings.DatabasePath = dbPath;
    

    I also saw in Android documentation and elsewhere that because 4.4 (KitKat) adopted Chromium for the WebView control, it should no longer be necessary from that version on to manually set the path of the database as we have to here.

    Friday, March 14, 2014 4:57 PM
  • User16522 posted
         WebView localWebView = FindViewById<WebView>(Resource.Id.LocalWebView);
                    localWebView.SetWebViewClient(new WebViewClient()); // stops request going to Web Browser
                    localWebView.Settings.JavaScriptEnabled = true;
                    localWebView.Settings.DatabaseEnabled = true;
                    localWebView.Settings.DomStorageEnabled = true;
                    localWebView.SetWebChromeClient(new WebChromeClient());
                    if (Build.VERSION.SdkInt < BuildVersionCodes.Kitkat)
                    {
                        string dbPath = Application.Context.GetDir("database", FileCreationMode.Private).Path;
                        localWebView.Settings.DatabasePath = dbPath;
                    }
    
    Monday, May 23, 2016 1:49 PM