首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >DownloadManager -如何获取Content-length头部信息?

DownloadManager -如何获取Content-length头部信息?
EN

Stack Overflow用户
提问于 2016-06-25 04:12:29
回答 1查看 457关注 0票数 0

我需要一些帮助:)。我有这样的代码:

代码语言:javascript
复制
    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)?

EN

回答 1

Stack Overflow用户

发布于 2016-06-25 05:04:09

你可以检查你的下载id的DownloadManager状态和错误。

  1. DownloadManager.ACTION_DOWNLOAD_COMPLETE
  2. 设置broadcast receiver检查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的所有状态代码

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/38021382

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档