My app shows a list of articles from an RSS feed and when one is selected it shows the article in a web view. The problem is that the web view is displaying the desktop sit
As @WarrenFaith pointed out in comments, this might be happening because of the custom User-Agent string that you are setting with
web.getSettings().setUserAgentString("Android");
Do not set this or make sure your webserver is configured to serve the mobile version of the site when it receives request with user agent as "Android".
WebSettings settings = view.getSettings();
settings.setJavaScriptCanOpenWindowsAutomatically(true);
settings.setSupportMultipleWindows(true);
settings.setBuiltInZoomControls(true);
settings.setJavaScriptEnabled(true);
settings.setAppCacheEnabled(true);
settings.setAppCacheMaxSize(10 * 1024 * 1024);
settings.setAppCachePath("");
settings.setDatabaseEnabled(true);
settings.setDomStorageEnabled(true);
settings.setGeolocationEnabled(true);
settings.setSaveFormData(false);
settings.setSavePassword(false);
settings.setRenderPriority(WebSettings.RenderPriority.HIGH);
// Flash settings
settings.setPluginState(WebSettings.PluginState.ON);
// Geo location settings
settings.setGeolocationEnabled(true);
settings.setGeolocationDatabasePath("/data/data/selendroid");
} catch (Exception e) {
SelendroidLogger.error("Error configuring web view", e);
}
After searching a lot this worked for me -
webView.getSettings().setJavaScriptEnabled(true);
webView.getSettings().setLoadWithOverviewMode(true);
webView.getSettings().setUseWideViewPort(true);
webView.getSettings().setSupportZoom(true);
webView.getSettings().setBuiltInZoomControls(true);
webView.getSettings().setDisplayZoomControls(false);
webView.setScrollBarStyle(WebView.SCROLLBARS_OUTSIDE_OVERLAY);
webView.setScrollbarFadingEnabled(false);
Setting setUseWideViewPort to false solved the problem for me:
mWebView.getSettings().setUseWideViewPort(false);
You just need to do include following line of code and it will be loading mobile site perfectly!
webView.setInitialScale(1);
webView.getSettings().setJavaScriptEnabled(true);