weird behaviour with WebView.loadDataWithBaseURL

by Jason Proctor » Wed, 08 Jul 2009 03:53:26 GMT


Sponsored Links
 i install a WebViewClient to intercept links using 
shouldOverrideUrlLoading(). i fetch the URL content myself, 
preprocess it, then feed it to the browser using 
loadDataWithBaseURL(). as the base URL, i use the original URL of the 
request.

this mechanism has been working reliably for a while, but recently it 
broke and i'm not sure what's going on. the symptoms i'm seeing are 
inconsistent despite the same inputs being presented. most of the 
time, the WebView displays the contents of the base URL, completely 
ignoring the "data" parameter. this is despite the preprocessing 
actually taking place and verifiably producing the correct output 
(which btw contains no links, relative or otherwise).

after reading the documentation on the loadDataWithBaseURL() method, 
which includes a note on file: URLs etc, i've been playing with the 
baseURL to see if that changes the behaviour. passing null as the 
base URL usually results in success, but of course i need relative 
links to work properly so it's not going to fly as a real solution. 
passing an http: URL initially worked, but after a few iterations 
broke, and the WebView then started just displaying the content of 
the http: baseURL.

all of this time, the failURL parameter was set to null, just so i'd 
be sure that it wasn't showing that instead.

also, Javascript and file access is enabled on the WebView via the 
WebSettings API.

IMHO, the WebView should never display the contents of the base URL. 
it's there as a string only in order to provide context for relative 
links in the data. i see notifications in my WebViewClient that it's 
calling onPageStarted() and onPageFinished() for the base URL, so 
it's doing *something* with it.

IMHO also, the WebView should call an installed WebViewClient's 
onReceivedError() method if errors happen. since 1.5 i have *never* 
seen it do this on Android (the equivalent works on iPhone, as does 
most everything else). i can see the justification for not calling it 
if there is a failURL installed, but not if there isn't.

this is crazy as i'm seeing different behaviour for the same inputs. 
literally i could see something work (like with an http: base URL) 
then rebuild it with *no* logic changes, and it would break.

any help appreciated. btw this list still does not get on with any of 
my addresses - i suspect gmail is filtering posts, now *all* posts 
not just mine, before they get to the per-user spam filter - so 
please copy directly on replies.

thanks much
-- 
jason.software.particle

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



Other Threads

1. FileNotFoundException when creating FileOutputStream with file on sdcard

this is because file.mkdirs() doesn't understand that the second 
argument you provided to the File constructor is a file name rather 
than a directory name. i think you might find, and indeed i found, 
that /sdcard/zackcorp/myfiles/myFile.txt is actually a directory. the 
directory is writable in the sense that you can put files in it, but 
you can't directly open it for writing using a FOS.

btw, i've so far found nothing weird in the Android File package. 
well, except that createTempFile() will return a file that's not 
writable if there is nothing mounted on /sdcard. that should be fixed 
IMHO.

hope this helps,
j




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

2. any word from google on video support (other than 3gp/youtube)?

I'm hoping to hear that video support for mp4 format is soon to be
patched/fixed/enhanced.

Can anyone confirm that google has solid video support (from local
files, sdcard as well as streaming) in the near future roadmap?

far as I know) is either very spotty or non-existent.  Note I'm not
referring to audio at all.

Yes, I know that the SDK claims video support and there is a thread
with sample mediaplayer code (see below) but I haven't yet seen anyone
successfully display mp4 video.  Even the sample mediaplayer code
posted by Megha Joshi (google) has a single response to it from
someone saying he can't get actual video (only audio from the file).
Sure enough, I've tried my own code, the sample code and at least two
other people's code and only the audio works from multiple size and
dimensions of test mp4 files.

I want to be passionate about Android development but I'm a little
discouraged right now.  If I at least knew it was coming, I'd stay
enthusiastic.  But I'm even doubting my preorder of the G1s right now
because it seems clear that they aren't committing to any video
features (none on the phone other than youtube 3gp and only
streaming... no local video file support at all).

I heard Sprint is planning "other features" for their upcoming phone.
Is video support an "other feature"?  Can I assume that the G1 may
never have it or is it simply an SDK issue and it will be fixed
somewhat soon?

Sorry for the rant, if you know anything, I'm anxious to hear it.



3. When is R.string etc available?

4. "Application error" is encountered when trying to load large image file

5. on-screen 12-key keyboard

6. How we can able to diaplay the more than one radio button?

7. Package flags and attributes