无法在WebView中打开本地PDF,在android中显示白屏

时间:2016-10-19 09:42:52

标签: android android-layout android-webview

webview在加载本地pdf时显示白屏 enter image description here

WebView webView = (WebView)findViewById(R.id.documentView);
        webView.invalidate();
        webView.getSettings().setJavaScriptEnabled(true);
        webView.getSettings().setLoadWithOverviewMode(true);
        webView.getSettings().setUseWideViewPort(true);
        webView.loadData(path.toString(),"application/pdf", "UTF-8"

);

请帮帮我。

1 个答案:

答案 0 :(得分:0)

试试这个

String localPath = path.toString();
 localPath  = localPath.replace(" ", "%20").trim();

并像这样使用

WebView webView = (WebView)findViewById(R.id.documentView);
        webView.invalidate();
        webView.getSettings().setJavaScriptEnabled(true);
        webView.getSettings().setLoadWithOverviewMode(true);
        webView.getSettings().setUseWideViewPort(true);
        webView.loadData("file:///"+localPath,"application/pdf", "UTF-8");