Webview不加载PDF URL

时间:2018-12-15 19:31:21

标签: android android-webview

我有以下代码,但无法使用包含PDF文件的URL。

日志未显示任何类型的错误。

override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_webview)

        webview.settings.javaScriptEnabled = true
        webview.settings.allowFileAccessFromFileURLs = true
        webview.settings.allowUniversalAccessFromFileURLs = true
        webview.settings.allowContentAccess = true
        webview.settings.allowFileAccess = true
        webview.webViewClient = object : WebViewClient(){

            override fun onPageFinished(view: WebView, url: String) {
                Log.d("WEBVIEWWWWW", "onPageFinished")
            }

            /**
             * Notify the host application that the WebView will load the resource
             * specified by the given url.
             *
             * @param view The WebView that is initiating the callback.
             * @param url The url of the resource the WebView will load.
             */
            override fun onLoadResource(view: WebView, url: String) {}

            override fun onReceivedError(view: WebView, request: WebResourceRequest, error: WebResourceError) {
                super.onReceivedError(view, request, error)
                Log.d("WEBVIEWWWWW", "onReceivedError")
            }
        }

        webview.loadUrl("http://www.axmag.com/download/pdfurl-guide.pdf")
    }

0 个答案:

没有答案