下载管理器发送STATUS_SUCCESSFUL失败的下载 [英] DownloadManager sends STATUS_SUCCESSFUL for failed download
问题描述
好吧,我下载文件(影像)。我想发一条消息,当地的URI图像时,下载完成。但是,20%的时间我得到这样的:
6-01 18:46:39.900:信息/下载管理器(412):发起请求下载605
06-01 18:46:39.910:警告/下载管理器(412):中止请求下载605:试图恢复下载无法恢复
06-01 18:46:39.910:信息/ ololo(2826):好吧,我会播出。
06-01 18:46:39.990:WARN / ImageView的(2826):无法打开内容:内容://下载/ my_downloads / 605
java.io.FileNotFoundException:未找到的文件名。
在android.database.DatabaseUtils.readExceptionWithFileNotFoundExceptionFromParcel(DatabaseUtils.java:145)...
06-01 18:46:39.990:信息/的System.out(2826):resolveUri没有坏的位图网址:内容://下载/ my_downloads / 605
06-01 18:46:39.990:信息/ ololo(2826):内容://下载/ my_downloads / 605是为android.widget.ImageView@408a2cf0设置
下面是code
龙downloadId = downloadIds.get(本);
如果(downloadId == intent.getLongExtra(DownloadManager.EXTRA_DOWNLOAD_ID,-1)){
DownloadManager.Query查询=新DownloadManager.Query();
query.setFilterById(downloadId);
光标光标= downloadManager.query(查询);
如果(cursor.moveToFirst()){
开关(cursor.getInt(cursor.getColumnIndex(DownloadManager.COLUMN_STATUS))){
案例DownloadManager.STATUS_SUCCESSFUL:{
Log.i(ololo,好吧,我会播出。);
// 广播
打破;
}
案例DownloadManager.STATUS_FAILED:{
Log.i(ololo,坏了,我就不会播出。);
INT原因= cursor.getInt(cursor.getColumnIndex(DownloadManager.COLUMN_REASON));
如果(原因== DownloadManager.ERROR_CANNOT_RESUME ||原因== DownloadManager.ERROR_UNKNOWN){
//重新运行下载
}
打破;
}
默认:
打破;
}
}
}
下载管理器是越野车,并不能正常工作。此bug已被提交给谷歌,而回:
HTTPS://$c$c.google。 COM / P /安卓/问题/详细信息?ID = 18462
对于单文件下载,你可以通过指定一个唯一的目录解决此下载专门为这个目的,而只是采取任何你在DownloadManager.STATUS_SUCCESSFUL该目录中获得。
对于多文件下载,我想不出一个解决办法的那一刻,除非你有在源重命名文件的功能。
Okay, I'm downloading files (images). I want to send a message with local URI for the image when the download is completed. But 20% of time I'm getting this:
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
Here is the code
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;
}
}
}
DownloadManager is buggy and doesn't work correctly. This bug was filed with Google a while back:
https://code.google.com/p/android/issues/detail?id=18462
For single file download, you could workaround this by specifying a unique directory to download to specifically for this purpose, and just take whatever you get in that directory upon DownloadManager.STATUS_SUCCESSFUL.
For multi-file downloads, I can't think of a workaround at the moment, unless you have the ability to rename files at the source.
这篇关于下载管理器发送STATUS_SUCCESSFUL失败的下载的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!