我正在尝试从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应用程序文件夹中下载图像,该文件夹将是私有的,用户无法通过文件管理器或其他应用程序访问。
尝试一下
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);
}
});