Display the pdf file(stored in google drive) in webview by using google docs

前端 未结 5 1188
半阙折子戏
半阙折子戏 2021-01-03 03:39

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 th
5条回答
  •  既然无缘
    2021-01-03 04:07

    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
    

提交回复
热议问题