Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/466.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/196.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 使用webview时,Android上的HTML localStorage为空_Javascript_Android_Webview_Local Storage - Fatal编程技术网

Javascript 使用webview时,Android上的HTML localStorage为空

Javascript 使用webview时,Android上的HTML localStorage为空,javascript,android,webview,local-storage,Javascript,Android,Webview,Local Storage,我正在尝试从本地web应用程序使用localstorage,以下是WebView初始化部分: static class MyWebView extends WebView { public MyWebView(Context context) { super(context); this.getSettings().setJavaScriptEnabled(true);

我正在尝试从本地web应用程序使用localstorage,以下是WebView初始化部分:

static class MyWebView extends WebView
        {
            public MyWebView(Context context)
            {
            super(context);

            this.getSettings().setJavaScriptEnabled(true);

            //enable support for DOM Storage and Database
            this.getSettings().setDatabaseEnabled(true);
            this.getSettings().setDomStorageEnabled(true);


            String databasePath = context.getDir("database", Context.MODE_PRIVATE).getPath();

            this.getSettings().setDatabasePath(databasePath);


            this.setVerticalScrollbarOverlay(true);
        } }
下面是JavaScript上的测试应用程序:

function testStorage() 
    {
        var storage = window.localStorage;
        if (storage) {
            try {
                storage.setItem("name", "Hello World!"); //saves to the database, “key”, “value”
            } catch (e) {

                    alert(e.message); //data wasn’t successfully saved due to quota exceed so throw an error
            }
            document.write(storage.getItem("name")); //Hello World!
            storage.removeItem('name'); 
        }
        else {
            alert('Your browser does not support HTML5 localStorage. Because Storage is' + storage);
        }
    }
但问题是localStorage总是空的,我已经检查了权限,并创建了一个WebChromeClient

@Override
            public void onExceededDatabaseQuota(String url,
                    String databaseIdentifier,
                    long currentQuota,
                    long estimatedSize,
                    long totalUsedQuota,
                    WebStorage.QuotaUpdater quotaUpdater)
            {
                quotaUpdater.updateQuota(estimatedSize * 2);
            }
从来没有人打过电话。 有人知道为什么吗


谢谢

您是否已尝试根据以下答案启用设置:

是否已在WebView上设置自定义WebRomeClient?是的,我已使用WebView.setWebChromeClient…可能重复