나는 아이템으로 채워진 ListView
입니다. 이 항목들은 해당 파일을 클릭하여 다운로드 할 수있는 파일을 나타냅니다. 항목을 클릭하면 download manager
이 시작되고 내가 만든 디렉토리에 파일이 다운로드됩니다.Android에서 한 번에 하나씩 다운로드 관리자 다운로드 파일을 만드시겠습니까?
파일을 다운로드하는 중에 불확실한 progress bar
(로딩 휠)이 목록의 해당 항목에 표시됩니다.
내 문제는 : 항목을 클릭하면 첫 번째 항목 클릭, 두 번째 항목 클릭, 다섯 번째 항목 클릭 등 ...)을 클릭했을 때 로딩 휠 (숨기기)을 인식하기 때문에 나는 원하지 않는다. download manager
은 동시에 여러 파일을 다운로드합니다.
: 큰 파일을 클릭 한 다음 목록의 작은 파일을 클릭하면 작은 파일을 다운로드하기 전에 큰 파일을 완전히 다운로드해야합니다.
이 방법이 있습니까?
편집 : 여기
y
, z
및 ld
가 시작 부분에서 0
로 설정되어 내 코드입니다.
// Loader of the clicked item is made visible
loader[z].setVisibility(View.VISIBLE);
// Construction of the URL
SharedPreferences codeSaveUrl = getSharedPreferences(PREFS_TEXT,Context.MODE_PRIVATE);
url2 = codeSaveUrl.getString("defaut", ""); // Organization code
uri = url10 + url2 + "&file=" + udl ;
// URL parse to URI
Uri myuri = Uri.parse(uri);
// Enqueue file to downloads, with notification. Storage of download id in a table
lastDownload[ld] = mgr.enqueue(new DownloadManager.Request(myuri)
.setAllowedNetworkTypes(DownloadManager.Request.NETWORK_WIFI |DownloadManager.Request.NETWORK_MOBILE)
.setAllowedOverRoaming(false)
.setTitle(udl + ".pdf")
.setDescription("Téléchargement en cours")
.setDestinationInExternalPublicDir("/Protocols/", (udl+".pdf"))
.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE));
// Increment variables for next downloads
ld=ld+1;
z=z+1;
방송 수신기 : 돕는
// Broadcast Receiver called when a download is finished
BroadcastReceiver onComplete = new BroadcastReceiver() {
public void onReceive(Context context, Intent intent) {
// referenceId is the download's id for which the method is called
long referenceId = intent.getLongExtra(DownloadManager.EXTRA_DOWNLOAD_ID, -1);
// If y (=0 at the beginning) is inferior to the number of downloads
if(y <ld){
// If the id of the download corresponds to the one for which the method is called
if(lastDownload[y] == referenceId){
// We define a cursor depending on the id
Cursor c = mgr.query(new DownloadManager.Query().setFilterById(lastDownload[y]));
if(c.moveToFirst()){
// Download status recovery
int x = c.getInt(c.getColumnIndex(DownloadManager.COLUMN_STATUS));
switch(x){
// If download is paused, pending or running, we do nothing
case DownloadManager.STATUS_PAUSED:
case DownloadManager.STATUS_PENDING:
case DownloadManager.STATUS_RUNNING:
break;
// If file has successfully been downloaded, loader is hidden
case DownloadManager.STATUS_SUCCESSFUL:
loader[y].setVisibility(View.GONE);
// Increment y to go to next download
y=y+1;
break;
// If download failed, it is retried
case DownloadManager.STATUS_FAILED:
//TODO: retry download
break;
}
}
}
}
}
};
감사합니다.