下载manager下载失败



无法从此链接下载mp3文件http://31.186.48.72/media/media/audio/a___209353.mp3但是可以从此链接下载https://www.androidtiorpoint.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

您的第一个链接是给出403错误,因此您无法下载

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

状态(例如原因)是整数字段,而不是字符串。如我所见,原因=占位符,并且您需要写cursor.getInt(cursor.getColumnIndex(downloadmanager.column_reason)),而不是getTring,cursor.getInt(cursor.getColumnIndex(downloctManager.column_status))应该看到实际错误原因,这将不是403 HTTP代码

最新更新