How do I call window.openDatabase from a webView hosted in an android application?

后端 未结 2 1032
一生所求
一生所求 2020-12-09 13:40

I created a native Android app that basically hosts a webView control. That webView is then used to load a page that calls window.openDatabase from JavaScript. I can succe

2条回答
  •  温柔的废话
    2020-12-09 14:33

    To use the database API you have to configure your WebView to accept HTML5 database calls:

    WebSettings settings = webView.getSettings();  
    settings.setJavaScriptEnabled(true);  
    settings.setJavaScriptCanOpenWindowsAutomatically(true); 
    ... 
    settings.setDatabaseEnabled(true);  
    settings.setDatabasePath("/data/data/your.package.name/database_name");
    

    You may also override the onExceededDatabaseQuota method of your WebChromeClient if you want to control your storage quota:

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

提交回复
热议问题