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. Work with a part of CameraPreview

Hi all,

I would like to retrieve the content display on a small part of a
camera preview, but I don't know how :-/

I create my surfaceview displaying the camera but after that, how can
I retrieve the data displayed inside this without taking a picture ?

Thanks by advance for your help.

Regards

-- 

2. Memory Problem ? and content media provider died

Dear,

My users meet a problem, I am not sure to understand.
Here an extract of the log file I have received
11-15 21:22:40.816 I/ActivityManager(   70): Low Memory: No more
background processes.
11-15 21:22:42.306 I/ActivityManager(   70): Stopping service:
com.tmobile.selfhelp/.alert.service.AlertService
11-15 21:22:47.606 D/dalvikvm(  114): GC freed 1536 objects / 71304
bytes in 130ms
11-15 21:22:47.966 I/ActivityManager(   70): Start proc
android.process.media for content provider
com.android.providers.media/.MediaProvider: pid=4021 uid=10011 gids=
{1006, 1015, 2001, 3003}
11-15 21:22:48.086 I/ActivityThread( 4021): Publishing provider media:
com.android.providers.media.MediaProvider
11-15 21:22:48.156 V/MediaProvider( 4021): Attached volume: internal
11-15 21:22:48.166 V/MediaProvider( 4021): /sdcard volume ID:
1052379123
11-15 21:22:48.266 V/MediaProvider( 4021): Attached volume: external
11-15 21:22:48.276 I/ActivityThread( 4021): Publishing provider
downloads: com.android.providers.downloads.DownloadProvider
11-15 21:22:48.306 I/ActivityThread( 4021): Publishing provider drm:
com.android.providers.drm.DrmProvider
11-15 21:22:48.426 I/ActivityThread( 3963): Removing dead content
provider: media
11-15 21:22:48.426 I/ActivityManager(   70): Process
android.process.media (pid 4021) has died.
11-15 21:22:48.426 I/ActivityManager(   70): Killing app  (pid 3963)
because provider com.android.providers.media.MediaProvider is in dying
process android.process.media

How do you understand this log ?

I see a low memory, I guess that's why the content provider is killed,
killing my application at the same time.. When I test my application,
After more than two hours running, heap size is around 3.8MB (start
around 3MB) and the allocated memory stays stable over the period
after the GC is called (between 2.3MB et 2.7MB depending the operation
running)
To send query to the content provider, I am using the the
contentResolver from the Application context (getApplicationContext
().getContentResolver())

Is there people who undertand the problem I meet or who can give a
direction where to search to solve the problem ?


Regards,

Olivier

-- 

3. Multiline Buttons..?

4. images from images.google.com

5. images.google.com results in my app

6. how to get application state

7. FS : HTC Tattoo BNIB