Webview loads page incorrectly on android versions lower than 4.0

I'm trying to display a result webpage in a Webview and I'm getting a weird result on Android version lower than 4.0. I have a print screen with what the difference is.

It displays correctly on versions newer than 4.0 and it works fine on my Galaxy S2 but it displays wrong on 2 Samsung phones with Android 2.2 and 2.3 and on the emulator. I tried an emulator with Android 3.0 and I had the same result. As a note, the webpage result works fine on the browser and I have a feeling that the website does some redirects, in case that helps.

Here is the code I'm using to load the page:

@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.webview); WebView webView = (WebView) findViewById(R.id.webView1); webView.getSettings().setJavaScriptEnabled(true); webView.getSettings().setDomStorageEnabled(true); // Show the web page webView.loadDataWithBaseURL(null, MainActivity.content, "text/html", "UTF-8", null); }

And the image.

Any ideas why it doesn't work the same on all Android versions?

<strong>UPDATE</strong> It's official, I have tried loading the website URL using multiple versions of WebViews, with different settings and the website just doesn't load correctly on devices with Android version older than 4. I'm stuck.

<strong>UPDATE 1</strong>

I noticed that on older versions it's not that it doesn't load correctly the page, the problem is that it tries to load the web version of the page and not the mobile version. I tried changing the user agent but it made no difference.

<strong>UPDATE 2</strong>

I tried almost all I could find on the site about WebViews and loading content and I can't figure out what the problem is. This is my code now, although it works the same only with java script enabled.

@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.webview); WebView webView = (WebView) findViewById(R.id.webView1); webView.setWebChromeClient(new WebChromeClient()); webView.setWebViewClient(new WebViewClient()); webView.getSettings().setJavaScriptEnabled(true); webView.getSettings().setDomStorageEnabled(true); webView.setPersistentDrawingCache(0); webView.setInitialScale(1); webView.getSettings().setDefaultTextEncodingName("utf-8"); String webData = MainActivity.content; webData = webData.replace("#", "%23"); webData = webData.replace("%", "%25"); webData = webData.replace("\\", "%27"); webData = webData.replace("?", "%3f"); webView.getSettings() .setUserAgentString( "Mozilla/5.0 (iPhone; U; CPU like Mac OS X; en) AppleWebKit/420+ (KHTML, like Gecko) Version/3.0 Mobile/1A543a Safari/419.3"); webView.loadData(webData, "text/html; charset=UTF-8", null); } // webView.loadDataWithBaseURL(MainActivity.url, MainActivity.content, // "text/html", "UTF-8", null); // webView.loadData(MainActivity.content, "text/html; charset=utf-8", // "UTF-8");

Is there something I'm missing?

Also, if it will help, this is the code for how I get the HTTP Post response that I use to display in the webview:

HttpClient httpClient = new DefaultHttpClient(); HttpPost httpPost = new HttpPost("http://www.fernbus24.de/bus-" + vonCopy + "-" + nachCopy); url = "http://www.fernbus24.de/bus-" + vonCopy + "-" + nachCopy; List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(); nameValuePairs.add(new BasicNameValuePair("_searchbox", "d5ed667846")); nameValuePairs.add(new BasicNameValuePair("von", von)); nameValuePairs.add(new BasicNameValuePair("nach", nach)); nameValuePairs.add(new BasicNameValuePair("datum", datum)); // etc... try { httpPost.setEntity(new UrlEncodedFormEntity(nameValuePairs)); HttpResponse response = httpClient.execute(httpPost); InputStream is = response.getEntity().getContent(); Log.i("Test", "response status" + response.getStatusLine().getStatusCode()); InputStreamReader inputStreamReader = new InputStreamReader(is); BufferedReader bufferedReader = new BufferedReader( inputStreamReader); StringBuilder stringBuilder = new StringBuilder(); String bufferedStrChunk = null; while ((bufferedStrChunk = bufferedReader.readLine()) != null) { stringBuilder.append(bufferedStrChunk); } content = stringBuilder.toString(); Log.i("Test", "content is " + content); } catch (UnsupportedEncodingException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (ClientProtocolException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); }

<strong>UPDATE 3</strong>

I have tried setting webView.setInitialScale(50); and I am getting this:<img src="https://i.stack.imgur.com/5w36W.png" alt="Image">


Try this;

Webview webView = (WebView) findViewById(R.id.webView1); wb.getSettings().setJavaScriptEnabled(true); wb.setWebViewClient(new WebViewClient()); wb.loadUrl("URL");

if it doesn't work, please write your url then i will try it.


Have you already tried



  • event is not working properly in mysql?
  • How to load react native JS bundle from network in Android?
  • Auto loop-scrolling active contents in JPanel - marquee text
  • Regex to match a capturing group one or more times
  • Android/MongoDB: “NoClassDefFoundError: com.mongodb.DBPortPool”
  • How to Set wallpaper of image with its actual size?
  • What is the official release update URL for Aptana Studio 3.0?
  • Google Player Game Service Error: Can't build the sample game
  • Android - HorizontalScrollView will not scroll all the way
  • What does certain JVM do after loading ByteCode into memory?
  • How can i dump blob fields from mysql tables
  • Best way to dynamically load an xml configuration file into a Flex4/Flash movie at runtime?
  • How can I enlarge video fullscreen without the affected interface project in as3?
  • What and where is mdimport
  • Does it make sense to call System.gc() and Thread.sleep() when working on Bitmaps?
  • Android - Material Design - NavigationView - How to put vertical scroll?
  • JQuery Internet Explorer and ajaxstop
  • Python urlparse: small issue
  • Jquery UI tool tip close icon
  • How to delay loading a property with linq to sql external mapping?
  • FileReader+canvas image loading problem
  • Cannot connect to cassandra from Spark
  • Align navbar back button on right side
  • DotNetZip - Calculate final zip size before calling Save(stream)
  • Get object from AWS S3 as a stream
  • SSO with signing and signature validation doesn't work
  • MySQL WHERE-condition in procedure ignored
  • Web-crawler for facebook in python
  • Warning: Can't call setState (or forceUpdate) on an unmounted component
  • How to get icons for entities from eclipse?
  • trying to dynamically update Highchart column chart but series undefined
  • Proper way to use connect-multiparty with express.js?
  • Load html files in TinyMce
  • Free memory of cv::Mat loaded using FileStorage API
  • How to get Windows thread pool to call class member function?
  • python draw pie shapes with colour filled
  • JaxB to read class hierarchy
  • costura.fody for a dll that references another dll
  • Reading document lines to the user (python)
  • java string with new operator and a literal