我正在创建一个Android应用程序来在Web视图中打开一个网站。该网站工作正常,我可以轻松导航到不同的页面,但当用户点击“登录”选项时,webview没有显示登录表单。我已经尝试了很多东西来修复它,但我没有得到它。 Plz帮助。
Web Activity.java
public class WebActivity extends AppCompatActivity {
private WebView webView;
private String url = "https://www.digverve.com/";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_web);
webView = findViewById(R.id.Web_view);
webView.setWebViewClient(new WebViewClient(){
@Override
public void onReceivedSslError(final WebView webView, final SslErrorHandler handler, SslError error) {
Log.d("CHECK", "onReceivedSslError");
AlertDialog.Builder builder = new AlertDialog.Builder(WebActivity.this);
AlertDialog alertDialog = builder.create();
String message = "Certificate error.";
switch (error.getPrimaryError()) {
case SslError.SSL_UNTRUSTED:
message = "The certificate authority is not trusted.";
break;
case SslError.SSL_EXPIRED:
message = "The certificate has expired.";
break;
case SslError.SSL_IDMISMATCH:
message = "The certificate Hostname mismatch.";
break;
case SslError.SSL_NOTYETVALID:
message = "The certificate is not yet valid.";
break;
}
message += " Do you want to continue anyway?";
alertDialog.setTitle("SSL Certificate Error");
alertDialog.setMessage(message);
alertDialog.setButton(DialogInterface.BUTTON_POSITIVE, "OK", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
Log.d("CHECK", "Button ok pressed");
// Ignore SSL certificate errors
handler.proceed();
}
});
alertDialog.setButton(DialogInterface.BUTTON_NEGATIVE, "Cancel", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
Log.d("CHECK", "Button cancel pressed");
handler.cancel();
}
});
alertDialog.show();
}
});
webView.getSettings().setJavaScriptEnabled(true);
webView.getSettings().setDomStorageEnabled(true);
webView.getSettings().setDatabaseEnabled(true);
webView.getSettings().setPluginState(WebSettings.PluginState.ON);
webView.getSettings().setAllowFileAccess(true);
webView.loadUrl(url);
}
}
答案 0 :(得分:0)
对于此类警报,您必须设置处理它的chrome client
。您应该使用WebChromeClient
在webview中获取这些类型的警报。 WebChromeClient
提供处理它的onJsAlert
方法,或者只是将此方法重写为
webView.setWebChromeClient(new WebChromeClient() {
@Override
public boolean onJsAlert(WebView view, String url, String message, JsResult result) {
// Anything you want to do on pop-up
return super.onJsAlert(view, url, message, result);
}