Quantcast
Channel: Active questions tagged utf-8 - Stack Overflow
Viewing all articles
Browse latest Browse all 1060

Load data with base64 encoding with loadDataWithBaseURL

$
0
0

I have an app which use WebView to show some local html to users. The app worked fine in last 2 years, but recently I'm getting too many reports that the app is showing some kind of error like this:

"Web page not available The web page at data:text/html; charset=utf-8;charset=utf-8;base64, could not be loaded because: net::ERR_INVALID_RESPONSE"

obviously something changed in android or WebView, and it did, the doc is saying:

Stricter UTF-8 decoder In Android 9, the UTF-8 decoder for Java language is stricter and follows the Unicode standard.

so, I tried to load my data with base64 encoding to solve the problem.

String encodedHtml = Base64.encodeToString(resource.getBytes(), Base64.NO_WRAP);loadDataWithBaseURL(basePath, encodedHtml, "text/html; charset=utf-8", "base64", null);

But this method just prints the raw base64 string. so I tried this:

loadData(encodedHtml, "text/html; charset=utf-8", "base64");

and it shows the html without any problem.

BUT, I need to use loadDataWithBaseURL so I can post process the html, eg. loading css, font and so on.

so what's the difference between loadData and loadDataWithBaseURL that cause one of them show the html and the other shows the raw base64 string?


Viewing all articles
Browse latest Browse all 1060

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>