-1

When I try to download files with asterisks in their names the downloads fail. The downloads work fine with files that don't have asterisks, and I know that it is using the correct path. The downloads just seems to stop right after starting. Do you guys have any ideas?

DownloadManager.Request request = new DownloadManager.Request(Uri.parse(Blahblahblah.com/asdf/filewithasaterisk));
request.setTitle(NameOfmp3File);
request.setDescription("File is being downloaded.....");
request.allowScanningByMediaScanner();
request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE);
request.setDestinationInExternalFilesDir(getApplicationContext(), Environment.DIRECTORY_MUSIC, mp3fileName);
request.setVisibleInDownloadsUi(false);

DownloadManager manager = (DownloadManager) getSystemService(Context.DOWNLOAD_SERVICE);
manager.enqueue(request);
MJDude
  • 73
  • 10
  • 2
    Tried escaping the asterisk? – Dave Feb 17 '16 at 21:26
  • @Dave What do you mean by that? I'm rather new to Programming. Are you saying to take out the asterisk and put it in right before downloading? – MJDude Feb 17 '16 at 21:27
  • It would be much easier to give you a definitive answer if you provided a real URL, rather than a URL that does not actually have an asterisk (plain or encoded). Beyond that, as others have noted, asterisks are reserved characters in a URL and have to be [percent-encoded](https://en.wikipedia.org/wiki/Percent-encoding). – CommonsWare Feb 17 '16 at 21:28
  • I appreciate your feedback, but I would rather not include the URL unless it is necessary. Is there a difference between percent-encoding and URLEncoding? – MJDude Feb 17 '16 at 21:31
  • Suggest you look at URLEncoding, give it a string that has an asterisk, see what output you get. Assuming the remote file contains an asterisk in the name, you should be fine. If you want to download multiple files, this isn't the way to do it. – Dave Feb 17 '16 at 21:33
  • Why the down-vote? Because I didn't include a real URL? – MJDude Feb 17 '16 at 21:34
  • I'm not having any luck with URLEncoding. I've been reading and it seems to say that it doesn't even replace the asterisks. Any other ideas as to why the download cancels? – MJDude Feb 17 '16 at 22:18

1 Answers1

0

Alright, I figured out what was wrong (kinda).

I couldn't figure out what was wrong with what I was doing. Everything I was reading said that URLEncoder didn't replace asterisks. I had been testing on an emulator so I though it may be an emulator issue, so I tried on a real device. This solved the problem... Phew!

Thanks for your help.

MJDude
  • 73
  • 10