0

right now i am working with webview, i reffered many codes regarding this but still i can't figure why i am not able to get the view in my device. I went through lot of examples, still no use, can you guys help to clear this issue. Thanks in advance, below is my code. I am loading file in WebView from the local SD card in device.

    webView.getSettings().setJavaScriptEnabled(true);
    webView.getSettings().setSaveFormData(true);
    webView.getSettings().setBuiltInZoomControls(true);
    webView.getSettings().setPluginState(PluginState.ON);
    webView.getSettings().setSavePassword(false);

    webView.setWebChromeClient(new MyWebChromeClient());
    webView.addJavascriptInterface(new DemoJavaScriptInterface(), "demo");
    webView.loadUrl(filePath);

final class DemoJavaScriptInterface {
    DemoJavaScriptInterface() {
    }

    public void clickOnAndroid() {
        mHandler.post(new Runnable() {
            public void run() {
                webView.loadUrl("javascript:wave()");
            }
        });

    }
}

 final class MyWebChromeClient extends WebChromeClient {
        @Override
        public boolean onJsAlert(WebView view, String url, String message, JsResult result) {
            Log.d(LOG_TAG, message);
            result.confirm();
            return true;
        }
    }
Vicky
  • 921
  • 1
  • 11
  • 33
  • You explain that something is not working, but I'm not sure I get what actually is the problem here... What is the exact "issue"? – shkschneider Dec 17 '14 at 14:19
  • well, i am getting blank page instead of documents in webview. – Vicky Dec 17 '14 at 14:20
  • Are you trying to load html/css content from SD card ? Maybe you should start a webserver on the device to do this (maybe use NanoHTTP) – Hugo Gresse Dec 17 '14 at 14:21
  • i am trying with each and every type of files like .pdf, .ppt, .xlsx,.doc is it possbile in webview – Vicky Dec 17 '14 at 14:24
  • @HugoG can you tell me clearly what should i do? or suppose any link related to your answer. – Vicky Dec 17 '14 at 14:27
  • Refer to this post http://stackoverflow.com/questions/5749569/load-local-html-file-into-webview Or this one : https://www.google.fr/search?q=load+local+file+in+webview+android&ie=utf-8&oe=utf-8&gws_rd=cr&ei=OZORVNANg6w679uBqAw – Hugo Gresse Dec 17 '14 at 14:30
  • i will get back once after checking with your answers thanks man – Vicky Dec 17 '14 at 14:34
  • is the file you want to show a static HTML page? is filePath a valid path to your file? try to print it and see if it's not pointing to a non-existing file or similar... – Alberto Malagoli Dec 17 '14 at 14:40
  • i think its for only loading Html files into webview and from asset folder. – Vicky Dec 17 '14 at 14:42
  • @albemala filePath is a valid path. No i don't want to show a static HTML page. – Vicky Dec 17 '14 at 14:47
  • so, as @HugoG said, you should probably use a webserver to access you web page – Alberto Malagoli Dec 17 '14 at 14:54
  • plz mark any answer as solved or answer your own question and close the subject – Hugo Gresse Dec 22 '14 at 10:05
  • i still didn't get my answer, well once i find it i will surely put it as my answer. – Vicky Dec 22 '14 at 10:14

1 Answers1

0

If you want to show not static page with html/css/js, you have to use a local webserver (like NanoHTTPD) on the device to host your files.

For more information about using NanoHTTPD, refer to this post. One this done, juste load the local url corresponding to the local server on your webView.

Community
  • 1
  • 1
Hugo Gresse
  • 17,195
  • 9
  • 77
  • 119