从webview下载后,下载管理器未在Gallery中显示文件

时间:2016-03-27 07:41:25

标签: java android url webview android-download-manager

我想从我的webview下载图片,收到通知并下载文件,但是当我去Gallery时,文件就不存在了。我做错了什么...... ??

        DownloadManager.Request request = new DownloadManager.Request(Uri.parse(geturl));
        request.setTitle("File Download");
        request.setDescription("File is being downloaded...");
        request.allowScanningByMediaScanner();
        request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED);
        String nameOfFile = URLUtil.guessFileName(geturl, null, MimeTypeMap.getFileExtensionFromUrl(geturl));

        request.setDestinationInExternalFilesDir(this,Environment.DIRECTORY_DCIM,nameOfFile);
        DownloadManager manager = (DownloadManager)getApplication().getSystemService(Context.DOWNLOAD_SERVICE);
        manager.enqueue(request);

虽然geturl是Override url,我通过它获取图像的url。

        public boolean shouldOverrideUrlLoading(WebView view, String url) {
        //Get url for downloading
        geturl = url;
        return true;
    }

0 个答案:

没有答案