无法从webview android查看下载的文件

时间:2017-02-21 05:28:54

标签: android webview android-download-manager

我正在使用以下代码从webview下载文件,

if(!url.contains("sharepoint.com")) {
            if (url.endsWith(".pdf") || url.endsWith(".PDF") ||
                    url.endsWith(".xls") || url.endsWith(".xlsx") ||
                    url.endsWith(".XLSX") || url.endsWith(".XLS") ||
                    url.endsWith(".txt") || url.endsWith(".TXT") || url.endsWith(".doc") || url.endsWith(".DOC") ||
                    url.endsWith(".docx") || url.endsWith(".DOCX") || url.endsWith(".ppt") || url.endsWith(".PPT") ||
                    url.endsWith(".pptx") || url.endsWith(".PPTX") || url.endsWith(".rtf") || url.endsWith(".RTF") ||
                    url.endsWith(".csv") || url.endsWith(".CSV")) {
                mWebView.setDownloadListener(new DownloadListener() {
                    public void onDownloadStart(String url, String userAgent,
                            String contentDisposition, String mimetype,
                            long contentLength) {
                        DownloadManager.Request request = new DownloadManager.Request(
                                Uri.parse(url));
                        final String fileName= URLUtil.guessFileName(url,contentDisposition,mimetype);
                        Log.d("ss","fileName:"+fileName);
                        request.allowScanningByMediaScanner();
                        request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED); //Notify client once download is completed!
                        request.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS, fileName);
                        DownloadManager dm = (DownloadManager) getSystemService(DOWNLOAD_SERVICE);
                        dm.enqueue(request);
                        Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT); //This is important!
                        intent.addCategory(Intent.CATEGORY_OPENABLE); //CATEGORY.OPENABLE
                        intent.setType("*/*");//any application,any extension
                        startActivity(intent);
                    }
                });
            }
        }

我的网址是“http://dev.citylaneapp.com/demo/wp-content/uploads/sites/6/2017/02/InfoChantier.pdf

但我无法查看我下载的文件。你能建议我查看下载的文件吗?

0 个答案:

没有答案
相关问题