2016-10-31 9 views
12

Possible duplicateAndroid DownloadManager.ERROR_FILE_ERROR

Ben Android DownloadManager kullanarak büyük zip dosyaları indirirken ediyorum. Tüm zip dosyalarının listesini gösteren bir liste görünümü ve kullanıcı indirmeye başlamak için öğeye dokunabilir. Bir seferde sadece bir öğe indirilebilir. Diğer indirme işlemi devam ederken yeni liste öğesi indirilmeye başladığında, önceki indirme kimliğini sıradan kaldırırım. Her şey iyi çalışıyor. Ama bazen LG g2 aygıt OS 5.0.2 üzerinde ERROR_FILE_ERROR alıyorum. i anında durduran bir dosya indirme başladığınızda O Huawei vb nexus 5, samsung s3, Note2 gibi diğer cihazlarda iyi çalışıyor

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); 

/nedeni DownloadManager.ERROR_FILE_ERROR başarısız oldu: İşte kodudur. Harici depolama dizinini temizlemeyi/temizlemeyi, ERROR_INSUFFICIENT_SPACE hatasını vb. Gidermeye çalıştım ama işe yaramadı. Herhangi bir yardım?

cevap

2

Bu biraz daha kurşun geçirmez olabilir:

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); 
}