mozilla pdf.js webview ask for internet

天大地大妈咪最大 提交于 2019-12-24 14:35:04

问题


I'm using mozilla/pdf.js to display a pdf in a webview in my Android application. The framework doesn't need any internet connection to render the pdf. If downloaded the .js file and everything so it can use that. Still every time I want to open a new pdf Android opens the default browser with the wireless settings dialog.

After closing the app and opening it again the PDF is rendered. My internet connection both wireless as data is disabled, so it doesn't need anything of internet, I'm sure about that.

How can I solve this that the webview ask for internet?

This is my code:

    webView = (WebView) findViewById(R.id.webViewWindow);
    WebSettings settings = webView.getSettings();
    settings.setJavaScriptEnabled(true);
    settings.setAllowFileAccessFromFileURLs(true);
    settings.setAllowUniversalAccessFromFileURLs(true);
    settings.setBuiltInZoomControls(true);
    webView.setWebChromeClient(new WebChromeClient());
    webView.loadUrl("file:///android_asset/pdfviewer/index.html");

I also found on the Android dev page that the setAllowFileAccessFromFileURL and the setAllowUniversalAccessfromFileURLS are both not necessary. You should use only the universal one, is this true or do I understand this incorrectly?


回答1:


I solved this problem by:

webView.setWebViewClient(new WebViewClient() {
    public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
        Log.d("Debug","Error");
    }
});

Then you have control about the error and you can like me choose to do nothing.



来源:https://stackoverflow.com/questions/22757425/mozilla-pdf-js-webview-ask-for-internet

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!