0

so I just started with Android programming and I am trying to make a little app using WebView. There is a url that redirects you to a pdf, I know WebView does not render pdf. So I want to use intent and display the pdf in Google Docs. However, the pdf address is randomly generated so I cant link it with

WebView.loadUrl("http://docs.google.com/gview?embedded=true&url=" + pdfURL);

How can I send an intent to Google Docs without using the exact pdf address?

Bajirao Shinde
  • 1,356
  • 1
  • 18
  • 26
Abdab
  • 3
  • 2

1 Answers1

0

I don't know what "randomly generated" means. But the first thing that comes to my mind is to set a WebViewClient and override shouldOverrideUrlLoading:

webView.setWebViewClient(new WebViewClient() {

    @Override
    public boolean shouldOverrideUrlLoading(WebView view, String url) {

        if (url.endsWith(".pdf") == true) {

             view.loadUrl("http://docs.google.com/gview?embedded=true&url=" + url);
             return true;
        }
        return false;
    }
});

Some more info in this thread.

Community
  • 1
  • 1
A.D.
  • 1,412
  • 2
  • 19
  • 37
  • Thank you for your reply. 'dynamic' is the word I should have used. – Abdab Feb 08 '17 at 20:22
  • The link does not end in ".pdf". I was thinking about embedding a download manager in the webview – Abdab Feb 08 '17 at 20:24
  • Ok, but at the end of the day the WebView will receive a resource to load. Try to override the onLoadResource method in the WebViewClient and try to act accordingly in it: https://developer.android.com/reference/android/webkit/WebViewClient.html#onLoadResource(android.webkit.WebView, java.lang.String) – A.D. Feb 08 '17 at 20:38