Reputation: 2119
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...
Upvotes: 2
Views: 9103
Reputation: 2048
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!!
Upvotes: 4