views:

48

answers:

3

Hi everyone,

Firstly, happy birthday!

I did try samples, demos from Google codes and other resources with WebView, but when i try to do it in my own code, it doesn't work for me.

I want to load myfile.html which i put in assets folder, and using:

private WebView myWebView;

myWebView.loadUrl("file:///android_assets/myfile.html);

On emulator shows error "The web page at file:///android_assets/myfile.html" could not be loaded as: The requested file was not found. /android_assets/myfile.html".

When i put that file to res/raw/ folder and using:

myWebView.loadUrl("file:///android_res/raw/myfile.html");

then only emulator android 2.2 API level 8 can load the file probably, other older versions show the same error. Am i missing something?

Could any way load an existing .html file in the application package which works on all API versions ?

Thank you in advance for your help!

A: 

You could read the html file manually and then use loadData or loadDataWithBaseUrl methods of WebView to show it.

Lucho
Hi Lucho, thanks for your answer. You means that i have to convert my .html file into String, then load it with loadData or loadDataWithBaseUrl method?
laph
my .html files are quite big to convert to string quickly. Any idea to load it with absolute path?
laph
A: 

mWebView.loadUrl("file:///android_res/raw/myfile.html"); definitely works on API level 8, but fail to load on older levels. Any idea why?

laph
A: 

ok, that was my very stupid mistake. I post the answer here just in case someone has the same problem.

The correct path for files stored in assets folder is "file:///android_asset/*" (with no "s" for assets folder which i was always thinking it must have a "s").

And, mWebView.loadUrl("file:///android_asset/myfile.html"); works under all API levels.

I still not figure out why mWebView.loadUrl("file:///android_res/raw/myfile.html"); works only on API level 8. But it doesn't matter now.

laph