WebView encoding? why?

by Angelo » Sat, 29 May 2010 06:55:13 GMT

Sponsored Links
 Hello all,

I have started to work with the WebView component of Android Platform,
but the API to load data to the component is confusing me, because it
includes a parameter with a encoding.

In both methods:
public void  loadData  (String data, String mimeType, String
public void  loadDataWithBaseURL  (String baseUrl, String data, String
mimeType, String encoding, String historyUrl);

you have to specify an encoding. In both cases, the API documentation
says that is is the encodign of the data (data parameter).

Well, as  know, if you provide data as a String object, the String is
internally stored in UTF-16 (unicode). To get a String object from a
external source, you need to specify the external source encoding to
convert it to UTF-16 and get the String internal representation
(String(byte[] data, String encoding)). So, at this moment, when you
have an String instance, everything from the original source has been
converted to UTF-16.
So, why do you need to specify an encoding if you are providing the
data as a String object?

I don't know the internal implementation of WebKit, but let's suppose
that, WebKit has a method, to render a source, providing as content an
InputStream and a default encoding. Well, as I know, when you process
a HTML page, you use the default encoding to read the HTML characters,
and if you find a <meta> tag specifing a different encoding, from that
moment, you have to use the new encoding to decode the characters of
the HTML page.

But what happens if you supply a HTML page that contains this <meta>
<meta HTTP-EQUIV="content-type" CONTENT="text/html;

using one of the methods specified at the top of this post,
how are you going to read ISO-8859-1 encoding from a String that it is
in UTF-16 encoding?
if the WebKit filtering this <meta> tags, and doesn't taking in
account the encoding specified in this tag?

Well, all of this is very confusing for me, because I don't understand
why the API includes this encoding parameter. I also don't know if the
<meta> encoding tags are filtered when the source is provided as a

Can anyone solve my doubts?

Thanks in advance


WebView encoding? why?

by Frank Weiss » Sat, 29 May 2010 11:11:42 GMT

 I think your puzzlement is well justified. It would seem to make more sense
that the first parameter should be byte[] instead of String.

Without looking at the Android source, I have some hypothesis:

1. The loadUrl() method indicates mimeType may be "image/jpeg" and encoding
may be "base64". In this case it would be reasonable that although the first
parameter is String, the correct loading of the data would require knowing
the encoding (although I don't know what other encoding may be reasonable).
2. In the absence of the ContentType HTTP header, you need to specify the
second and third parameters, perhaps because the WebView methods delegate to
another class/method that does require them.
3. Perhaps the encoding parameter is entirely ignored in the case that the
mimeType is text/*. That's where looking at the source would be helpful.


Sponsored Links

Other Threads

1. grid instead of mapview on emulator

Hello All
i am getting only a grid and not map. my ddms log has the following 3
lines and doesn't any one know how to get past this?

09-23 15:10:30.061: WARN/Maps_Persistence(605): Couldn't find
file:  /
09-23 15:10:30.141: WARN/Maps_Persistence(605): Couldn't find
file:  /
09-23 15:10:30.172: WARN/Maps(605): Couldn't restore map info, data

I have made manifest file and code according to the various
suggestions in this forum but am not successfull in seeing a map on

Best Regards,


2. Can anyone tell me if the Android platform supports Ifrared port ?


There is a group of us working on infrared for Andriod to port the
IrSimple stack to Andriod platform.   The new generation of phones
from Japan - from Docomo, Softbank, KDDI, Sharp, Casio and Sony all
have the 4Mbps transfer rate with the revised IrSimple stack - makes
beaming large multimedia files a real snap.  They are currently
available already in all the new models.  Other products also have
this stack includes:  printers, cameras, TVs, settop box as well as HD-
DVR players.

Why?  Isn't Bluetooth better and more convenient?  Basically cameras
are higher resolution (and files getting larger with 5 and 8
Megapixels in phonecameras) - so it does not make sense to just view
on a 3 inch display - beam it to a 42inch HD TV in under 1 second and
show it in your living room or office presentation.  Infrared is still
the lowest cost wireless component - less than $1 per module.  And
IrDA also has 16Mbps specs defined.  They have also demonstrated 1Gbps
infrared already 

Better still, swap photos and videos with your pals in the beach and
train station - without ever trying to get online - just beam it to
each other.  This is already happening in Japan with IrSimple
mobiles.  With 1Gbps, a whole CD takes less than 5 seconds!

p.s. we would like Andriod spec owners to add infrared
This is one thing iphone cannot do today!

- acton


3. I need to develop a calendar application using Android.

4. Testers Needed - Community App Store

5. Entrepreneur seeks Android Development

6. Proper shutdown

7. Blackberry storm