2016-10-31 4 views
12

Possible duplicate안드로이드 DownloadManager.ERROR_FILE_ERROR

나는 안드로이드 DownloadManager를 사용하여 큰 zip 파일을 다운로드하고 있습니다. 나는 모든 zip 파일의 목록을 보여주는 listview를 가지고 있으며, 사용자는 다운로드를 시작하기 위해 항목을 탭할 수있다. 한 번에 하나의 항목 만 다운로드 할 수 있습니다. 다른 다운로드가 진행되는 동안 새 목록 항목이 다운로드되기 시작하면 이전 다운로드 ID를 대기열에서 제거합니다. 모든 것이 잘 작동합니다. 하지만 때로는 ERROR_FILE_ERROR LG g2 장치 OS 5.0.2에지고 있습니다. 내가 그것을 즉시 중지 파일을 다운로드하기 시작하면 그것은 화웨이 등 넥서스 5, 삼성 S3, 주 2를 포함하여 다른 장치에서 잘 작동

Uri uri = Uri.parse(path); 
DownloadManager.Request request = new DownloadManager.Request(uri); 
request.setAllowedNetworkTypes(DownloadManager.Request.NETWORK_WIFI | DownloadManager.Request.NETWORK_MOBILE); 
request.setAllowedOverRoaming(false); 
request.setVisibleInDownloadsUi(false); 

String localStorageBasePath = FileUtils.zipDirectory(context).getAbsolutePath() + File.separator + fileName; 
Uri localStorageBasePathUri = Uri.fromFile(new File(localStorageBasePath)); 
request.setDestinationUri(localStorageBasePathUri); 
Long downloadId = downloadManager.enqueue(request); 

/이유 DownloadManager.ERROR_FILE_ERROR 실패했습니다 여기에 코드입니다. 내가/ERROR_INSUFFICIENT_SPACE 오류 등이 아니라 작동하지 않았는지 확인, 외부 저장 디렉토리를 청소/청소하려고했습니다. 어떤 도움이 필요합니까?

답변

2

이 좀 더 방탄 수 있습니다 :

public void file_download(String path, String filename) 
{ 
    Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS).mkdirs(); 

    Uri uri = Uri.parse(path); 
    DownloadManager.Request request = new DownloadManager.Request(uri); 
    request.setDescription(""); 
    request.setTitle(""); 
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) 
    { 
     request.allowScanningByMediaScanner(); 
     request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED); 
    } 
    request.setAllowedNetworkTypes(DownloadManager.Request.NETWORK_WIFI | DownloadManager.Request.NETWORK_MOBILE); 
    request.setAllowedOverRoaming(false); 
    request.setVisibleInDownloadsUi(false); 
    request.setDestinationInExternalFilesDir(context, DIRECTORY_DOWNLOADS, fileName); 

    //String localStorageBasePath = FileUtils.zipDirectory(context).getAbsolutePath() + File.separator + fileName; 
    //Uri localStorageBasePathUri = Uri.fromFile(new File(localStorageBasePath)); 
    //request.setDestinationUri(localStorageBasePathUri); 
    DownloadManager downloadManager = (DownloadManager) this.getSystemService(Context.DOWNLOAD_SERVICE); 
    Long downloadId = downloadManager.enqueue(request); 
}