List of usage examples for android.app DownloadManager STATUS_RUNNING
int STATUS_RUNNING
To view the source code for android.app DownloadManager STATUS_RUNNING.
Click Source Link
From source file:Main.java
/** * Find a download with the specified name. Returns -1 if none was * found.//from w w w .j a v a2 s .c o m */ static long findPath(DownloadManager dm, String path) { DownloadManager.Query query = new DownloadManager.Query(); query.setFilterByStatus( DownloadManager.STATUS_PAUSED | DownloadManager.STATUS_PENDING | DownloadManager.STATUS_RUNNING); Cursor c = dm.query(query); if (!c.moveToFirst()) return -1; final int columnID = c.getColumnIndexOrThrow(DownloadManager.COLUMN_ID); final int columnLocalURI = c.getColumnIndexOrThrow(DownloadManager.COLUMN_LOCAL_URI); do { final String uri = c.getString(columnLocalURI); if (uri != null && uri.endsWith(path)) return c.getLong(columnID); } while (c.moveToNext()); return -1; }
From source file:Main.java
public static void CheckDwnloadStatus(DownloadManager downloadManager, Activity activity, long id) { // TODO Auto-generated method stub DownloadManager.Query query = new DownloadManager.Query(); query.setFilterById(id);/*ww w . ja v a 2 s . co m*/ Cursor cursor = downloadManager.query(query); if (cursor.moveToFirst()) { int columnIndex = cursor.getColumnIndex(DownloadManager.COLUMN_STATUS); int status = cursor.getInt(columnIndex); int columnReason = cursor.getColumnIndex(DownloadManager.COLUMN_REASON); int reason = cursor.getInt(columnReason); switch (status) { case DownloadManager.STATUS_FAILED: String failedReason = ""; switch (reason) { case DownloadManager.ERROR_CANNOT_RESUME: failedReason = "ERROR_CANNOT_RESUME"; break; case DownloadManager.ERROR_DEVICE_NOT_FOUND: failedReason = "ERROR_DEVICE_NOT_FOUND"; break; case DownloadManager.ERROR_FILE_ALREADY_EXISTS: failedReason = "ERROR_FILE_ALREADY_EXISTS"; break; case DownloadManager.ERROR_FILE_ERROR: failedReason = "ERROR_FILE_ERROR"; break; case DownloadManager.ERROR_HTTP_DATA_ERROR: failedReason = "ERROR_HTTP_DATA_ERROR"; break; case DownloadManager.ERROR_INSUFFICIENT_SPACE: failedReason = "ERROR_INSUFFICIENT_SPACE"; break; case DownloadManager.ERROR_TOO_MANY_REDIRECTS: failedReason = "ERROR_TOO_MANY_REDIRECTS"; break; case DownloadManager.ERROR_UNHANDLED_HTTP_CODE: failedReason = "ERROR_UNHANDLED_HTTP_CODE"; break; case DownloadManager.ERROR_UNKNOWN: failedReason = "ERROR_UNKNOWN"; break; default: failedReason = "unknown reason"; break; } Toast.makeText(activity, "FAILED: " + failedReason, Toast.LENGTH_LONG).show(); break; case DownloadManager.STATUS_PAUSED: String pausedReason = ""; switch (reason) { case DownloadManager.PAUSED_QUEUED_FOR_WIFI: pausedReason = "PAUSED_QUEUED_FOR_WIFI"; break; case DownloadManager.PAUSED_UNKNOWN: pausedReason = "PAUSED_UNKNOWN"; break; case DownloadManager.PAUSED_WAITING_FOR_NETWORK: pausedReason = "PAUSED_WAITING_FOR_NETWORK"; break; case DownloadManager.PAUSED_WAITING_TO_RETRY: pausedReason = "PAUSED_WAITING_TO_RETRY"; break; } Toast.makeText(activity, "PAUSED: " + pausedReason, Toast.LENGTH_LONG).show(); break; case DownloadManager.STATUS_PENDING: Toast.makeText(activity, "PENDING", Toast.LENGTH_LONG).show(); break; case DownloadManager.STATUS_RUNNING: Toast.makeText(activity, "RUNNING", Toast.LENGTH_LONG).show(); break; case DownloadManager.STATUS_SUCCESSFUL: Toast.makeText(activity, "SUCCESSFUL", Toast.LENGTH_LONG).show(); break; } } }
From source file:com.appjma.appdeployer.adapter.AppVersionsAdapter.java
@Override public void bindView(View view, Context context, Cursor cursor) { ViewHolder holder = (ViewHolder) view.getTag(); String version = cursor.getString(PROJECTION_VERSION); long updatedAt = cursor.getLong(PROJECTION_UPDATED_AT); long id = cursor.getLong(PROJECTION_APP_VERSION_ID); String downloadManagerId = cursor.getString(PROJECTION_DOWNLOAD_MANAGER_ID); int status = -1; if (downloadManagerId != null) { DownloadItem downloadItem = mMap.get(downloadManagerId); if (downloadItem != null) { status = downloadItem.mStatus; }//from w w w .j ava 2s. co m } if (status == DownloadManager.STATUS_PENDING || status == DownloadManager.STATUS_RUNNING) { holder.mButton.setBackgroundResource(R.drawable.ic_list_item_downloading); } else if (status == DownloadManager.STATUS_SUCCESSFUL) { holder.mButton.setBackgroundResource(R.drawable.ic_list_item_downloaded); } else { holder.mButton.setBackgroundResource(R.drawable.ic_list_item_download); } holder.mPosition = cursor.getPosition(); holder.mText1.setText(String.format(mVersionFormat, version)); CharSequence updatedAtText = DateUtils.getRelativeTimeSpanString(updatedAt, mNow, DateUtils.MINUTE_IN_MILLIS); holder.mText2.setText(updatedAtText); holder.mId = id; }
From source file:com.commonsware.android.downmgr.DownloadFragment.java
private String statusMessage(Cursor c) { String msg = "???"; switch (c.getInt(c.getColumnIndex(DownloadManager.COLUMN_STATUS))) { case DownloadManager.STATUS_FAILED: msg = getActivity().getString(R.string.download_failed); break;//from www.j ava2s . c o m case DownloadManager.STATUS_PAUSED: msg = getActivity().getString(R.string.download_paused); break; case DownloadManager.STATUS_PENDING: msg = getActivity().getString(R.string.download_pending); break; case DownloadManager.STATUS_RUNNING: msg = getActivity().getString(R.string.download_in_progress); break; case DownloadManager.STATUS_SUCCESSFUL: msg = getActivity().getString(R.string.download_complete); break; default: msg = getActivity().getString(R.string.download_is_nowhere_in_sight); break; } return (msg); }
From source file:com.example.linhdq.test.main_menu.language.OCRLanguageActivity.java
private void updateLanguageListWithDownloadManagerStatus(OCRLanguageAdapter adapter) { if (adapter != null) { // find languages that are currently being downloaded Query query = new Query(); query.setFilterByStatus(DownloadManager.STATUS_RUNNING | DownloadManager.STATUS_PENDING | DownloadManager.STATUS_PAUSED); final DownloadManager dm = (DownloadManager) getSystemService(Context.DOWNLOAD_SERVICE); Cursor c = dm.query(query); if (c == null) { return; }// w w w .j av a 2s .c o m int columnIndex = c.getColumnIndex(DownloadManager.COLUMN_TITLE); while (c.moveToNext()) { final String title = c.getString(columnIndex); adapter.setDownloading(title, true); } adapter.notifyDataSetChanged(); c.close(); } }
From source file:com.cypher.cota.helpers.DownloadHelper.java
private static long[] getDownloadProgress(long id) { DownloadManager.Query q = new DownloadManager.Query(); q.setFilterById(id);//from w w w . ja va2s . com Cursor cursor = sDownloadManager.query(q); int status; if (cursor == null || !cursor.moveToFirst()) { status = DownloadManager.STATUS_FAILED; } else { status = cursor.getInt(cursor.getColumnIndex(DownloadManager.COLUMN_STATUS)); } long error = -1; long totalBytes = -1; long downloadedBytes = -1; switch (status) { case DownloadManager.STATUS_PAUSED: case DownloadManager.STATUS_RUNNING: downloadedBytes = cursor.getLong(cursor.getColumnIndex(DownloadManager.COLUMN_BYTES_DOWNLOADED_SO_FAR)); totalBytes = cursor.getLong(cursor.getColumnIndex(DownloadManager.COLUMN_TOTAL_SIZE_BYTES)); break; case DownloadManager.STATUS_FAILED: sDownloadingRom = false; error = getDownloadError(cursor); break; } if (cursor != null) { cursor.close(); } return new long[] { status, totalBytes, downloadedBytes, error }; }
From source file:com.renard.ocr.help.OCRLanguageActivity.java
private void updateLanguageListWithDownloadManagerStatus(OCRLanguageAdapter adapter) { if (adapter != null) { // find languages that are currently beeing downloaded Query query = new Query(); query.setFilterByStatus(DownloadManager.STATUS_RUNNING | DownloadManager.STATUS_PENDING | DownloadManager.STATUS_PAUSED); final DownloadManager dm = (DownloadManager) getSystemService(Context.DOWNLOAD_SERVICE); Cursor c = dm.query(query); int columnIndex = c.getColumnIndex(DownloadManager.COLUMN_TITLE); while (c.moveToNext()) { final String title = c.getString(columnIndex); adapter.setDownloading(title, true); }/*from w w w. j a v a 2 s. c o m*/ adapter.notifyDataSetChanged(); c.close(); } }
From source file:com.zsxj.pda.ui.client.LoginActivity.java
private boolean downloading() { DownloadManager.Query query = new DownloadManager.Query(); SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this); long downloadId = prefs.getLong(PrefKeys.DOWNLOAD_ID, 0); query.setFilterById(downloadId);/* ww w .j a va 2 s. c o m*/ DownloadManager dm = (DownloadManager) getSystemService(Context.DOWNLOAD_SERVICE); Cursor c = dm.query(query); if (c.moveToNext()) { int statusIdx = c.getColumnIndex(DownloadManager.COLUMN_STATUS); int status = c.getInt(statusIdx); if (DownloadManager.STATUS_RUNNING == status) { return true; } } return false; }
From source file:com.bluros.updater.UpdatesSettings.java
@Override protected void onStart() { super.onStart(); // Determine if there are any in-progress downloads mDownloadId = mPrefs.getLong(Constants.DOWNLOAD_ID, -1); if (mDownloadId >= 0) { Cursor c = mDownloadManager.query(new DownloadManager.Query().setFilterById(mDownloadId)); if (c == null || !c.moveToFirst()) { Toast.makeText(this, R.string.download_not_found, Toast.LENGTH_LONG).show(); } else {/*from w ww. ja v a 2s .com*/ int status = c.getInt(c.getColumnIndex(DownloadManager.COLUMN_STATUS)); Uri uri = Uri.parse(c.getString(c.getColumnIndex(DownloadManager.COLUMN_URI))); if (status == DownloadManager.STATUS_PENDING || status == DownloadManager.STATUS_RUNNING || status == DownloadManager.STATUS_PAUSED) { mDownloadFileName = uri.getLastPathSegment(); } } if (c != null) { c.close(); } } if (mDownloadId < 0 || mDownloadFileName == null) { resetDownloadState(); } requestUpdateLayout(); IntentFilter filter = new IntentFilter(UpdateCheckService.ACTION_CHECK_FINISHED); filter.addAction(DownloadReceiver.ACTION_DOWNLOAD_STARTED); registerReceiver(mReceiver, filter); checkForDownloadCompleted(getIntent()); setIntent(null); }
From source file:scal.io.liger.LigerDownloadManager.java
public boolean checkQueue() { String fileName = ZipHelper.getExpansionZipFilename(context, mainOrPatch, version); String filePath = ZipHelper.getExpansionZipDirectory(context, mainOrPatch, version); File checkFile = new File(filePath, fileName + ".tmp"); boolean foundInQueue = false; // need to check if a download has already been queued for this file //HashMap<Long, QueueItem> queueMap = QueueManager.loadQueue(context); //for (Long queueId : queueMap.keySet()) { //Timber.d("QUEUE ITEM IS " + queueMap.get(queueId).getQueueFile() + " LOOKING FOR " + checkFile.getName()); //if (checkFile.getName().equals(queueMap.get(queueId).getQueueFile())) { Long queueId = QueueManager.checkQueue(context, checkFile); if (queueId == null) { // not found foundInQueue = false;/*from ww w. j av a 2 s .co m*/ } else if (queueId.equals(QueueManager.DUPLICATE_QUERY)) { // not exactly in queue, but someone is already looking for this item, so avoid collision foundInQueue = true; } else if (queueId < 0) { // use negative numbers to flag non-manager downloads if (checkFileProgress()) { Timber.d("QUEUE ITEM FOUND FOR " + checkFile.getName() + " AND DOWNLOAD PROGRESS OBSERVED, LEAVING " + queueId.toString() + " IN QUEUE "); foundInQueue = true; } else { Timber.d("QUEUE ITEM FOUND FOR " + checkFile.getName() + " BUT NO DOWNLOAD PROGRESS OBSERVED, REMOVING " + queueId.toString() + " FROM QUEUE "); QueueManager.removeFromQueue(context, Long.valueOf(queueId)); } } else { // use download manager ids to flag manager downloads // need to init download manager to check queue initDownloadManager(); DownloadManager.Query query = new DownloadManager.Query(); query.setFilterById(queueId.longValue()); Cursor c = dManager.query(query); try { if (c.moveToFirst()) { int columnIndex = c.getColumnIndex(DownloadManager.COLUMN_STATUS); if (DownloadManager.STATUS_FAILED == c.getInt(columnIndex)) { Timber.d("QUEUE ITEM FOUND FOR " + checkFile.getName() + " BUT DOWNLOAD STATUS IS FAILED, REMOVING " + queueId.toString() + " FROM QUEUE "); QueueManager.removeFromQueue(context, Long.valueOf(queueId)); } else if (DownloadManager.STATUS_PAUSED == c.getInt(columnIndex)) { Timber.d("QUEUE ITEM FOUND FOR " + checkFile.getName() + " AND DOWNLOAD STATUS IS PAUSED, LEAVING " + queueId.toString() + " IN QUEUE "); foundInQueue = true; } else if (DownloadManager.STATUS_PENDING == c.getInt(columnIndex)) { Timber.d("QUEUE ITEM FOUND FOR " + checkFile.getName() + " AND DOWNLOAD STATUS IS PENDING, LEAVING " + queueId.toString() + " IN QUEUE "); foundInQueue = true; } else if (DownloadManager.STATUS_RUNNING == c.getInt(columnIndex)) { Timber.d("QUEUE ITEM FOUND FOR " + checkFile.getName() + " AND DOWNLOAD STATUS IS RUNNING, LEAVING " + queueId.toString() + " IN QUEUE "); foundInQueue = true; } else if (DownloadManager.STATUS_SUCCESSFUL == c.getInt(columnIndex)) { Timber.d("QUEUE ITEM FOUND FOR " + checkFile.getName() + " BUT DOWNLOAD STATUS IS SUCCESSFUL, REMOVING " + queueId.toString() + " FROM QUEUE "); QueueManager.removeFromQueue(context, Long.valueOf(queueId)); } else { Timber.d("QUEUE ITEM FOUND FOR " + checkFile.getName() + " BUT DOWNLOAD STATUS IS UNKNOWN, REMOVING " + queueId.toString() + " FROM QUEUE "); QueueManager.removeFromQueue(context, Long.valueOf(queueId)); } } else { Timber.d("QUEUE ITEM FOUND FOR " + checkFile.getName() + " BUT NOTHING FOUND IN DOWNLOAD MANAGER, REMOVING " + queueId.toString() + " FROM QUEUE "); QueueManager.removeFromQueue(context, Long.valueOf(queueId)); } } finally { if (c != null) { c.close(); } } // cleanup c.close(); } //} // skipping timeout check for now, timeout duration undecided /* if (foundInQueue) { Date currentTime = new Date(); long queuedTime = queueMap.get(queueId).getQueueTime(); if ((currentTime.getTime() - queueMap.get(queueId).getQueueTime()) > QueueManager.queueTimeout) { Timber.d("TIMEOUT EXCEEDED, REMOVING " + queueId.toString() + " FROM DOWNLOAD MANAGER."); int numberRemoved = manager.remove(queueId); if (numberRemoved == 1) { Timber.d("REMOVED FROM DOWNLOAD MANAGER, RE-QUEUEING: " + queueId.toString() + " -> " + uriFile.toString()); QueueManager.removeFromQueue(context, Long.valueOf(queueId)); foundInQueue = false; } else { Timber.d("FAILED TO REMOVE FROM DOWNLOAD MANAGER, NOT QUEUEING: " + queueId.toString() + " -> " + uriFile.toString()); } } } */ //} return foundInQueue; }