1

My Android app can display files sent as raw HTML in a web view.

Generally there are no issues, but a user is sending the following and all i am getting is a blank white page.

 <!doctype html>
   <html>
     <head></head>
       <body>
        <script type='text/javascript'>
          window.location.href = "http://www.pdf995.com/samples/pdf.pdf";
        </script>
       </body>
   </html>

and i cannot get the webview to load the file in the script.

I have all of the following enabled to try to get javascript to work:

webview.getSettings().setJavaScriptEnabled(true);
webview.getSettings().setDomStorageEnabled(true);
webview.getSettings().setLoadWithOverviewMode(true);
webview.getSettings().setUseWideViewPort(true);
webview.getSettings().setBuiltInZoomControls(true);
webview.getSettings().setDisplayZoomControls(false);
webview.getSettings().setSupportZoom(true);
webview.getSettings().setDefaultTextEncodingName("utf-8");
webview.getSettings().setPluginState(WebSettings.PluginState.ON);

and i have used both of these loadData calls to no avail (not using both at the same time, just included to show what i've tried):

webview.loadDataWithBaseURL("", documentHtml.htmlRaw, "text/html", "utf-8", "");
webview.loadData(htmlRaw, "text/html", "utf-8");

When i create a .html document containing the above html, email it and open it on my Android device, it gives me the choice to use Android HTML Viewer or Chrome/Internet (Android browser)...when i use the HTML Viewer i get the same blank white page that i see in my app...when i use Chrome/Internet it allows me to download the file and then view it.

The file will not always necessarily be a PDF file, but no matter what i want to be able to either:

  1. Preferably display the document in the app without having to download it first

  2. Download the document to my devices Downloads folder, and then view it.

Any help/suggestions would be great.

1 Answer 1

1

This will surely work if you have the urls to the files which you want to display. Just replace "http://www.pdf995.com/samples/pdf.pdf" this url with the dynamic one.

    String html_string = "<div> \n" +
                "<object type=\"text/html\" data=\""+"http://docs.google.com/gview?embedded=true&url="+ "http://www.pdf995.com/samples/pdf.pdf" +"\" width=\"1000px\" height=\"1800px\">\n" +
                "</object>\n" +
                " </div>";
    webView.loadData(html_string, "text/html", "UTF-8");
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks but I'm not in control of what raw HTML is supplied, and i do not want to parse or change the HTML in any way. The HTML in question comes in with a javascript script, my questions is how to work with that HTML.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.