2

I'm trying to open a pdf file in a Android WebView from this url:

http://bijsluiters.fagg-afmps.be/registrationSearchServlet?key=BE-TU441865&leafletType=leafletNL

When i searched for information online on how to achieve this, i found that you need to extend the url with this in front of it: "http://docs.google.com/gview?embedded=true&url="

but when i do this, i can only see html like when you open the link in a browser: "https://docs.google.com/gview?embedded=true&url=http://bijsluiters.fagg-afmps.be/registrationSearchServlet?key=BE-TU441865&leafletType=leafletNL"

How can i see the actual non-html content in my webview?

public class BijsluiterFragment : Android.Support.V4.App.Fragment
{
    //Title = DomainController.Instance.GetWord("BijsluiterTitle");
    private View view;
    private WebView webview;
    private string url;

    public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
    {
        view = inflater.Inflate (Resource.Layout.BijsluiterFragment, container, false);
        webview = view.FindViewById<WebView> (Resource.Id.webView);
        webview.Settings.JavaScriptEnabled=true;
        webview.Settings.SetPluginState (WebSettings.PluginState.On);
        if(!String.IsNullOrEmpty(url))
        {
            webview.LoadUrl ("http://docs.google.com/gview?embedded=true&url="+url);
        }
        return view;
    }

    public void SetUrl(string url)
    {
        this.url = url;
    }
}

I also tried with the 'loadwithbaseurl' method but it didn't work either...

1

1 Answer 1

4

I solved the same problem with this:

if (url.endsWith(".pdf")) {
    try {
         String urlEncoded = URLEncoder.encode(url, "UTF-8");
         url = "http://docs.google.com/viewer?url=" + urlEncoded;
    } catch (UnsupportedEncodingException e) {
         e.printStackTrace();
    }

}

With this prefix: "http://docs.google.com/viewer?url=" the WebView open the pdf with GoogleDocs.

Hope it helps you!!

1
  • nope didn't work, i get "[AwContents] nativeOnDraw failed; clearing to background color".
    – DennisVA
    Commented Feb 16, 2015 at 18:17

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.