webview problems when rendering HTML and using loadData

by Clay » Mon, 02 Mar 2009 09:51:57 GMT


Sponsored Links
 I know that many of you know this already but I am making a post
because I spent 5 hours trying to figure out why loadData was not
working. This does not pop up easily in searches of the mailing list.

TAGS: webview background white android loadData

WebView momentContent =
                        (WebView) view.findViewById
(R.id.subscription_list_moment_webcontent);
WebSettings wsettings =
                        momentContent.getSettings();
wsettings.setJavaScriptEnabled(true);

//works great
//momentContent.loadUrl(" http://www.momentarynow.com/app/public/ 
android/info_about.html");

//doesnt work exact same content WHY?
momentContent.loadData(
                                ResourceUtils.loadResToString(R.raw.content, 
mContext),
                                mimeType,
                                encoding);

====

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<style type="text/css">
<!--
.bg {
        font-size: x-small;
        background-color: #CC6600;
}
-->
</style>
</head>
<body class="bg">
foobar
</body>
</html>

unless you use the most simple html possible, like no style sheets,
backgrounds, etc, loadData seems to blow up. The only workaround I
have found is to use loadDataWithBaseURL instead


                final String mimeType = "text/html";
                final String encoding = "UTF-8";
                //render the html
                WebView momentContent =
                        (WebView) 
findViewById(R.id.subscription_list_moment_webcontent);
                WebSettings wsettings =
                        momentContent.getSettings();
                wsettings.setJavaScriptEnabled(true);
                momentContent.loadDataWithBaseURL(" http://fake.com ",
                                ResourceUtils.loadResToString(
                                                R.raw.content,
                                                getApplicationContext()),
                                mimeType,
                                encoding,
                                " http://fake.com ");


oh now it magically works. but my forehead is a bit bruised from
hammering it against the brick wall.

I merely post to help others avoid my fate.

Clay



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



Other Threads

1. dlopen libexif.so will fail when it is linked to other native code

We met issue when try to use libexif.so which is linked to other
native code and in the same time used by ExifInterface java class.

The native code can call libexif.so successfully but the java class
ExifInteface will fail "Cannot find library".

To avoid the problem,we have to split the libexif.so to two library
libexif.so and libexifcore.so,the libexif.so will contain JNI and
libexifcore.so will contain jhead code only.

My question is:
1.Why a library with JNI code can't be dlopen by VM when it is linked
with native code?
2.Is it acceptable to split libexif to two library so that other
native code can call jhead?
--~--~---------~--~----~------------~-------~--~----~
unsubscribe: android-porting+unsubscr...@googlegroups.com
website: 

2. Getting a complete list of android native drawables

> I've checked that one out, that's for Android 1.0 which is old.

Not that old. Are there any you've found that do not work?

-- 
Mark Murphy (a Commons Guy)
http://commonsware.com
_The Busy Coder's Guide to Android Development_ Version 2.0 Available!



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

3. Capture data packet of dev phone

4. Why can not edit /init.rc on adp1 with firmware 1.1?

5. Checking how a program was installed?

6. A simple question regarding inter-process communication.

7. Android + SugarCRM + Web Services = SugaDroid (Open Source)