使用谷歌文档在 webview 中显示 pdf 文件(存储在谷歌驱动器中) [英] Display the pdf file(stored in google drive) in webview by using google docs

查看:28
本文介绍了使用谷歌文档在 webview 中显示 pdf 文件(存储在谷歌驱动器中)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的 pdf 文件存储在某个网站例如:

应该怎么做才能使用我自己的 google 驱动器中的 pdf 在 webview 中打开

我已关注 CommonsWareStuart Siegler, Samir Mangroliya 但没有任何效果.:(

解决方案

我有一个 WebView,我的 pdf 存储在 google drive 中的链接是:

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

不要忘记/view".

还有我用于显示的 java 代码:

private void displayWebView() {webView.getSettings().setJavaScriptEnabled(true);webView.setWebViewClient(new WebViewClient(){@覆盖public boolean shouldOverrideUrlLoading(WebView view, WebResourceRequest request) {view.loadUrl(myPdfUrl);返回真;}});webView.loadUrl(myPdfUrl);}

并在 onCreate()

上方添加 @SuppressLint("SetJavaScriptEnabled")

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

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

Now I can't rely on other websites for my app. So

  1. I've downloaded the pdf doc
  2. uploaded in google drive
  3. Got my own link for pdf
  4. Trying to open that in webview using google docs
  5. FAILED

Now the links are as follows

Result,

  • Other websites may change their url at anytime. Can't rely on it.

  • If I use the google drive link alone, then it is opening in web browser not within the app.

  • If preceded with google docs, it is not resulting in a pdf doc. I get something like this.

What should be done so that I can use my own pdf from google drive to open in webview

I've followed CommonsWare, Stuart Siegler, Samir Mangroliya But nothing works. :(

解决方案

I have a WebView, and the link to my pdf stored in google drive is:

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

Don't forget "/view".

And my java code for display:

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);
}

And add @SuppressLint("SetJavaScriptEnabled") above onCreate()

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

这篇关于使用谷歌文档在 webview 中显示 pdf 文件(存储在谷歌驱动器中)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆