Analysis of considerations for Android WebView's loadData method

  • 2020-05-10 18:51:13
  • OfStack

html data in loadData() cannot contain '#', '%', '\', '? '4, a special character that causes parsing errors and shows that the page is missing and part of the html code is missing. How do you deal with it? We need to encode %23, %25, %27, %3f in UrlEncoder.
You can use two types of code, data is html of type string
1. webView. loadData(URLEncoder. encode(data, "utf-8 "), "text/html",  " utf-8 ");
So it doesn't look so good in the background or anything. Is not recommended.
2. webView.loadDataWithBaseURL(null,data, "text/html",   "utf-8 ", null);
And then you have a perfect solution.

Related articles: