Android下载管理器失败错误

时间:2014-12-18 06:09:48

标签: android download

我一直在为特定的网址面对这个问题。每当我尝试使用android管理器下载文件时,我都会收到下载失败的错误。当我尝试与其他下载管理器相同的链接时说ES File Downloader,它运行正常。

这是我从URI下载的代码。

try{
    uri = Uri.parse(urls.get(countLinks));
    }catch(Exception e)
    {
        Log.d("Caught inside uri", e.toString());
    }

这里的下载管理器

Toast.makeText(getApplicationContext(), "Download Started", Toast.LENGTH_SHORT).show();;
            DownloadManager.Request songDownload = new DownloadManager.Request(uri);
            songDownload.setTitle(title);
            songDownload.setDescription("Simple Mp3 Downloader...");
            songDownload.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED);
            songDownload.setDestinationInExternalPublicDir(Environment.DIRECTORY_MUSIC, (title+".mp3") );
            songDownload.allowScanningByMediaScanner();
            DownloadManager dm = (DownloadManager) getSystemService(Context.DOWNLOAD_SERVICE);
            dm.enqueue(songDownload);

在此过程中,logcat中没有显示错误。但下载管理器显示不成功。  :Here is a sample link

2 个答案:

答案 0 :(得分:7)

好吧,我自己想出来了,我不得不用%20替换url中的空格并且它有效。我建议使用URLEncoder。

String s = url.replaceAll(" " , "%20");
Uri link = Uri.parse(s);

答案 1 :(得分:-2)

缩短您要下载的文件的名称

not ok(filename_123123123123123123123123123131.mp3)

ok(file_name_001.mp3)
相关问题