Reputation: 484
I'm trying to use android's own DownloadManager and it works perfectly on API 18+ but the same code fails (STATUS_FAILED) with reason ERROR_UNKNOWN almost as soon as I enqueue it on API 17 phones. here's my code
Context context = MyApplication.getSharedContext();
DownloadManager.Request request = new DownloadManager.Request(Uri.parse(url));
request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE).setTitle(notiTitle).
setVisibleInDownloadsUi(false);
File file = new File(Environment.getExternalStorageDirectory().getAbsolutePath()+File.separator+fileName);
request.setDestinationUri(Uri.fromFile(file));
DownloadManager manager = (DownloadManager) context.getSystemService(Context.DOWNLOAD_SERVICE);
manager.enqueue(request) ;
Upvotes: 2
Views: 1171
Reputation: 484
After days of struggling with this problem , I accidentally discovered the root of the issue. the urls to downloads which were fetched from a server had "[" and "]" characters. they posed no problem in API 18+ DownloadManager but in API 17 the download fails with ERROR_UNKNOWN with no information as to why whatsoever. replacing them with %5B and %5D respectively solved the problem.
url = url.replace("[","%5B").replace("]","%5D");
Upvotes: 2