android下载管理器返回STATUS_SUCCESSFUL以进行不成功的下载

时间:2014-07-21 07:40:55

标签: android

BroadcastReceiver receiver = new BroadcastReceiver() {
    @Override
    public void onReceive(Context context, Intent intent) {
        String action = intent.getAction();
        if (DownloadManager.ACTION_DOWNLOAD_COMPLETE.equals(action)) {
            long downloadId = intent.getLongExtra(
                    DownloadManager.EXTRA_DOWNLOAD_ID, 0);
            Query query = new Query();
            query.setFilterById(enqueue);
            Cursor c = dm.query(query);
            if (c.moveToFirst()) {
                int columnIndex = c
                        .getColumnIndex(DownloadManager.COLUMN_STATUS);
                context.unregisterReceiver( this );
                if (DownloadManager.STATUS_SUCCESSFUL == c
                        .getInt(columnIndex)) {

                    Toast.makeText(mContext,
                            "download complete ",
                            Toast.LENGTH_SHORT).show();
                }
            }
        }
    }
};

DownloadManager.STATUS_SUCCESSFUL == c.getInt(columnIndex)for underccessable

toast会因下载失败而被执行。我需要单独获取不成功下载的状态

0 个答案:

没有答案