Open pdf in webview android Download Source code here 
activity_main.xml
<RelativeLayout android:layout_width="match_parent"
 android:layout_height="match_parent"
 xmlns:android="http://schemas.android.com/apk/res/android">

 <WebView
 android:layout_width="match_parent"
 android:background="#ffffff"
 android:layout_height="match_parent"
 android:id="@+id/webview"></WebView>


 </RelativeLayout>
MainActivity.java
package com.pdfwebview;

import android.app.ProgressDialog;
import android.graphics.Bitmap;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.webkit.WebView;
import android.webkit.WebViewClient;

public class MainActivity extends AppCompatActivity {

 WebView webview;
 ProgressDialog pDialog;

 @Override
 protected void onCreate(Bundle savedInstanceState) {
 super.onCreate(savedInstanceState);
 setContentView(R.layout.activity_main);

 init();
 listener();
 }

 private void init() {
 webview = (WebView) findViewById(R.id.webview);
 webview.getSettings().setJavaScriptEnabled(true);

 pDialog = new ProgressDialog(MainActivity.this);
 pDialog.setTitle("PDF");
 pDialog.setMessage("Loading...");
 pDialog.setIndeterminate(false);
 pDialog.setCancelable(false);
 webview.loadUrl("https://drive.google.com/file/d/0B534aayZ5j7Yc3RhcnRlcl9maWxl/view");

 }

 private void listener() {
 webview.setWebViewClient(new WebViewClient() {
 @Override
 public void onPageStarted(WebView view, String url, Bitmap favicon) {
 super.onPageStarted(view, url, favicon);
 pDialog.show();
 }

 @Override
 public void onPageFinished(WebView view, String url) {
 super.onPageFinished(view, url);
 pDialog.dismiss();
 }
 });
 }
}
Advertisements