0

I have the HTML data in the byte array, and I want to display it in webview. Currently I am displaying it by converting the byte array to a string and displaying it by using the following code.

mDecryptDataWv.loadDataWithBaseURL("", htmlData,    mimeType, encoding, "");

I want to display the byte array directly into webview without using a string.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
InnoTest
  • 9
  • 3

1 Answers1

0

Sorry, ultimately you can't do that if you're using below API level 11. Even the webview loads data interms of string only (basically it parses the HTML tags and renders the content). Even when you load the URL in webview also the same thing happens.

If you're using 11 and above, you can use the following method.

@TargetApi(11)
@Override
public WebResourceResponse shouldInterceptRequest(WebView view, String url) {
    Log.d("shouldInterceptRequest", url);

    InputStream stream = new ByteArrayInputStream(source);
    if (stream != null) {
        return new WebResourceResponse("text/javascript", "utf-8", stream);
    }
    return super.shouldInterceptRequest(view, url);
}
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Sush
  • 3,864
  • 2
  • 17
  • 35
  • Ok..but the problem if the data is more(more then 4mb string) then string is not able to hold the data,so app is loosing some data.Can you suggest how to overcome from this? – InnoTest Dec 30 '13 at 09:18
  • its not effiecient but save it as file and load it. but if ur using api level 11 and above. u just check my updated ans – Sush Dec 30 '13 at 09:24