I am developing an android application. There is a webview in my app, it will load a webpage.
webView = findViewById(R.id.web_view);
webView.getSettings().setUserAgentString("Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3770.142 Safari/537.36 SECSSOBrowserChrome");
webView.getSettings().setJavaScriptEnabled(true);
webView.loadUrl("xxxx.html");
I tested with https://www.google.com, the webView worked normally.
But it failed to load xxx.html ( this site is protected by Cloudflare)
I added WebViewClient like this
webView.setWebViewClient(new WebViewClient() {
@Override
public void onPageStarted(WebView view, String url, Bitmap favicon) {
super.onPageStarted(view, url, favicon);
KLog.d(TAG, "onPageStarted " + url);
}
@Override
public boolean shouldOverrideUrlLoading(WebView view, WebResourceRequest request) {
KLog.d(TAG, "host =" + request.getUrl().toString());
view.loadUrl(request.getUrl().toString());
return true;
}
@Override
public void onPageFinished(WebView view, String url) {
KLog.d(TAG, "onPageFinished " + url);
}
@Override
public void onReceivedError(WebView view, WebResourceRequest request, WebResourceError error) {
super.onReceivedError(view, request, error);
KLog.d(TAG,"onReceivedError " + error.getDescription() + "Error code = " + error.getErrorCode());
}
});
But public void onPageStarted(WebView view, String url, Bitmap favicon) { never call.
After waiting for a long time, I get this image
https://drive.google.com/file/d/12DmOGWNqKcq5IsMiQEApmtnvequOIxqD/view?usp=drivesdk
Could you help me to use android WebView to load this page?
Thanks in advance