2014-02-14 2 views
1

파일 다운로드를 위해 다운로드 관리자를 사용 중입니다. 다운로드 진행 상황을 표시하려면 파일 크기가 필요합니다. 다음 코드를 사용하면 파일 크기가 -1이됩니다. 올바른 파일 크기는 어떻게 얻습니까?안드로이드 다운로드 관리자 파일 크기가 제대로 맞지 않습니다.

DownloadManager.Query q = new DownloadManager.Query(); 
q.setFilterById(downloadmanagerid1); 
Cursor cursor = dm.query(q); 
if (cursor.moveToFirst()) { 

FileDownloading.setDownload_status(cursor.getInt(cursor.getColumnIndex(DownloadManager.COLUMN_STATUS))); 
long fileSize = cursor.getLong(cursor.getColumnIndex(DownloadManager.COLUMN_TOTAL_SIZE_BYTES)); 
long bytesDL = cursor.getLong(cursor.getColumnIndex(DownloadManager.COLUMN_BYTES_DOWNLOADED_SO_FAR)); 
Log.e("file size getting ",""+fileSize);  
FileDownloading.setDownload_progress((int) ((bytesDL * 100.0f)/fileSize)); 

} 
else { 
FileDownloading.setDownload_progress(0); 
FileDownloading.setDownload_status(-1); 
} 
cursor.close(); 

답변

0

이 방법을 좋아합니까 :

while ((count = input.read(data)) != -1) { 
       total += count; 
       // publishing the progress.... 
       // After this onProgressUpdate will be called 
       // publishProgress("" + (int) ((total * 100)/lenghtOfFile)); 

       // writing data to file 
       progressBar.setProgress((int) ((total * 100)/lenghtOfFile)); 
       output.write(data, 0, count); 
      } 
+0

을 다운로드 관리자를 사용할 수 있습니까? – Anu