我一直面临着特定网址的这个问题.每当我尝试使用android管理器下载文件时,我都会收到下载失败的错误.当我尝试与其他下载管理器相同的链接时说ES File Downloader,它运行正常.
这是我从URI下载的代码.
try{
uri = Uri.parse(urls.get(countLinks));
}catch(Exception e)
{
Log.d("Caught inside uri", e.toString());
}
Run Code Online (Sandbox Code Playgroud)
和下载管理器在这里
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);
Run Code Online (Sandbox Code Playgroud)
在此过程中,logcat中没有显示错误.但下载管理器显示不成功.:这是一个示例链接
好吧,我自己想出来了,我不得不用%20替换url中的空格并且它有效.我建议使用URLEncoder.
String s = url.replaceAll(" " , "%20");
Uri link = Uri.parse(s);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3136 次 |
| 最近记录: |