Tuesday, September 13, 2011

[android-developers] Re: Problem loading an HTML asset in WebView

hello,

may be you should use function load data with base url where your
assets placed

webview.loadDataWithBaseURL("file:///android_asset/
Shopping/", .......

On Sep 12, 10:55 pm, darrinps <darri...@gmail.com> wrote:
> I have an asset that I am trying to load in WebView. If the same file
> is read from the SD card, all works fine, but I cannot read it when
> packaged as an asset.
>
> Here is the code
>
> WebView webview = new WebView(this);
>
> ((ViewGroup)findViewById(R.id.content)).addView(webview, 0);
> webview.getSettings().setJavaScriptEnabled(true);
> webview.setWebViewClient(new WebViewClient()
> {
>     ... //code elided for brevity
>     webview.loadUrl("file:///android_asset/Shopping/index.html");
>
> }
>
> This same code works fine if I use another html file if it isn't in
> its own directory.
>
> For example, this works:
> webview.loadUrl("file:///android_asset/sample.html");
>
> Also, as stated above, if I read it from an SD card this all is OK.
>
> For example, this also works:
>       webview.loadUtl("content://com.android.htmlfileprovider/sdcard/
> downloads/Shopping/index.html");
>
> The only think that doesn't work is when the thing is in its own
> directory it seems. Is packaging an asset inside its own directory a
> no no? I'd like to keep things tidy if possible, but if it cannot be
> done then I will remove the Shopping directory and plunk everything
> down under assets.
>
> Thanks!

--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate