3

The problem occurs only some devices. My application has about 1.9 million users, I get this problem as feedback from some users. They have sent screen shots too.

Detailed Explanation of problem: The WebView cannot show my static HTML content on some devices, shows only blank page. But 99% of devices works fine.

According to user feedbacks, this problem occurs on many different brands like Samsung, Sony, LG, ZTE etc. Also they have different versions of Android OS from 4.0.3 to 5.1.1

Tried all Genymotion Emulators and many real devices, all worked perfectly for me. Never seen this bug personally. But some users keep reporting this issue for 1.5 years.

Also my WebView's layout_height parameter is wrap_content, but it behaves like it has some invisible content(a couple of lines). Normally, it should have lots of lines.

Screen Shot

My webview settings:

webView = (WebView) v.findViewById(R.id.webView);
webView.getSettings().setJavaScriptEnabled(true);
webView.setWebViewClient(wvClient);
webView.getSettings().setTextSize(WebSettings.TextSize.NORMAL);

String start = "<html><head><meta name=\"viewport\" content=\"user-scalable=no\"/><meta http-equiv='Content-Type' content='text/html' charset='UTF-8' /><style>a {color:#9b252e;}\nimg.size-full{width:100%; height:auto;} iframe{width:100%; height:auto;} img{display: inline; height: auto; max-width: 100%;}</style></head><body>";
String end = "</body></html>";

webView.loadDataWithBaseURL(null, start + myHTMLContent + end, null, "text/html; charset=UTF-8", null);

My Questions are:

  1. What can cause that problem?
  2. How can I fix this?
  3. Can it be related to WebView version of currently installed on device?

Edit: I have already checked every related questions & answers on stackoverflow.

Oğuzhan Döngül
  • 7,856
  • 4
  • 38
  • 52

3 Answers3

1

What I would start with is fix the HTML so that there are no errors in it. I don't know which content you put in it, but the header already has several errors in it:

  • There is no doctype;
  • You should write content='text/html;charset='UTF-8' instead of content='text/html' charset='UTF-8';
  • There is no title element.

I'm inclined to think that the problem is related to the content you are showing inside since the outside stays the same, so make sure there are no errors as well.

While this may be related to the version of the WebView, but since you mention that the problem happens on 4.0, I think it should be more than just a version of a WebView because on that version of Android it isn't updated from Google Play like on the newest versions.

Malcolm
  • 41,014
  • 11
  • 68
  • 91
  • Thanks for the answer, I will consider your suggestions and update my code and wait for the user feedbacks. – Oğuzhan Döngül Mar 07 '16 at 08:36
  • We have similar problem... did anything help? – Zbyszek Dec 21 '16 at 17:47
  • I have the same issue only I get the blank page when my content (an HTML-encoded string) gets bigger than a certain size. I have not found any solution to that. I have added android:largeHeap="true" android:hardwareAccelerated="false" but still not fixed. Any suggestion? – msc87 Sep 16 '20 at 20:59
0

Google Chrome browser app's version should be same with WebView's version. I had similar problem and updating Google Chrome helped.

Mussa
  • 1,463
  • 21
  • 25
0

Applications targeting Build.VERSION_CODES.Q or later must either use base64 or encode any # characters in the content as %23, otherwise they will be treated as the end of the content and the remaining text used as a document fragment identifier.

wslaimin
  • 49
  • 2