我需要在 android webview 中加载一个 https url,但它会加载白屏。
我也处理public void onReceivedSslError(WebView view, SslErrorHandler handler, SslError error)
过,但在加载 url 时仍然会出现白屏,但 logcat 中没有异常。
下面是我的代码
public class MainActivity extends Activity {
private static final String URL = "https://someurl";
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
WebView myWebView = (WebView)findViewById(R.id.webview);
WebSettings settings = myWebView.getSettings();
settings.setJavaScriptEnabled(true);
settings.setDomStorageEnabled(true);
myWebView.loadUrl(URL);
myWebView.setWebViewClient(new MyWebViewClient());
}
private class MyWebViewClient extends WebViewClient {
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
if (Uri.parse(url).getHost().equals(URL)) {
return false;
}
Activity that handles URLs
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
startActivity(intent);
return true;
}
@Override
public void onReceivedSslError(WebView view, SslErrorHandler handler, SslError error) {
super.onReceivedSslError(view, handler, error);
handler.proceed();
}
}
}
期待你的答复。
谢谢