【问题标题】:Android download manager unsuccessful errorAndroid下载管理器不成功的错误
【发布时间】:2017-01-30 21:22:20
【问题描述】:

我一直面临特定网址的这个问题。每当我尝试使用 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

【问题讨论】:

    标签: android download


    【解决方案1】:

    好吧,我自己想通了,我必须将 url 中的空格替换为 %20 并且它有效。不过我建议使用 URLEncoder。

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

    【讨论】:

      【解决方案2】:

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

      not ok(filename_123123123123123123123123123131.mp3)
      
      ok(file_name_001.mp3)
      

      【讨论】:

        猜你喜欢
        • 2012-05-20
        • 1970-01-01
        • 2020-04-05
        • 1970-01-01
        • 2016-07-09
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多