It seems, DownloadManager does not correctly parse URL's with international characters in them.
private DownloadManager mTestDl;
public void downloadTest() {
mTestDl = (DownloadManager) getSystemService(Context.DOWNLOAD_SERVICE);
BroadcastReceiver br = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
Long referenceId = intent.getLongExtra(DownloadManager.EXTRA_DOWNLOAD_ID, -1);
DownloadManager.Query q = new DownloadManager.Query();
q.setFilterById(referenceId);
Cursor c = mTestDl.query(q);
if (!c.moveToFirst()) {
Log.i(TAG, "No downloaded file");
}
else {
c.getString(c.getColumnIndex(DownloadManager.COLUMN_LOCAL_URI));
for (String cn : c.getColumnNames()) {
String value = c.getString(c.getColumnIndex(cn));
int intValue = c.getInt(c.getColumnIndex(cn));
Log.i(TAG, "XColumn: " + cn + ". Value: " + value + ". int value: " + intValue);
}
}
}
};
registerReceiver(br, new IntentFilter(DownloadManager.ACTION_DOWNLOAD_COMPLETE));
Uri uri = Uri.parse("http://media.sample.com/video/[요기요]_11월_냠냠냠.mp4");
DownloadManager.Request request = new DownloadManager.Request(uri);
long dlid = mTestDl.enqueue(request);
Log.v(TAG, "download ID: " + dlid);
}
And the result is:
XColumn: _id. Value: 4141. int value: 4141
XColumn: local_filename. Value: null. int value: 0
XColumn: mediaprovider_uri. Value: null. int value: 0
XColumn: destination. Value: 2. int value: 2
XColumn: title. Value: . int value: 0
XColumn: description. Value: . int value: 0
XColumn: uri. Value: http://media.sample.com/video/[요기요]_11월_냠냠냠.mp4. int value: 0
XColumn: status. Value: 403. int value: 16
XColumn: hint. Value: null. int value: 0
XColumn: media_type. Value: null. int value: 0
XColumn: total_size. Value: -1. int value: -1
XColumn: last_modified_timestamp. Value: 1446747064114. int value: -656914638
XColumn: bytes_so_far. Value: 0. int value: 0
XColumn: allow_write. Value: 0. int value: 0
XColumn: local_uri. Value: content://downloads/my_downloads/4141. int value: 0
XColumn: reason. Value: placeholder. int value: 403
Generally, HTTP status 403 is meant to be "unauthorized access". In this case though the hosting is Amazon S3 which gives 403 when trying to list contents of the folder. So, the assumption is that the URL is incorrect.
Does DownloadManager support downloading files with international names?
EDIT: title
Answering my own question the download succeeds if encoding the name of the file in the URL using URLEncoder: Switch this line:
Uri uri = Uri.parse("http://media.sample.com/video/[요기요]_11월_냠냠냠.mp4");
to this one:
Uri uri = Uri.parse("http://media.sample.com/video/" + URLEncoder.encode("[요기요]_11월_냠냠냠.mp4", "UTF-8"));
Now the file is downloaded successfully. I was able to debug this only using proxy server capturing HTTP requests. No hints were given by DownloadManager.