Android DownloadManager-收到操作\u下载\u完成,但状态为状态\u正在运行
我在舱单中注册了一个广播接收者,用于广播 当我收到此广播时,我提取下载id:Android DownloadManager-收到操作\u下载\u完成,但状态为状态\u正在运行,android,android-download-manager,Android,Android Download Manager,我在舱单中注册了一个广播接收者,用于广播 当我收到此广播时,我提取下载id: public class DownloadCompleteBroadcastReceiver extends BroadcastReceiver { @Override public void onReceive(Context context, Intent intent) { if (intent != null) { String action
public class DownloadCompleteBroadcastReceiver
extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
if (intent != null) {
String action = intent.getAction();
if (DownloadManager.ACTION_DOWNLOAD_COMPLETE.equals(action)) {
handleDownloadCompleteReceiver(context, intent);
}
}
}
private void handleDownloadCompleteReceiver(Context context, Intent intent) {
long enqueueId = intent.getLongExtra(DownloadManager.EXTRA_DOWNLOAD_ID, -1);
if (enqueueId != -1) {
Intent startServiceIntent = new Intent(context, HandleAPKDownloadCompleteIntentService.class);
startServiceIntent.putExtra(HandleAPKDownloadCompleteIntentService.EXTRA_ENQUEUE_ID, enqueueId);
context.startService(startServiceIntent);
}
}
}
我正在获取enqueueId
的有效值,并启动IntentService
来处理已下载的文件:
@Override
protected void onHandleIntent(Intent intent) {
long enqueueId = intent.getLongExtra(EXTRA_ENQUEUE_ID, -1);
if (enqueueId == -1) {
return;
}
DownloadManager dm = (DownloadManager) getSystemService(Context.DOWNLOAD_SERVICE);
DownloadManager.Query query = new DownloadManager.Query();
query.setFilterById(enqueueId);
Cursor c = dm.query(query);
if (c != null) {
if (c.moveToFirst()) {
int statusColumnIndex = c.getColumnIndex(DownloadManager.COLUMN_STATUS);
int downloadManagerDownloadStatus = c.getInt(statusColumnIndex);
if (DownloadManager.STATUS_SUCCESSFUL == downloadManagerDownloadStatus) {
...
...
}
else if (DownloadManager.STATUS_FAILED == downloadManagerDownloadStatus) {
...
...
}
else {
reportToGoogleAnalyticsUnexpectedStatus(downloadManagerDownloadStatus);
}
}
c.close();
}
}
此时downloadManagerDownloadStatus
=2,根据运行的状态
这没有任何意义,因为广播ACTION\u DOWNLOAD\u COMPLETE
已被调用,因此下载不应运行
我在谷歌分析中多次看到这种情况,但无法重现
- 知道为什么会这样吗
- 知道如何繁殖吗
提前感谢。因为我以前使用过
下载管理器。我想您可以注意以下几点:
1.DownloadManager
似乎与DownloadProvider.apk
有关系,当此应用程序的进程被终止时,DownloadManager
可能有问题
2.当您没有足够的存储空间时,您将面临以下问题:
Downloads.Impl.STATUS_INSUFFICIENT_SPACE_ERROR
这种情况可能会告诉您状态为下载。Impl.status\u RUNNING
您提到您正在开始多次下载
值得一提的一点是:我正在集中使用下载管理器:
一次启动10-15次下载,以触发
应用程序
现在,请清楚地解释onHandleIntent中发生了什么
摘自
受保护的抽象内容无效(意图)
在工作线程上调用此方法,并请求
过程一次只处理一个意图,但处理
在独立于其他线程运行的工作线程上发生
应用程序逻辑。因此,如果这段代码需要很长时间,它将保持不变
向同一IntentService发送其他请求,但不会挂起
别的。处理完所有请求后
IntentService会自动停止,因此不应调用stopSelf()
很有可能是由于一次或多次成功下载而使下载管理器跳闸。操作\u下载\u完成
,然后线程处于状态\u运行
状态,原因有多种,下载未完成
正如另一个答案所提到的,您可能已经耗尽了内存。我建议在每个阶段都登录你的应用程序,看看到底下载了什么,在哪里卡住了。然后调查它停止的原因。这种行为似乎很奇怪。您可以尝试下面的方法来获得您感兴趣的两种情况(除了
setFilterById()
):
但这并不能说明你为什么会得到你所得到的。我建议您添加下面的日志以查看光标中的内容,这将为您提供更好的想法
DatabaseUtils.dumpCursorToString(cursor)
更新:这是值得检查的:我已经用过几次了,有类似的问题。确保仔细检查所有内容,如:
- android.permission.INTERNET
- query.setFilterByStatus(DownloadManager.STATUS|u暂停| DownloadManager.STATUS|u挂起| DownloadManager.STATUS|u运行| DownloadManager.STATUS|u成功)李>
- 检查这个好
我希望这能有所帮助。@Yvette:我已经按照你的要求更新了我的问题。谢谢你的回答,但我不明白。。DownloadsImpl.STATUS\u RUNNING与DownloadMnager.STATUS\u RUNNIG之间的连接/关系是什么?它们是完全不同的常量。我的意思是,在您没有足够空间的情况下,这将导致操作下载完成,然后您查询可以运行状态的状态。您实际遇到过这种情况吗?如果是-您在特定设备上遇到过吗?哦,不,我的朋友发生过这种情况,他以前告诉过我。我没有遇到过这种情况。
DatabaseUtils.dumpCursorToString(cursor)