6
我使用DownloadManager获取下载状态,但它仍然不起作用,它从不跳转到条件if(c.moveToFirst())
,我不知道为什么。请有人帮助我吗?如何获取下载的状态?
private final BroadcastReceiver myReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
if(Intent.ACTION_SCREEN_OFF.equals(action)) {
DownloadManager downloadMgr = (DownloadManager)getSystemService(DOWNLOAD_SERVICE);
DownloadManager.Query query = new DownloadManager.Query();
query.setFilterByStatus(DownloadManager.STATUS_FAILED|DownloadManager.STATUS_PENDING|DownloadManager.STATUS_RUNNING|DownloadManager.STATUS_SUCCESSFUL);
Cursor c = downloadMgr.query(query);
if(c==null) {
//
}
else {
if(c.moveToFirst()) {
int columnIndex = c.getColumnIndex(DownloadManager.COLUMN_STATUS);
int status = c.getInt(columnIndex);
if(status == DownloadManager.STATUS_RUNNING){
//do something
}
}
}
}
}
};
显然光标是空的? – Blundell 2012-04-21 11:12:33
嗯?我该如何解决它? – Adam 2012-04-21 11:15:08
看起来游标不是空的,因为它总是去其他地方,而不是如果(C == null)。 – Adam 2012-04-21 11:17:50