我想在android中显示一个Web应用程序(带有JavaScript桥)。我使用了WebView,并且能够正确显示Web应用程序的登录页面,但是一旦用户输入登录凭据并按下登录按钮,Android就会显示空白页面。我无法使用android自定义标签,因为它不支持javascript bridge。我需要JavaScript桥来实现蓝牙打印机的相关功能。我的代码如下:
WebView mWebView = (WebView)findViewById(R.id.mWebView);
WebSettings settings = mWebView.getSettings();
settings.setDefaultTextEncodingName("utf-8");
settings.setJavaScriptEnabled(true);
settings.setAllowUniversalAccessFromFileURLs(true);
settings.setDomStorageEnabled(true);
settings.setAppCacheEnabled(true);
settings.setAllowFileAccess(true);
settings.setDatabaseEnabled(true);
//String dbPath = this.getApplicationContext().getDir("databases", Context.MODE_PRIVATE).getPath();
//settings.setDatabasePath(dbPath);
mWebView.setWebChromeClient(new WebChromeClient()
{
@Override
public void onExceededDatabaseQuota(String url, String databaseIdentifier, long currentQuota, long estimatedSize, long totalUsedQuota, WebStorage.QuotaUpdater quotaUpdater)
{
quotaUpdater.updateQuota(estimatedSize * 2);
}
});
mWebView.setWebViewClient(new WebViewClientDemo());
mWebView.loadUrl("https://zibito.net/webpos2/");
mWebView.addJavascriptInterface(new JsObject(),"accessprinter");