Webpage in data: text / html is not available with specific content lines of WebView text / html

I am using the following Java code to create HTML code to display content.

public String htmlFromArrayList(ArrayList<TSI> a) { StringBuilder returnStringBuilder = new StringBuilder(); for (TSI i : a) { returnStringBuilder.append("<h3>"); returnStringBuilder.append(i.itemTitle); returnStringBuilder.append("</h3><p>"); returnStringBuilder.append(i.itemText); returnStringBuilder.append("</p>"); } return returnStringBuilder.toString(); } 

To load a line, I use

 mWebView.loadData(htmlFromArrayList(mSummaryItemArrayList), "text/html", null); 

Now this works from about 60% to 70% of my ArrayList<TSI> , but for the rest I get an error when opening TSI :

The web page at data:text/html;null,%3Cp%E.......p%3E might be temporarily down or it may have moved...

I guess this has something to do with weird encoding characters. What does the error message mean?

+3
source share
1 answer

Do you have weird characters like percent signs, backslashes, or other non-alphabetic characters in your i.itemText or i.itemTitle? If you do this, it will cause a “webpage not found” problem.

http://code.google.com/p/android/issues/detail?id=4401

In addition, you do not pass in encoding, try passing "UTF-8" instead of null.

 mWebView.loadData(htmlFromArrayList(mSummaryItemArrayList), "text/html", "utf-8"); 

This problem can be solved by replacing all% characters with an HTML object (Ampersand Pound 37): (& # 37).

There are reports that if any Chinese characters get into your webView, you can still get the "page not found" problem, even if you are processing a percent sign. So the work on this is to try the following:

This works with all the plus Chinese characters:

 mWebView.loadData(URLEncoder.encode(html,"utf-8").replaceAll("\\+"," "), "text/html", "utf-8"); 

Source http://code.google.com/p/android-rss/issues/detail?id=15

+9
source

Source: https://habr.com/ru/post/1438546/


All Articles