我正在尝试从Android应用程序的自定义文件夹中的webview下载图像。到目前为止,我只能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/data/com.abc.xyz/
是否有任何方法可以直接在内部存储(在根目录下)下创建文件夹?
File direct = new File(Environment.getExternalStorageDirectory()+"folder_name");
if(!direct.exists()) {
if(direct.mkdir());
}
尝试这个
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);
File folder = new File("/storage/emulated/0/Folder_Name");
if (!folder.exists()) {
folder.mkdirs();
System.out.println("Directory created");
} else {
System.out.println("Directory is not created");
}
request.setDestinationInExternalPublicDir("Folder_Name","Wallpaper.jpg");
DownloadManager dm = (DownloadManager) getSystemService(DOWNLOAD_SERVICE);
dm.enqueue(request);
}
});
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句