[英]How do I call window.openDatabase from a webView hosted in an android application?
I created a native Android app that basically hosts a webView control. 我创建了一个原生Android应用程序,它基本上托管了一个webView控件。 That webView is then used to load a page that calls window.openDatabase from JavaScript.
然后,该webView用于加载从JavaScript调用window.openDatabase的页面。 I can successfully confirm that the API exists by verifying window.openDatabase.
我可以通过验证window.openDatabase来成功确认API是否存在。
Calling this method returns a null when called in a hosted webView control. 在托管的webView控件中调用时,调用此方法将返回null。 Calling the same method in the Android Browser returns an instance of the database.
在Android浏览器中调用相同的方法将返回数据库的实例。
Does anyone know the permessions in the manifest or settings on the webView control that need to be set to access the database? 有谁知道webView控件上的清单或设置中的渗透需要设置为访问数据库? Is this even possible in a native app.
这在本机应用程序中是否可行。
To use the database API you have to configure your WebView to accept HTML5 database calls: 要使用数据库API,您必须将WebView配置为接受HTML5数据库调用:
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: 如果要控制存储配额,还可以覆盖WebChromeClient的onExceededDatabaseQuota方法:
public void onExceededDatabaseQuota(String url, String
databaseIdentifier, long currentQuota, long estimatedSize, long
totalUsedQuota, WebStorage.QuotaUpdater quotaUpdater) {
quotaUpdater.updateQuota(204801);
}
This solution worked for me: 这个解决方案对我有用:
WebSettings settings = myWebView.getSettings();
settings.setJavaScriptEnabled(true);
settings.setDatabaseEnabled(true);
String databasePath = this.getApplicationContext().getDir("database",
Context.MODE_PRIVATE).getPath();
settings.setDatabasePath(databasePath);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.