如何从webview下载图像到Android中的自定义文件夹

问题描述 投票:0回答:1

我正在尝试从Webview的Android应用程序的自定义文件夹中下载图像。到目前为止,我只能使用以下代码下载Download文件夹中的文件。

DownloadManager.Request request = new DownloadManager.Request(Uri.parse(imgUrl));
request.allowScanningByMediaScanner();
request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED);
DownloadManager downloadManager = (DownloadManager) getActivity().getSystemService(DOWNLOAD_SERVICE);
downloadManager.enqueue(request);

是否可以将图像存储在其他文件夹(新创建的文件夹)中,而不是默认的Download文件夹中。实际上,我想在Android应用程序文件夹中下载图像,该文件夹将是私有的,用户无法通过文件管理器或其他应用程序访问。

android webview android-download-manager
1个回答
0
投票

尝试一下

mywebView.setDownloadListener(new DownloadListener() {

    public void onDownloadStart(String url, String userAgent, String contentDisposition, String mimetype, long contentLength) {

        Request request = new Request(Uri.parse(url));
        request.allowScanningByMediaScanner();

        request.setNotificationVisibility(
        DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED);

        request.setDestinationInExternalPublicDir(
        Environment.DIRECTORY_DOWNLOADS,    //Download folder
            "download");                        //Name of file


        DownloadManager dm = (DownloadManager) getSystemService(DOWNLOAD_SERVICE);

        dm.enqueue(request);  

    }
});
© www.soinside.com 2019 - 2024. All rights reserved.