Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pdf sometimes not loading with google embedded viewer on Android

I am using the google docs pdf embedded viewer in my android app to display my pdfs. Sometimes the viewer doesn't load my file even though most of the time it does and it's pretty random when it doesn't.

I generate the url with "https://docs.google.com/viewer?embedded=true&url=" + myUrl.

And after that I load the webview :

    showLoader()
    web_view.settings.javaScriptEnabled = true
    web_view.clearCache(true)
    web_view.webViewClient = object : WebViewClient() {
        override fun onPageFinished(view: WebView?, url: String?) {
            hideLoader()
        }

        override fun shouldOverrideUrlLoading(view: WebView?, request: WebResourceRequest?): Boolean {
            web_view.loadUrl(url)
            return true
        }

        override fun onReceivedSslError(view: WebView, handler: SslErrorHandler, error: SslError) {
            println("before handler")
            handler.proceed()
            println("after handler")
        }
    }

    web_view.loadUrl(url)

I tried to proceed if I encounter any sslError, to override urlLoading but none of this resolved my problem.

To test here is one of the url which doesn't always load :

http://docdif.fr.grpleg.com/general/MEDIAGRP/NP-FT-GT/LE10061AA.pdf

One thing I tried too is show the url when display on my app and when it doesn't load on my viewer it blocks too on my navigator. But if I reload the page it does charge.

Any idea what the bug might be?

like image 551
Florian Saurs Avatar asked Dec 03 '22 19:12

Florian Saurs


1 Answers

Try this:

public void onPageFinished(WebView view, String url) {
    if (view.getTitle().equals(""))
        view.reload();
}

I hope that it can help you!

like image 177
Michelangelo Pucci Avatar answered Dec 06 '22 11:12

Michelangelo Pucci