好的,我正在下载文件(图像)。下载完成后,我想发送一条带有图像本地 URI 的消息。但是 20% 的时间我得到这个:
6-01 18:46:39.900: INFO/DownloadManager(412): Initiating request for download 605
06-01 18:46:39.910: WARN/DownloadManager(412): Aborting request for download 605: Trying to resume a download that can't be resumed
06-01 18:46:39.910: INFO/ololo(2826): Okay, I'll broadcast.
06-01 18:46:39.990: WARN/ImageView(2826): Unable to open content: content://downloads/my_downloads/605
java.io.FileNotFoundException: No filename found.
at android.database.DatabaseUtils.readExceptionWithFileNotFoundExceptionFromParcel(DatabaseUtils.java:145)...
06-01 18:46:39.990: INFO/System.out(2826): resolveUri failed on bad bitmap uri: content://downloads/my_downloads/605
06-01 18:46:39.990: INFO/ololo(2826): content://downloads/my_downloads/605 was set for android.widget.ImageView@408a2cf0
这是代码
Long downloadId = downloadIds.get(this);
if(downloadId == intent.getLongExtra(DownloadManager.EXTRA_DOWNLOAD_ID, -1)) {
DownloadManager.Query query = new DownloadManager.Query();
query.setFilterById(downloadId);
Cursor cursor = downloadManager.query(query);
if(cursor.moveToFirst()) {
switch (cursor.getInt(cursor.getColumnIndex(DownloadManager.COLUMN_STATUS))) {
case DownloadManager.STATUS_SUCCESSFUL : {
Log.i("ololo", "Okay, I'll broadcast.");
// Broadcasting
break;
}
case DownloadManager.STATUS_FAILED : {
Log.i("ololo", "Bad, I won't broadcast.");
int reason = cursor.getInt(cursor.getColumnIndex(DownloadManager.COLUMN_REASON));
if(reason == DownloadManager.ERROR_CANNOT_RESUME || reason == DownloadManager.ERROR_UNKNOWN) {
// Rerun download
}
break;
}
default:
break;
}
}
}