So I download .mp3 songs from provided URLs using the following code:
private long DownloadData (Uri uri) {
long downloadReference;
// Create request for android download manager
downloadManager = (DownloadManager)getSystemService(DOWNLOAD_SERVICE);
DownloadManager.Request request = new DownloadManager.Request(uri);
request.setTitle("Data Download");
request.setAllowedNetworkTypes(DownloadManager.Request.NETWORK_WIFI |
DownloadManager.Request.NETWORK_MOBILE);
request.setDescription("Android Data download using DownloadManager.");
request.setDestinationInExternalFilesDir(DownloadSongActivity.this,
Environment.DIRECTORY_DOWNLOADS ,"doesn'twork.mp3");
downloadReference = downloadManager.enqueue(request);
return downloadReference;
}
I then attempt to give user access to these files in the app using the following code to get them
File path = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS).getAbsolutePath());
File[] downloadedFiles = path.listFiles();
if(downloadedFiles == null){
System.out.println("DownloadedFiles are null");
} else if(downloadedFiles.length == 0){
System.out.println("DownloadedFiles are empty");
} else{
System.out.println("DownloadedFiles are not empty");
}
However it seems that downloadedFiles always is null. Any suggestions. Here are some pictures for reference to
If I go to Files -> Downloads
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.