我正在使用android.I我正在尝试使用下载管理器获取下载状态。但它不起作用。我使用了以下代码
DownloadManager.Query query = null;
Log.i("service1", "blah");
Cursor c = null;
DownloadManager downloadManager = null;
downloadManager = (DownloadManager)getSystemService(Context.DOWNLOAD_SERVICE);
Log.i("service2", "blah");
query = new DownloadManager.Query();
if(query!=null) {
Log.i("service3", "blah");
query.setFilterByStatus(DownloadManager.STATUS_FAILED|DownloadManager.STATUS_PAUSED|DownloadManager.STATUS_SUCCESSFUL|
DownloadManager.STATUS_RUNNING|DownloadManager.STATUS_PENDING);
} else {
Log.i("service4", "blah");
return;
}
c = downloadManager.query(query);
if(c.moveToFirst()) {
Log.i("service5", "blah");
int status = c.getInt(c.getColumnIndex(DownloadManager.COLUMN_STATUS));
Log.i("service6", "blah");
switch(status) {
case DownloadManager.STATUS_PAUSED:
break;
case DownloadManager.STATUS_PENDING:
break;
case DownloadManager.STATUS_RUNNING:
Toast.makeText(this, "Download started", Toast.LENGTH_SHORT).show();
break;
case DownloadManager.STATUS_SUCCESSFUL:
Toast.makeText(this, "Download completed", Toast.LENGTH_SHORT).show();
break;
case DownloadManager.STATUS_FAILED:
break;
}
}
它不会进入if(c.moveToFirst())。或者在Android中获取下载状态的任何其他方式?