Display pdf file (stored on google drive) in web view with google docs

My pdf file is stored on some ex website: http://www.pdf995.com/samples/pdf.pdf

Now I can not rely on other sites for my application. So,

  • I uploaded a pdf document
  • uploaded to google drive
  • Got my own pdf link
  • Trying to open this in webviewwith google docs
  • FAILED

Now the links are as follows

Result

  • Other websites may change their URL at any time. I can not rely on this.

  • If I use only the link to Google Drive, then it opens in a web browser that is not included in the application.

  • If preceded by Google docs, this does not result in a pdf document. I get something like this.

enter image description here

What needs to be done so that I can use my own pdf file from Google disk to open in webview

I followed CommonsWare , Stuart Siegler , Samir Mangroly, but nothing works. : (

+1
source
3

pdf , Google, . , :

webview.loadUrl("http://drive.google.com/viewerng/viewer?embedded=true&url=" + pdf);

pdf - PDF. :

String pdf = "http://www.pdf995.com/samples/pdf.pdf";
webview.loadUrl("http://drive.google.com/viewerng/viewer?embedded=true&url=" + pdf);
+2

WebView, pdf , Google:

String myPdfUrl = "https://drive.google.com/file/d/1fQfqgEmz-AiCpdHEIh7SNwdnAkQFqDQp/view";

"/view".

java :

private void displayWebView() {
    webView.getSettings().setJavaScriptEnabled(true);
    webView.setWebViewClient(new WebViewClient(){
        @Override
        public boolean shouldOverrideUrlLoading(WebView view, WebResourceRequest request) {
            view.loadUrl(myPdfUrl);
            return true;
        }
    });
    webView.loadUrl(myPdfUrl);
}

@SuppressLint("SetJavaScriptEnabled") onCreate()

@SuppressLint("SetJavaScriptEnabled")
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.act
0

, .

Google.

, URL-

https://drive.google.com/uc?id=0B1dndMpNP4zgdlTuMm5rcjFk3TQ&export=download // test url //

String url="https://drive.google.com/uc?id=0B1dndMpNP4zgdlTuMm5rcjFk3TQ&export=download";
webView = (WebView) findViewById(R.id.progr);
webView.getSettings().setJavaScriptEnabled(true);
webView.getSettings().setLoadWithOverviewMode(true);
webView.loadUrl("http://drive.google.com/viewerng/viewer?embedded=true&url="+url);
-1
source

All Articles