我正在尝试在Android中使用Webview
,并在访问一个需要在我启动后立即弹出身份验证的网站时遇到以下困难。
当应用运行时,Webview
显示空白页面而不是弹出窗口或身份验证页面。
注意:加载其他网页也没关系。例如" google" " Facebook和#34;
Java代码
public class MainActivity extends AppCompatActivity {
private WebView webview1;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
initialize();
}
private void initialize() {
webview1 = (WebView) findViewById(R.id.webview1);
webview1.setVisibility(View.VISIBLE);
webview1.loadUrl("http://164.100.194.110:81");
webview1.setWebChromeClient(new WebChromeClient(){
@Override
public boolean onJsAlert(WebView view, String url, String message,JsResult result) {
webview1.loadUrl(url);
return super.onJsAlert(view, url, message, result);
}
});
webview1.getSettings().setJavaScriptEnabled(true);
webview1.getSettings().setJavaScriptCanOpenWindowsAutomatically(true);
webview1.getSettings().setSupportZoom(true);
webview1.getSettings().setSupportMultipleWindows(true);
webview1.setWebViewClient(new WebViewClient() {
public void onPageStarted(WebView view, final String url, Bitmap favicon) {
super.onPageStarted(view, url, favicon);
}
public void onPageFinished(WebView view, final String url) {
super.onPageFinished(view, url);
}
});
}
}
答案 0 :(得分:0)
您在网站上使用基本访问身份验证,解决方案是您应用程序上的预定义用户名和密码,您可以查看this
private final String HOST = "164.100.194.110:81";
private final String URL = "http://" + HOST + "/";
private final String USERNAME = "user";
private final String PASSWORD = "pass";
WebViewDatabase.getInstance(this).clearHttpAuthUsernamePassword();
webview1.setHttpAuthUsernamePassword(HOST, HOST, USERNAME, PASSWORD);
或者您可以通过override WebViewClient
来实现