I am implementing an android application related to Webview. I am getting base64 data string from server that data format may be jpg or pdf file or doc file etc.
I want to load that base64 data string in webview using:
webview.loadData(urlString, "text/html; charset=utf-8", null);
Sample:
String urlString = getIntent().getStringExtra("base64String");
String mimeType = getIntent().getStringExtra("MimeType");
WebSettings settings = webView.getSettings();
settings.setDefaultTextEncodingName("utf-8");
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.FROYO) {
String base64 = Base64.encodeToString(urlString.getBytes(), Base64.DEFAULT);
webView.loadData(urlString, "text/html; charset=utf-8", "base64");
} else {
String header = "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>";
webView.loadData(header + urlString, "text/html; chartset=UTF-8", null);
}
Just Try it:
webView.loadData(urlString, "text/html; charset=utf-8", "base64");
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With