Reputation: 1653
I want to view a pdf in a Webview using the following code i am able to view it but the problem is that it opens a new view occupying the entire screen.I want the pdf to be viewed should be open in the Webview only and not in a new window. I am using the following code:
webView = (WebView) findViewById(R.id.webView);
webView.getSettings().setJavaScriptEnabled(true);
webView.getSettings().setPluginsEnabled(true);
String pdf = "http://178.239.16.28/fzs/sites/default/files/dokumenti-vijesti/sample.pdf";
String url = "http://docs.google.com/gview?embedded=true&url=" + pdf;
webView.loadUrl(url);
And following is my xml file:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<RelativeLayout
android:id="@+id/header_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/pdf_top_box" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:text="Title"
android:textColor="#ffffff" />
<Button
android:id="@+id/back_pdf"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:layout_marginLeft="10dp"
android:background="@drawable/back_pdf" />
</RelativeLayout>
<WebView
android:id="@+id/webView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/header_layout"
/>
</RelativeLayout>
Upvotes: 1
Views: 1162
Reputation: 28484
Try this way
webView = (WebView) findViewById(R.id.webView);
webView.getSettings().setJavaScriptEnabled(true);
webView.getSettings().setPluginsEnabled(true);
String pdf = "http://178.239.16.28/fzs/sites/default/files/dokumenti-vijesti/sample.pdf";
String url = "http://docs.google.com/gview?embedded=true&url=" + pdf;
webView.setWebViewClient(new WebViewClient()); //UPDATE HERE
webView.loadUrl(url);
Upvotes: 3