Can you wait for the DownloadManager to finish only your own downloads? To achieve this, you can save handles of your downloads with something like this:
List<Long> downloadIds = new ArrayList<>();
downloadIds.add(downloadManager.enqueue(request));
Then you can query the downloadManager this way:
Query q = new Query();
long[] ids = new long[downloadIds.size()];
int i = 0;
for (Long id: downloadIds) ids[i++] = id;
q.setFilterById(ids);
Cursor c = downloadManager.query(q);
Set<Long> res = new HashSet<>();
int columnStatus = c.getColumnIndex(DownloadManager.COLUMN_STATUS);
while (c.moveToNext()) {
int status = c.getInt(columnStatus);
if (status != DownloadManager.STATUS_FAILED && status != DownloadManager.STATUS_SUCCESSFUL) {
// There is at least one download in progress
}
}
c.close();
Bear in mind that this can work if you're interested only in your own downloads, not every possible download that can occur system wide.
Hope this helps.