我在应用程序中遇到拖曳问题。
1-我正在使用Android DownloadManager
下载在线文件,但它通过使用以下命令将所有文件下载到系统目录,即Download
目录
request.setDestinationInExternalPublicDir(Environment.DIRECTORY_PICTURES, "fileName");
现在,我想将文件下载到我自己的目录中,例如“New Folder”。如何实现。请在这方面帮助我,我将非常感谢。
2-如何检查SD卡是否可用?
最佳答案
使用这种方式:这里Dhaval_files是我的文件夹名称
public void file_download(String uRl) {
File direct = new File(Environment.getExternalStorageDirectory()
+ "/dhaval_files");
if (!direct.exists()) {
direct.mkdirs();
}
DownloadManager mgr = (DownloadManager) this.getSystemService(Context.DOWNLOAD_SERVICE);
Uri downloadUri = Uri.parse(uRl);
DownloadManager.Request request = new DownloadManager.Request(
downloadUri);
request.setAllowedNetworkTypes(
DownloadManager.Request.NETWORK_WIFI
| DownloadManager.Request.NETWORK_MOBILE)
.setAllowedOverRoaming(false).setTitle("Demo")
.setDescription("Something useful. No, really.")
.setDestinationInExternalPublicDir("/dhaval_files", "test.jpg");
mgr.enqueue(request);
}