download - Android DownloadManager Query for COLUMN_STATUS returns zero -
i'm using download manager downloading file in app. i'm fetching status of download @ time. sometimes, after download goes pending i.e downloadmanager.status_pending, next values of column_status returned zero. 0 status not defined
when have column_status zero? facing similar issue?
public int checkstatus() { long downloadid = preference.getinstance(mcontext) .getenqueuenumber(); if (downloadid == 0) { return -1; } if (dm == null) { dm = (downloadmanager) mcontext .getsystemservice(context.download_service); } query mydownloadquery = new query(); // set query filter our enqueued download mydownloadquery.setfilterbyid(downloadid); int status = 0; cursor cursor = null; // query download manager downloads have been requested. try { cursor = dm.query(mydownloadquery); if (cursor != null && cursor.movetofirst()) { // column status int columnindex = cursor .getcolumnindex(downloadmanager.column_status); status = cursor.getint(columnindex); switch (status) { case downloadmanager.status_failed: dm.remove(downloadid); deletefile(); status = downloadmanager.status_failed; break; case downloadmanager.status_paused: status = downloadmanager.status_paused; break; case downloadmanager.status_pending: status = downloadmanager.status_pending; break; case downloadmanager.status_running: status = downloadmanager.status_running; break; case downloadmanager.status_successful: status = downloadmanager.status_successful; break; default: break; } } } catch (exception e) { e.printstacktrace(); } { if (cursor != null) cursor.close(); } return status; }
Comments
Post a Comment