我需要一些帮助:)。我有这样的代码:
public void downloadFile(Uri uri, String title, String description, String subDir) {
try {
DownloadManager.Request request = new DownloadManager.Request(uri);
request.setDescription(description).setTitle(title);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
request.allowScanningByMediaScanner();
//request.setVisibleInDownloadsUi(false); request.setAllowedNetworkTypes(DownloadManager.Request.NETWORK_MOBILE | DownloadManager.Request.NETWORK_WIFI);
request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED);
}
request.setDestinationInExternalFilesDir(DownloadDatabaseActivity.this, Environment.DIRECTORY_DOWNLOADS, subDir);
this._bDatabaseMngr = (DownloadManager) getSystemService(Context.DOWNLOAD_SERVICE);
_bDatabaseMngrId = this._bDatabaseMngr.enqueue(request);
/*** HERE IS MY QUESTION - BEGIN ***/
Log.v(TAG, "File size (HTTP Content-length header): " + HOW_TO_GET_CONTENT_LENGTH_HEADER_FROM_DOWNLOADMANAGER);
if(HOW_TO_GET_CONTENT_LENGTH_HEADER_FROM_DOWNLOADMANAGER < getFreeSpace()) {
// I'd like to handle it ;)
}
/*** HERE IS MY QUESTION - END ***/
} catch (Exception e) {
Log.e(TAG, e.getMessage());
}
}我想要实现的是HTTP报头中的Content-length值?有什么想法(最低api级别16)?
发布于 2016-06-25 05:04:09
你可以检查你的下载id的DownloadManager状态和错误。
DownloadManager.ACTION_DOWNLOAD_COMPLETE onReceive中的状态新查询= DownloadManager.Query DownloadManager.Query();
query.setFilterById(id);Cursor =查询(downloadManager.query);if(cursor.moveToFirst()){ int columnIndex = cursor.getColumnIndex(DownloadManager.COLUMN_STATUS);int columnIndex= cursor.getInt(columnIndex);int columnReason =query int columnIndex=cursor.getInt(ColumnIndex);
}
您可以找到here的所有状态代码
https://stackoverflow.com/questions/38021382
复制相似问题