I made a program that downloads some files and then plays them. The program cannot play files if they have not been downloaded. I have blocked button play. How do I know when files have been downloaded to unlock the button?
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();
}
}
}
you will need to register an
BroadcastReceiverforDownloadManager.ACTION_DOWNLOAD_COMPLETEAction and enable button when download complete Action fire from Downloadnamager as:you can see this example for enable/disable button when download complete :
https://github.com/commonsguy/cw-android/blob/master/Internet/Download/src/com/commonsware/android/download/DownloadDemo.java