SECURITY_ERR:DOM 异常 18 在 WebView 中打开数据库时 [英] SECURITY_ERR: DOM Exception 18 When opening database in WebView

查看:24
本文介绍了SECURITY_ERR:DOM 异常 18 在 WebView 中打开数据库时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个应用程序,它们都在 webview 中使用 SQL 数据库.

I have two app which both of them use SQL Database in webview.

其中一个在我的设备上运行良好,但另一个在尝试打开数据库时出现此错误.

One of them works very well on my device, but the other raise this error when trying to open database.

未捕获的错误:SECURITY_ERR:DOM 异常 18

Uncaught Error: SECURITY_ERR: DOM Exception 18

两个项目的一切都相似,我尝试了很多东西但没有找到原因.

Everything is similar in both project, I tried many thing but didn't find the reason.

我从头开始了一个项目,效果很好.

I started a project from scratch, it works fine.

推荐答案

这花了我一整天的时间才弄明白,所以我想提供关于如何在 Android 4.2 和 4.3 上解决这个问题的完整文档.

This took me a full day to figure out, so I'd like to give full documentation about how to solve this problem on Android 4.2 and 4.3.

可以从 WebView 中的 file:// URL 使用 Web SQL.科尔多瓦人设法做到了.您只需三件事:

You can use Web SQL from a file:// URL in WebView. The Cordova folks managed to do it. There are just three things you must do:

1) 调用 setDatabaseEnabled()(废话):

1) Call setDatabaseEnabled() (duh):

webView.getSettings().setDatabaseEnabled(true);

2) 设置数据库文件路径.是的,这在 Android 4.4 中已被弃用,但如果您想避免 Kitkat 之前的 DOM Exception 18,它是必需的:

2) Set the database file path. Yes, this is deprecated in Android 4.4, but it is required if you want to avoid the DOM Exception 18 in pre-Kitkat:

String databasePath = getContext().getApplicationContext().getDir(
  "database", Context.MODE_PRIVATE).getPath();
webView.getSettings().setDatabasePath(databasePath);

3) 设置 onExceededDatabaseQuota 处理程序.是的,它在 Android 4.4 中已被弃用,等等.

3) Set the onExceededDatabaseQuota handler. Yes, it's deprecated in Android 4.4, blah blah blah.

    webView.setWebChromeClient(new WebChromeClient() {

      @Override
      public void onExceededDatabaseQuota(String url, String databaseIdentifier, long currentQuota, long estimatedSize,
                                          long totalUsedQuota, WebStorage.QuotaUpdater quotaUpdater) {
        quotaUpdater.updateQuota(estimatedSize * 2);
      }
    });

如果您跳过这 3 个步骤中的任何一个,那么您将收到 DOM Exception 18 错误并且 Web SQL 将无法工作.你已被警告.

If you skip any one of these 3 steps, then you will get the DOM Exception 18 error and Web SQL will not work. You've been warned.

这篇关于SECURITY_ERR:DOM 异常 18 在 WebView 中打开数据库时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆