0

I have an application which displays html file from assets folder.
Now the issue is if there is only one html, all works fine but in case I have more than 1 html, how do I refer it?


Folder structure when only 1 html is present is like
screen 1

and I refer to html file as follows:
InputStream input = this.getAssets().open("index.html");


but in case of multiple html's, it should/will be like
screen 2


So, in this scenario , how do I refer different html's?
i.e. how do I refer a file from a folder placed within assets folder?

As I have no idea how to proceed, any help appreciated...

GAMA
  • 5,958
  • 14
  • 79
  • 126

2 Answers2

4

You can access it as a URL like so:

"file:///android_asset/myfile.html"

So in a WebView you can use the method:

loadUrl("file:///android_asset/myfile.html")

Israel Unterman
  • 13,158
  • 4
  • 28
  • 35
  • I used `webView1.loadUrl("file:///android_asset/HTML 1/index.html");` and it's working !!! – GAMA May 04 '12 at 07:06
1

You can refer like this

WebView webview;

webview=(WebView)findViewById(R.id.webView1);

        webview.getSettings().setJavaScriptEnabled(true);

        webview.loadUrl("file:///android_asset/HTML 1/index.html");   

        webview.addJavascriptInterface(new MyJavaScriptInterface(), "Android");
final class MyJavaScriptInterface
    {
        public void ProcessJavaScript(final String scriptname, final String args)
            {             
                mHandler.post(new Runnable()
                    {
                        public void run()
                            {
                             //ToDo Something here...
                            }
                    });
            }
    }    
Ponmalar
  • 6,871
  • 10
  • 50
  • 80