[英]Authentication pop up in webview android
I am trying to use Webview
in Android and facing the below difficulty while accessing a site which requires authentication in pop up as soon I launch it. 我试图在Android中使用
Webview
,并在访问需要启动弹出式窗口身份验证的网站时遇到以下困难。
When the app runs, Webview
displays blank page instead of the popup or the authentication page. 应用运行时,
Webview
显示空白页面,而不是弹出窗口或身份验证页面。
Note: loading other webpages are fine. 注意:加载其他网页也可以。 eg "google" "facebook"
例如“ google”“ facebook”
Java code 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);
}
});
}
}
You are using Basic access authentication on your website, the solution is predefined username and password on your application, you can take a look on 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);
or you can achieve by override WebViewClient 或者您可以通过重写WebViewClient来实现
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.