2013-11-24 36 views
2

我正在android下載。到目前爲止,我發現有異步任務或使用下載管理器來完成。問題是,我使用下載管理器來處理幾乎所有的網絡問題。唯一的問題是我想一次只下載一個文件。例如:一次只下載一個文件在android

有5個文件: ABCDE

如果我下載文件A,如果有任何文件(比如文件C)interupt,停止文件A的下載和啓動C,如果C光潔度只是恢復下載的A

但是好像當我取消文件A時,它會被刪除但不能恢復,我該如何解決這個問題?由於

private long startDownload(String url) { 
Uri DownloadUri = Uri.parse(url);  
String fileName = StorageUtils.getFileNameFromUrl(url); 
String destination = null; 

downloadManager = (DownloadManager) getSystemService(DOWNLOAD_SERVICE); 
DownloadManager.Request request = new DownloadManager.Request(
     DownloadUri); 

request.setAllowedNetworkTypes(DownloadManager.Request.NETWORK_WIFI | DownloadManager.Request.NETWORK_MOBILE); 
request.setAllowedOverRoaming(false); 

request.setTitle(fileName); 
request.setDescription("com.example.services"); 

if (StorageUtils.isSDCardPresent() 
     && StorageUtils.isSdCardWrittenable() 
     && StorageUtils.checkAvailableStorage()) { 
    destination = StorageUtils.SDCARD_ROOT; 
} 

try { 
    StorageUtils.mkdir(); 
} catch (IOException e) { 
    e.printStackTrace(); 
} 

request.setDestinationInExternalPublicDir(destination, fileName); 
downloadReference = downloadManager.enqueue(request); 

Log.d("Downloader","Start download manager: " + destination + fileName); 
return downloadReference; 

}

+0

如果你要更多的詳細信息添加到您的帖子,只需編輯而不是提出另一個問題。 – hichris123

回答