我已经搜索了很多,但我找不到令人满意的答案。我只是创建了一个方法,当被调用时,在 Log.i() 中打印所有可用的下载状态;这是方法:
DownloadManager downloadManager = (DownloadManager)getSystemService(Context.DOWNLOAD_SERVICE);
DownloadManager.Query query = new DownloadManager.Query();
Cursor c = downloadManager.query(query);
while (c.moveToNext()) {
switch(c.getInt(c.getColumnIndex(DownloadManager.COLUMN_STATUS))) {
case DownloadManager.STATUS_FAILED:
Log.i("46dl","Download failed!");
break;
case DownloadManager.STATUS_PAUSED:
Log.i("46dl","Download paused!");
break;
case DownloadManager.STATUS_PENDING:
Log.i("46dl","Download pending!");
break;
case DownloadManager.STATUS_RUNNING:
Log.i("46dl","Download in progress!");
break;
case DownloadManager.STATUS_SUCCESSFUL:
Log.i("46dl","Download complete!");
break;
default:
Log.i("46dl","Download is nowhere in sight");
break;
}
}
但这仅在我从我的应用程序开始下载时才有效;例如
Request request = new Request(Uri.parse("http://www.something.com/img/img4.jpg"));
downloadManager.enqueue(request);
对于使用其他应用程序(例如使用浏览器)下载的其他文件,日志中没有写入任何行。我错过了什么吗?谢谢您的帮助!