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