DownloadManager下载失败

时间:2017-11-22 09:31:56

标签: java android

无法从此链接http://31.186.48.72/media/audio/a_209353.mp3下载mp3文件 但可以从这个链接下载 https://www.androidtutorialpoint.com/wp-content/uploads/2016/09/AndroidDownloadManager.mp3使用android.app.DownloadManager。

Uri uri = Uri.parse(DOWNLOAD_FILE);
    Log.d("download", "downloading....");
    DownloadManager downloadManager = (DownloadManager) getSystemService(Context.DOWNLOAD_SERVICE);
    String fileName = "testmp3";
    DownloadManager.Request request = new DownloadManager.Request(uri);
    request.setTitle(fileName);
    request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED);
    request.allowScanningByMediaScanner();
    request.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS,"test.mp3");
    downloadManager.enqueue(request);

这是光标结果

_id=8
local_filename=null
mediaprovider_uri=null
destination=4
title=testmp3
description=
uri=http://31.186.48.72/media/audio/a_209353.mp3
status=403
hint=file:///mnt/sdcard/Download/test.mp3
media_type=null
total_size=-1
last_modified_timestamp=1511346244441
bytes_so_far=0
local_uri=null
reason=placeholder

3 个答案:

答案 0 :(得分:3)

您的第一个链接显示403错误,因此您无法下载

答案 1 :(得分:0)

下载管理器在服务器端有限制。

答案 2 :(得分:0)

状态(例如原因)是整数字段,而不是字符串。如我所见,reason = placeholder,您需要写原因的cursor.getInt(cursor.getColumnIndex(DownloadManager.COLUMN_REASON)),而不是getString,并在状态后写cursor.getInt(cursor.getColumnIndex(DownloadManager.COLUMN_STATUS))以获取状态应该会看到实际的错误原因,而不是403 http代码