Search code examples
javaandroidandroid-download-managerdownload-manager

Downloading files with asterisks in their names Android Java


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);

Solution

  • 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.