2

I am showing a pdf with Google docs in webview. I am using url from Google Drive. I tried so many formats from Google Drive, But have no luck. My Url link as below

https://drive.google.com/drive/u/0/folders/0Bxd-5Rffh6BufmNiYS16NFZKN2JmYzd3TjgtWmxLeEZ2SnlMa2l2RDhmYlNyTDgtUXZOdnM 

My Activity class as foloows"

public class FormWebViewActivity extends CustomWindow { int value; static String POSITION_ID = "position"; // WebView webView; ProgressBar progressBar_webview; @SuppressWarnings("deprecation") @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); try { WebView webView = new WebView(FormWebViewActivity.this); webView.getSettings().setJavaScriptEnabled(true); webView.getSettings().setPluginState(PluginState.ON); String pdfURL = "https://drive.google.com/drive/u/0/folders/0Bxd-5Rffh6BufmNiYS16NFZKN2JmYzd3TjgtWmxLeEZ2SnlMa2l2RDhmYlNyTDgtUXZOdnM"; // https://drive.google.com/file/d/0Bxd-5Rffh6BuSlhnTHJsMW5Hclk/view webView.setWebViewClient(new WebViewClient() { @Override public void onPageFinished(WebView view, String url) { super.onPageFinished(view, url); // progressBar_webview.setVisibility(View.GONE); } @Override public void onPageStarted(WebView view, String url, Bitmap favicon) { super.onPageStarted(view, url, favicon); // progressBar_webview.setVisibility(View.VISIBLE); } @Override public boolean shouldOverrideUrlLoading(WebView view, String url) { // view.loadUrl(url); return false; } }); webView.loadUrl("http://docs.google.com/gview?embedded=true&url=" + pdfURL); setContentView(webView); } catch (RuntimeException e) { e.printStackTrace(); } // WebView webView = new WebView(FormWebViewActivity.this); } 

}

But it shows only HTML code, not the actual PDF view. Am i putting wrong Google Drive URL? Or It's not possible to show from Google Drive.

Any free web hosting for PDF file will also be appreciated.

2 Answers 2

2

In addition to the @Derek Fung's answer, if your drive having a login session you may need to provide the session access as well.

But If you use the view only url the user is not propted to login to there google account.

Simply you can use like this::

 webView.loadUrl("https://docs.google.com/viewer?url="+ pdfURL); 
Sign up to request clarification or add additional context in comments.

3 Comments

i load the url successfully. But when scroll down , the pdf pages not loaded well. supose if a pdf has 10 page, then 1st or 2nd page load well. Rest of pages unloaded.
It's good to hear that now your able to load the pages/pdf, I think there was some problem with your pdf (or) some piece of code (may be).. So it is better to post another question with all your codes !!
I am trying this solution but my webview is returning blank and black after loading the new url, but putting the same url in a normal web browser works. Do you have any idea why?
1

The link you try to use requires authentication, it means that unless the webview has the login session, you cannot access the content probably.

You have to follow the link below and setup either as Anyone with the link or Public web access, please be reminded that the URL would be something else as well.

Edit:

forget to provide the link

https://support.google.com/drive/answer/2494886?hl=en

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.