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
encoding);
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>
tag:
<meta HTTP-EQUIV="content-type" CONTENT="text/html;
charset=ISO-8859-1"/>

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
String?

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. Using/accessing the AutoText database

Hi all,

Does the AutoText mechanism in Android have a database of correct
English words ?

Can I use it somehow to test several word combinations to see if I can
find a match ?

(trying to built T9...)

TIA
--~--~---------~--~----~------------~-------~--~----~

2. How do you save the state of an activity on an ActivityUnitTestCase

Thanks. I did give ActivityInstrumentationTestCase a try but it didn't
work. Now I gave it another try with a fresh look and it's partly
running (the test is failing, but I believe the problem is somewhere
else so if I post I'd do it as another thread).








-- 
J. Pablo Fernndez <pup...@pupeno.com> (http://pupeno.com)

--~--~---------~--~----~------------~-------~--~----~

3. 3D world view with zoom - maybe google earth?

4. AdMob for Android

5. Not able to build Browser Source Code on android-sdk-windows-1.0_r1

6. recovery, bootloader and diskinstaller

7. Is SDK(r2) support camera capture from desktop devices * (webcams etc). ?