Why do some pages not load in my WebView (but seem to work fine in Chrome)? For example:
I've set my WebView to enable JS. Here is my WebView init code:
webView = (WebView) findViewById(R.id.webview);
webView.getSettings().setJavaScriptEnabled(true);
webView.getSettings().setBuiltInZoomControls(true);
webView.getSettings().setDisplayZoomControls(false);
webView.getSettings().setDomStorageEnabled(true);
webView.setWebViewClient(new WebViewClient());
webView.setWebChromeClient(new WebChromeClient() {
public void onProgressChanged(WebView view, int progress) {
progressBar.setProgress(progress);
if (progress == 100) {
progressBar.setVisibility(View.GONE);
}
else {
progressBar.setVisibility(View.VISIBLE);
}
}
});
webView.loadUrl(url);
You might often face issues in updating the chrome and Android System Webview. To fix this problem, you can reboot your device, check your internet connection, stop auto-updating all apps, clear Google Playstore cache, and storage, leave the beta testing program, and manually update Android WebView app from Playstore.
Chrome, Google's ubiquitous browser, powers Android System WebView. The Android System WebView app is typically pre-installed on most Android smartphones. That way, every developer that resorts to using it to render internet content inside their app can do so without warning about compatibility issues.
The WebView shipped with Android 4.4 (KitKat) is based on the same code as Chrome for Android version 30. This WebView does not have full feature parity with Chrome for Android and is given the version number 30.0. 0.0.
Alternatives to WebView If you want to send users to a mobile site, build a progressive web app (PWA). If you want to display third-party web content, send an intent to installed web browsers. If you want to avoid leaving your app to open the browser, or if you want to customize the browser's UI, use Custom Tabs.
I have a very similar webview code on my project, I just replaced the urls you have provided.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_user_agreement);
WebView webView = (WebView) findViewById(R.id.userAgreementView);
final ProgressWheel progressWheel = (ProgressWheel) findViewById(R.id.progress_bar);
webView.getSettings().setJavaScriptEnabled(true);
webView.getSettings().setBuiltInZoomControls(true);
webView.getSettings().setDisplayZoomControls(false);
webView.getSettings().setDomStorageEnabled(true);
//webView.getSettings().setUserAgentString("Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2228.0 Safari/537.36");
Log.v("UA", webView.getSettings().getUserAgentString());
String url = getIntent().getStringExtra("data"); //Urls provided by other activity
if (url != null && !url.equals("")) {
webView.setWebChromeClient(new WebChromeClient() {
public void onProgressChanged(WebView view, int progress) {
//progress wheel fills here etc.
// ...
// ...
}
}
});
webView.loadUrl(url);
}
}
http://onlinelibrary.wiley.com/doi/10.1002/art.39115/pdf this one loaded like a charm in the webview with no glitches and no wrong behavior.
Then I tried this one http://www.ajpmonline.org/article/S0749-3797(14)00628-X/fulltext, when the webview completes loading a new native Chrome activity starts immediately and loads the mobile version of the page in a separate activity.
I checked the behavior of the website with my desktop Chrome, when I make an http request with a Android user agent string it turns out to do the following things.
Then I decided mimic the user agent string as a desktop browser. I picked a UA string from http://www.useragentstring.com/pages/Chrome/ and set it like this before the loadUrl method and voilà!
webView.getSettings().setUserAgentString("Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2228.0 Safari/537.36");
Log.v("UA", webView.getSettings().getUserAgentString());
This may be an edge case scenario and depending on the URL you are loading behavior may change but you can force to load desktop version of the websites with a proper user agent string.
I'm using this code:
WebSettings settings = webView.getSettings();
settings.setLoadWithOverviewMode(true);
settings.setUseWideViewPort(true);
settings.setJavaScriptEnabled(true);
settings.setAppCacheEnabled(false);
settings.setCacheMode(WebSettings.LOAD_NO_CACHE);
settings.setDatabaseEnabled(false);
settings.setDomStorageEnabled(false);
settings.setGeolocationEnabled(false);
settings.setSaveFormData(false);
Hope it can help you.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With