Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"no preview available" while viewing pdf in google docs in android webview

While opening pdf in webview in android with google doc links :-

webView.loadUrl("http://docs.google.com/gview&embedded=true&url=" + getIntent().getStringExtra(CONSTANT.pdfurl));

for some pdf

"no preview availbale"

happens in webview , and for some pdf it always happen , i know this question have been asked several times and have seen all the stackoverflow and internet but could not find any satisfactory explanation to it.

How to know when "no preview available" happens while viewing pdf in google docs and how to solve this problem, also

the progress bar stops automatically without showing any content sometimes

here is my full code of implementation :-

webView.getSettings().setJavaScriptEnabled(true);
webView.getSettings().setBuiltInZoomControls(true);

progressBar.setVisibility(View.VISIBLE);

webView.loadUrl("http://docs.google.com/gview&embedded=true&url=" + getIntent().getStringExtra(CONSTANT.pdfurl));

webView.setWebViewClient(new WebViewClient() {

            @Override
            public void onPageStarted(WebView view, String url, Bitmap favicon) {

                super.onPageStarted(view, url, favicon);
                progressBar.setVisibility(View.VISIBLE);

            }

            @Override
            public boolean shouldOverrideUrlLoading(WebView view, String url) {
                view.loadUrl(url);
                return false;
            }
            @Override
            public void onPageFinished(WebView view, String url) {
                // do your stuff here
                progressBar.setVisibility(View.GONE);
                webView.setVisibility(View.VISIBLE);
            }

            @Override
            public void onReceivedError(WebView view, int errorCode,
                                        String description, String failingUrl) {
                view.loadUrl("about:blank");
                Toast.makeText(getApplicationContext(), "Error occured, please check newtwork connectivity", Toast.LENGTH_SHORT).show();
                super.onReceivedError(view, errorCode, description, failingUrl);
            }

   });

One thing i know for sure is that in http website it happen more frequently than https website . How to resolve this issue ?

Is there any way to covert url to https from http without changing website ?

like image 690
gautam Avatar asked Oct 18 '22 01:10

gautam


1 Answers

check your pdf path may be it will null like (https://docs.google.com/gview?embedded=true&url=null)

Or use intent to open pdf I found it easy

Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(pdf_url));
startActivity(browserIntent);
like image 96
Ashish Chaugule Avatar answered Oct 20 '22 07:10

Ashish Chaugule