我制作了一个下载一些文件然后播放它们的程序。如果文件尚未下载,程序将无法播放文件。我阻止了按钮播放。我如何知道何时下载了文件以解锁按钮?
private DownloadManager manager;
public void downloadFiles() {
ArrayList<HashMap<String, String>> pl = getPlayList();
ArrayList<String> fileListForDownload = xm.getDownloadList(pl);
for (int i=0; i<fileListForDownload.size(); i++) {
Log.i("tag", fileListForDownload.get(i));
String url = BASE_URL + fileListForDownload.get(i);
DownloadManager.Request request = new DownloadManager.Request(Uri.parse(url));
request.setDescription(fileListForDownload.get(i));
request.setTitle(fileListForDownload.get(i));
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
request.allowScanningByMediaScanner();
request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED);
}
request.setDestinationInExternalPublicDir(DIRECTORY_FOR_MUSIC, fileListForDownload.get(i));
// get download service and enqueue file
try {
downloadReference = manager.enqueue(request);
}
catch (Exception e) {
e.printStackTrace();
}
}
}