无法在Android中的webview中打开链接。我在webview中尝试了它,但它只显示空白页面。似乎有些网址被加载了,但有些网址却没有加载。
String strUrl = "https://app.mygtechguy.com/5862bd814bf7f";
webView.setWebViewClient(new WebViewClient() {
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return true;
}
@Override
public void onPageFinished(WebView view, String url) {
progressBar.setVisibility(View.GONE);
}
@Override
public void onReceivedError(WebView view, WebResourceRequest request, WebResourceError error) {
Toast.makeText(getActivity(), "Oh no! ", Toast.LENGTH_SHORT).show();
alertDialog.setTitle("Error");
alertDialog.setMessage("Make sure internet is working well");
alertDialog.setButton("OK", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
return;
}
});
alertDialog.show();
}
});
webView.getSettings().setLoadsImagesAutomatically(true);
webView.getSettings().setJavaScriptEnabled(true);
webView.getSettings().getAllowContentAccess();
webView.setScrollBarStyle(View.SCROLLBARS_INSIDE_OVERLAY);
webView.loadUrl(strUrl);
答案 0 :(得分:0)
我建议尝试从这样的shouldOverrideUrlLoading中删除网址加载:
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
//view.loadUrl(url);
return false;
}
并且还在AndroidManifest.xml中设置了Internet权限:
<uses-permission android:name="android.permission.INTERNET" />