質問

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?

役に立ちましたか?

解決

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.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top