我想在我的网页浏览中打开glauniversity.in。我已经实现了以下代码并进行了大量搜索,但一切似乎都是徒劳的。任何帮助将不胜感激。代码如下:
public class WebViews extends Activity {
String link;
WebView webview;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_web_view);
link="glauniversity.in";
webview = findViewById(R.id.wv);
webview.getSettings().setJavaScriptEnabled(true);
webview.setWebViewClient(new WebViewClient(){
@Override
public void onReceivedSslError(WebView view, SslErrorHandler handler, SslError error){
handler.proceed();
}
});
webview.setWebChromeClient(new WebChromeClient() { @Override public boolean onJsAlert(WebView view, String url, String message, JsResult result) { return super.onJsAlert(view, url, message, result); } });
webview.setWebViewClient(new WebViewClient());
webview.loadUrl(link);
}
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if (event.getAction() == KeyEvent.ACTION_DOWN) {
switch (keyCode) {
case KeyEvent.KEYCODE_BACK:
if (webview.canGoBack()) {
webview.goBack();
}
else {
finish();
}
return true;
}
}
return super.onKeyDown(keyCode, event);
}
}
答案 0 :(得分:0)
glauniversity.in
,这不是有效的网址
将其替换为
http://glauniversity.in/
<强>加成强> ::
通过
检查有效网址Patterns.WEB_URL.matcher(url).matches()
或
URLUtil.isValidUrl(url)